Name: Anonymous 2011-10-06 9:06
Any code you work with right now, and we'll criticize it(or not).
print ("print");
def check_online_own3d(streamID):
f = urllib.urlopen("http://api.own3d.tv/liveCheck.php?live_id=" + streamID)
liveLink = f.read()
f.close()
if '<isLive>true</isLive>' in liveLink:
ready = 1
else:
ready = 0
return ready
def on_text(word, word_eol, userdata):
destination = xchat.get_context()
triggernick = word[0]
trigger = re.split(' ', word[1].lower())
if trigger[0] == '!stream' and trigger[1] == 'list':
strStreamListOwn3d = 'none'
liveStreamListOwn3d = []
inStreamListOwn3d = []
#own3d
loop = 0
infile = open(os.path.join("C:\\Program Files\\XChat-WDK\\plugins\\streamFiles", "streamListOwn3d.txt"))
findingLine = infile.readlines()
infile.close()
for i in findingLine:
streamID = findingLine[loop].strip()
if check_online_own3d(streamID) == 1:
inStreamListOwn3d.append(streamID)
loop += 1
if '40553' in inStreamListOwn3d:
liveStreamListOwn3d.append('http://www.own3d.tv/live/40553/ComeWithMe')
strStreamListOwn3d = str(liveStreamListOwn3d)
if liveStreamListOwn3d == []:
destination.command("say " + triggernick + ": No live streams currently online.")
else:
destination.command("say " + triggernick + ": Live Streams are " + strStreamListOwn3d)
return xchat.EAT_NONE
xchat.hook_print('Channel Message', on_text)#if defined (__GNUC__)
#define VMCALL __attribute__((hot, fastcall))
#elif defined (MSVC)
#define VMCALL __fastcall
#else
#define VMCALL
#endif
#define VMDECL(name) static int VMCALL name(unsigned int op, thread* t)
#!/bin/bash
root=`echo ~`
watched_folder="$root/downloads/torrents/links"
if [ ! 1 -eq $# ]; then
echo This script needs one argument
exit 1
fi
file="$root/scripts/torrents/$1"
if [ ! -f "$file" ]; then
# History file does not exist yet
touch "$file"
echo Created a history file
fi
url="http://api.dailytvtorrents.org/1.0/torrent.getLatest?show_name=$1&just_link=yes"
link=`curl -s "$url"`
old_link=`cat "$file"`
# Change this by checking if .torrent file already there
if [ ! "$old_link" = "$link" ]; then
# Last download of the torrent != current try
# Do we need to start deluged?
ps=`pgrep deluged`
if [ "$ps" = "" ]; then
sudo /etc/rc.d/deluged start
fi
cd "$watched_folder"
curl -s -O "$link"
echo "Got one"
# We remember it
echo $link > $file
else
echo "Nothing new"
fi
if ...:
ready = 1
else:
ready = 0
return readyreturn ...". What you're doing is just ugly and Pythonic
#include "hurrdurr.h"
hurr
durr
herp
derp //derp
Private Sub Process(ByVal ID As Byte)
Dim Ev As Reflection.EventInfo
Dim EvDel As System.Delegate
Dim Args As New Collections.List(Of Object)
Try
Ev = PacketEvents(ID)
Catch Err As Collections.KeyNotFoundException
Throw New UnknownPacketException(ID)
End Try
EvDel = CType(GetType(Client).GetField(Ev.Name + "Event", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(Me), System.Delegate)
For Each Arg As Reflection.ParameterInfo In Ev.EventHandlerType.GetMethod("Invoke").GetParameters()
Dim Type As System.Type = Arg.ParameterType
If Type Is GetType(Client) Then
Args.Add(Me)
ElseIf Type Is GetType(Boolean) Then
Args.Add(Stream.ReadByte() <> 0)
ElseIf Type Is GetType(Byte) Then
Args.Add(Stream.ReadByte())
ElseIf Type Is GetType(Short) Then
Args.Add(Stream.ReadShort())
ElseIf Type Is GetType(Integer) Then
Args.Add(Stream.ReadInteger())
ElseIf Type Is GetType(Long) Then
Args.Add(Stream.ReadLong())
ElseIf Type Is GetType(Single) Then
Args.Add(Stream.ReadSingle())
ElseIf Type Is GetType(Double) Then
Args.Add(Stream.ReadDouble())
ElseIf Type Is GetType(String) Then
Args.Add(Stream.ReadString())
Else
Throw New System.ArgumentException
End If
For Each Attr As PacketTerminatorAttribute In Arg.GetCustomAttributes(GetType(PacketTerminatorAttribute), False)
If Attr.Value = CLng(Args(Args.Count - 1)) Then
GoTo EscapeOuterFor
End If
Next
Next
EscapeOuterFor:
If EvDel IsNot Nothing Then
EvDel.DynamicInvoke(Args.ToArray())
ElseIf (Ev.GetAddMethod().Attributes And Reflection.MethodAttributes.Public) <> 0 Then
RaiseEvent ReceivedUnhandled(Me, ID, Ev.Name)
End If
'System.Console.Out.Write("{0}:", ID)
'For Each Arg As Object In Args
'System.Console.Out.Write(" {0}", Arg)
'Next
'System.Console.Out.WriteLine()
End Sub
#ifdef _MSC_VER
#pragma warning( disable : 4820 )
#pragma warning( disable : 4514 )
#endif
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
//#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define MULTISAND_DEBUG
#include "defines.h"
#include "powder.h"
#include "menu.h"
#include "graphics.h"
//#include <getopt.h>
int main(int argc, char** argv)
{
SDL_Event MEvent;
int MouseX;
int MouseY;
int MouseSt;
bool UserQuit = false;
bool brushchg = false;
ptype* pselection = &ptable[1];
InitSDL("Multisand");
if(init_particles() != 0)
{
puts("Error: Not enough memory!");
exit(1);
}
while(!UserQuit)
{
//Clear menu area
memset(menmem, 0, menmemsz);
// Get mouse state and position
while(SDL_PollEvent(&MEvent))
{
if(MEvent.type == SDL_QUIT)
{
UserQuit = true;
}
}
MouseSt = SDL_GetMouseState(&MouseX, &MouseY);
if(MouseSt & SDL_BUTTON(4) && brushsz < 7)
{
puts("Text");
++brushsz;
}
if(MouseSt & SDL_BUTTON(5) && brushsz > 0)
--brushsz;
//Is this optimized? TODO: Fix this, but later for sure
if(update_menu(MouseX, MouseY, &pselection, MouseSt) & SDL_BUTTON(1) && MouseY < MENU_LOWEST_POINT)
{
brush_fill(MouseX, MouseY, pselection->ID);
//vidmem[(XRES_BIT(MouseY)) + MouseX] = pselection->color;
}
// pmap[XRES_BIT(20) + 6] = pmap[XRES_BIT(20) + 7] = pmap[XRES_BIT(20) + 8] = 0xFF0000;
//memcpy(vidmem, pmap, sizeof(pmap));
SDL_UpdateRect(Video, 0, 0, 0, 0);
SDL_Delay((Uint32)1);
}
SDL_Quit();
return 0;
}
// deinterlace the 4 chunks from one imageData blob in one pass
// see appendix e of gif spec
//
// ideas: canvasize first, then deinterlace...
// and do canvas drawImage calls or putImageData calls to move the rows around
GIF.render.deinterlacePixels = function(oldpixels, w, h){
var pixels = new Uint8Array(oldpixels.length);
var stripes2 = Math.ceil(h/8); // the row where the 2nd interlaced chunk starts
var stripes3 = Math.ceil(h/4);
var stripes4 = Math.ceil(h/2);
// pixels[(w*y) +x] = oldpixels[(w*y) +x] <- base calculation
for(var y=0; y<h; y++){
var interlacedRowOffset;
var rowOffset = w * y;
if (y % 8 === 0)
interlacedRowOffset = w* (y/8);
else if ((y + 4) % 8 === 0)
interlacedRowOffset = w* ((y-4)/8+stripes2);
else if (y % 2 === 0)
interlacedRowOffset = w* ((y-2)/4+stripes3);
else
interlacedRowOffset = w* ((y-1)/2+stripes4);
for(var x=0; x<w; x++)
pixels[rowOffset+x] = oldpixels[interlacedRowOffset+x];
}
return pixels;
};
#!/bin/bash
while true;
do
runhaskell $1 &
inotifywait -q -q -e modify $1
killall ghc
done
echo "SELECT key, concat('\'',val,'\'') FROM some_table" | \
mysql -A -u user -p db01 | \
sed 's/^/SET /g' | \
redis-cli > /dev/null
char day_name[7][10];
int i;
for (i = 0; i < 7; i++)
{
switch(i)
{
case 0: strcpy(day_name[i], "Sunday");
case 1: strcpy(day_name[i], "Monday");
case 2: strcpy(day_name[i], "Tuesday");
case 3: strcpy(day_name[i], "Wednesday");
case 4: strcpy(day_name[i], "Thursday");
case 5: strcpy(day_name[i], "Friday");
case 6: strcpy(day_name[i], "Saturday");
}
}char day_name[7][10] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
13 * sizeof(char). If I had used pointers that'd be 7 * sizeof(char*) which is bigger on most architectures. The last alternative is using a Win32-like multistring but then retrieval would be slower.
char day_name[7][10];
int i;
for (i = 0; i < 7; i++)
{
switch(i)
{
case 0: strcpy(day_name[i], "Sunday");
case 1: strcpy(day_name[i], "Monday");
case 2: strcpy(day_name[i], "Tuesday");
case 3: strcpy(day_name[i], "Wednesday");
case 4: strcpy(day_name[i], "Thursday");
case 5: strcpy(day_name[i], "Friday");
case 6: strcpy(day_name[i], "Trollday");
}
}
#!/bin/sh
echo hello world
exit 24
Sub unwrap()
Function trunc(kc, n)
k1 = kc
trunc = 0
While (k1 > n)
k1 = k1 - n
trunc = trunc + 1
Wend
End Function
Dim xx(311, 264)
nrow = 88: ncol = 35: nwraps = 2: nwrapcols = 20
sname1 = "wrapped": sname2 = "unwrapped":
Sheets(sname2).Select: Sheets(sname2).Cells.Select
Selection.ClearContents: Selection.Borders.LineStyle = xlNone
For kkrow = 1 To nrow: Cells(kkrow + 32, 2) = kkrow: Next kkrow
For kkcol = 1 To ncol: Cells(32, kkcol + 2) = kkcol: Next kkcol
For kkcol = 1 To ncol
Cells(33, kkcol + 2).Borders(xlEdgeTop).LineStyle = XlLineStyle.xlDouble
Cells(nrow + 32, kkcol + 2).Borders(xlEdgeBottom).LineStyle = XlLineStyle.xlDouble
Next kkcol
For kkrow = 1 To nrow
Cells(kkrow + 32, 3).Borders(xlEdgeLeft).LineStyle = XlLineStyle.xlDouble
Cells(kkrow + 32, ncol + 2).Borders(xlEdgeRight).LineStyle = XlLineStyle.xlDouble
Next kkrow
For kkrow = 1 To nrow: For kkcol = 1 To ncol
Sheets(sname1).Select
kkr1 = nwraps * (kkrow - 1) + trunc(kkcol, nwrapcols) + 1
kkc1 = kkcol - nwrapcols * trunc(kkcol, nwrapcols)
xx(kkrow, kkcol) = Cells(kkr1, kkc1)
Sheets(sname2).Select
Cells(kkrow + 32, kkcol + 2) = xx(kkrow, kkcol)
Next kkcol: Next kkrow
End Sub
#!/bin/bash
echo "Segmentation fault" >&2
exit 139
# problem, lunix?
segmentation fault
sub addr-parse( Str $str, :$cidr ) {
my @chunks = $str.comb: /\d+/;
my $mask = @chunks[4] // 0;
my $base = [+] @chunks[^4] Z+< 24, 16, 8, 0;
return ( $base, $mask ) if $cidr;
return $base;
}
sub cidr-str( Int $base, Int $mask ) {
my $str = (
for 24, 16, 8, 0 -> $s { ( $base +> $s ) +& 0xff; }
).join('.') ~ '/' ~ $mask;
return $str;
}
Option Explicit
const w = 3
const h = 3
const tyhja = "_"
redim TheGame(w,h)
dim fun
dim i, j
dim inp, x, y
dim view
dim merkki
dim winner
dim random_ok
view = ""
winner = "0"
fun = True
For i = 0 To w -1
For j = 0 To h-1
TheGame(i,j) = tyhja
Next
Next
Randomize
msgbox "Super X0 !!!!!!!!!!!!!!!!!!111111oneoneelevenone" & vbCr & vbCr & "Paina OK, tampio"
Do While fun
view = ""
For i = 0 To h-1
For j = 0 To w-1
merkki = TheGame(j,i)
view = view & merkki
if merkki <> tyhja Then
If i <> 0 and i <> h-1 Then
if TheGame(j, i-1) = merkki and TheGame(j, i+1) = merkki Then
winner = merkki
fun = False
End If
End If
If j <> 0 and j <> w-1 Then
if TheGame(j-1, i) = merkki and TheGame(j+1, i) = merkki Then
winner = merkki
fun = False
End If
End If
If j <> 0 and i <> 0 and i <> h-1 and j <> w-1 Then
If (TheGame(j-1, i-1) = merkki and TheGame(j+1, i+1) = merkki) _
Or (TheGame(j+1, i-1) = merkki and TheGame(j-1, i+1) = merkki) Then
winner = merkki
fun = False
End If
End If
end if
Next
view = view & vbCr
Next
if fun then
inp = InputBox(view)
x = CInt(mid(inp, 1, 1)) - 1
y = CInt(mid(inp, 2, 1)) - 1
if TheGame(x,y) = tyhja then
TheGame(x,y) = "X"
end If
random_ok = False
do while not random_ok
x = w * Rnd
y = h * Rnd
if TheGame(x, y) <> "0" Then
TheGame(x,y) = "0"
random_ok = True
End If
loop
end if
Loop
MsgBox winner & " voitti..."
#ifndef VEC2_H_INCLUDED_
#define VEC2_H_INCLUDED_
#include <cmath>
/**
* Represents 2D vector.
*/
class Vec2
{
public:
float x, y;
/** Construct vector with given values */
Vec2(float _x, float _y) : x(_x), y(_y) {}
/** Create uninitialized vector */
Vec2(){}
/** Construct scaled copy */
Vec2(const Vec2& v, float scale_ratio) {
*this = v;
scale(scale_ratio);
}
Vec2& operator += (const Vec2& v) {
x += v.x;
y += v.y;
return *this;
}
Vec2& operator -= (const Vec2& v) {
x -= v.x;
y -= v.y;
return *this;
}
Vec2 operator + (const Vec2& v) const {
return Vec2(x+v.x, y+v.y);
}
Vec2 operator - (const Vec2& v) const {
return Vec2(x-v.x, y-v.y);
}
/** multiply with scalar */
void scale(float m) {
x *= m;
y *= m;
}
/** Dot product */
float dot(const Vec2& v) const {
return x * v.x + y * v.y;
}
/** Cross product */
Vec2 cross(const Vec2& v) const {
return Vec2(y - v.y, x - v.y);
}
float length() const {
return std::sqrt(length2());
}
/** Square of length */
float length2() const {
return x*x + y*y;
}
/** Distance to other vector */
float distance(const Vec2& v) const {
return std::sqrt(distance2(v));
}
/** Distance to other vector squared */
float distance2(const Vec2& v) const {
float dx = x - v.x;
float dy = y - v.y;
return dx*dx + dy*dy;
}
/** Normalize vector. The length after normalization is 1 */
void normalize() {
scale(1 / length());
}
/** set new value */
void set(float _x, float _y) {
x = _x;
y = _y;
}
/** Rotate vector by angle radians */
void rotate(float angle) {
float len = length();
angle += atan2(y, x);
x = cos(angle) * len;
y = sin(angle) * len;
}
/** Create vector projection: u projected to *this */
Vec2 projection(const Vec2& u) const {
Vec2 p = *this;
float len = length();
p.scale(this->dot(u) / (len * len));
return p;
}
};
#endif