pouët.net

Random line of code thread

category: code [glöplog]
Code: move.l d0,d1 ; copy lsl.w #4,d0 ; multiply by 40 lsl.w #3,d1 add.w d0,d0 add.w d1,d0


on ARM:
Code: MOV R1,R0,LSL #3 ADD R1,R1,R0,LSL #5
added on the 2009-04-08 14:17:37 by mrhill mrhill
Code: !MACRO Interpolate .x1, .y1, .x2, .y2, .step { !for i, .step { !byte MOVE, .x1 - i * ((.x1-.x2) / .step), .y1 - i * ((.y1-.y2) / .step) !byte WAIT,0 } !byte MOVE,.x2,.y2 }
added on the 2009-04-08 14:36:14 by Skate Skate
http://alan.umcs.lublin.pl/~mistrall/tajne/python/EXEPACKER/
Packs dlls and other resources into one exe ;]
added on the 2009-04-08 23:13:22 by vestige vestige
gl_FragColor=texture2D(t,x)*.43+(texture2D(t,x-vec2(.02,0))+texture2D(t,x+vec2(.02,0))+texture2D(t,x-vec2(0,.02))+texture2D(t,x+vec2(0,.02)))*.15;
added on the 2009-04-09 04:07:38 by ferris ferris
(shouldn't that .43 be .4?)

#include <malloc.h>
added on the 2009-04-09 10:55:50 by iq iq
Code: idozit :: Int -> BeatData -> IO () idozit beat beatdata = (snd $ head $ dropWhile (\xx -> fst xx <= beat) parts) beatdata

^^ this is the "sync engine" of our bp demo. the first line actually optional, so it's really one line!
added on the 2009-04-15 12:16:45 by blala blala
Code: return $success ? true : false


I just encountered this beauty in some code here (at the place I work).

Yes, web development is soul destroying.
added on the 2009-04-15 13:01:00 by spinor spinor
Code:/* THIS CODE IS CONFIDENTIAL */
added on the 2009-04-15 13:06:24 by decipher decipher
Code:ISR (TIMER1_COMPA_vect) { // Get rid of Jitter asm volatile ( "lds r24, 132 \n\t" // 2 // ////////////////////////// HACK WARNING! ATMega644 TCNT1 IO Position "andi r24,7 \n\t" // 1 "cpi r24,7 \n\t" // 1 "breq 1f \n\t" // 1/2 "cpi r24,6 \n\t" // 1 "breq 2f \n\t" // 1/2 "cpi r24,5 \n\t" // 1 "breq 3f \n\t" // 1/2 // "cpi r24,4 \n\t" // 1 // "breq 4f \n\t" // 1/2 // "cpi r24,3 \n\t" // 1 // "breq 5f \n\t" // 1/2 // "cpi r24,2 \n\t" // 1 // "breq 6f \n\t" // 1/2 // "cpi r24,1 \n\t" // 1 // "breq 7f \n\t" // 1/2 "nop \n\t" "rjmp 8f \n\t" // "cpi r24,0 \n\t" // 1 // "breq 8f \n\t" // 1/2 "1: \n\t" "nop \n\t" "2: \n\t" "nop \n\t" "3: \n\t" "nop \n\t" "4: \n\t" "nop \n\t" "5: \n\t" "nop \n\t" "6: \n\t" "nop \n\t" "7: \n\t" "nop \n\t" "8: \n\t" "nop \n\t" //: : "M" (_SFR_IO_ADDR(TCNT1)) );
Dunno why, but that should have been BACKSLASHnBACKSLASHt and not just nt behind the ASM lines.
spinor: optimize it to "!!$success"!.
added on the 2009-04-15 13:15:31 by ryg ryg
Code:demo::Editor::get()->setVisible(true);
@ryg: When I did some c (some hundred years ago) I also used the double negation until I discovered that the WATCOM compiler removed them in optimization to (success == !!success). I probably spend some hours figuring that out. Actually I like the idea, that nowadays others struggle for me with C++ and I can relax programming python.
added on the 2009-04-15 23:28:56 by pixtur pixtur
@spinor: that part would fall under "comedy", eh ?
added on the 2009-04-15 23:32:21 by d0DgE d0DgE
Code:(defun render-objects () (with-camera-transform (mapc #'render-object objects)))
Greets to blala for haskell-demos. I'd like to see more democoders using very high-level languages, and I really liked your breakpoint08 entry with the impossible-to-remember name.
added on the 2009-04-17 15:03:19 by main main
ah, thanks. the trick is to remember "mrs. pavlov" only, and then the pouet search tells you the rest :)

and now, back to the topic:
Code: second :: (b -> c) -> (a,b) -> (a,c) second f (x,y) = (x, f y)
added on the 2009-04-17 15:42:05 by blala blala
Code: #define FLT(s,e,m) ((((s)&1)<<31)|(((127+(e))&0xFF)<<23)|((m)&0x3FFFFF))

Code:@LABEL 12 flush matchclr matchstr 1 7 "OK\13\10" !S8 sets the time, in seconds, that the modem must pause when the "," dial modifier is encountered in the dial string. !Currently the pause duration is set to 2 seconds. Increase the number to lengthen the duration. write "ATS8=2\13" matchread 60 pause 90 jump 101
added on the 2009-04-20 23:25:02 by neoneye neoneye
Probably the most embarassing code I have written for long:
Code: public void move() { Direction d = next_move; int pri_coord; float pri_sub, sec_sub; int dir_sign; next_move = Direction.NONE; switch(d) { case UP: case DOWN: pri_coord = y; pri_sub = y_sub; sec_sub = x_sub; dir_sign = d.y; break; case LEFT: case RIGHT: pri_coord = x; pri_sub = x_sub; sec_sub = y_sub; dir_sign = d.x; break; default: return; } if (!map.coordsAreWithin(x + d.x, y + d.y)) return; if (!map.tileOn(x + d.x, y + d.y).isTraversable()) { pri_sub += speed * dir_sign; if(pri_sub * dir_sign > 0) { pri_sub = 0; } } else { if (pri_sub != 0.0f) { if (speed < Math.abs(pri_sub)) { if (pri_sub < 0) { pri_sub += speed; } else { pri_sub -= speed; } } else { pri_sub += (speed - Math.abs(sec_sub)) * dir_sign; sec_sub = 0; } } else { pri_sub += speed * dir_sign; } } if (pri_sub * dir_sign > 1.0f) { pri_coord += 1 * dir_sign; pri_sub -= 1.0f * dir_sign; } switch(d) { case UP: case DOWN: y = pri_coord; y_sub = pri_sub; x_sub = sec_sub; break; case LEFT: case RIGHT: x = pri_coord; x_sub = pri_sub; y_sub = sec_sub; break; } }

Trying to shorten this:
Code: private void moveY(int sign) { if (!map.coordsAreWithin(x, y - 1 * sign)) return; if (!map.tileOn(x, y - 1 * sign).isTraversable()) { y_sub -= speed * sign; if (y_sub * sign < 0) { y_sub = 0; } } else { if (x_sub != 0.0f) { if (speed < Math.abs(x_sub)) { if (x_sub < 0) { x_sub += speed; } else { x_sub -= speed; } } else { y_sub -= (speed - Math.abs(x_sub)) * sign; x_sub = 0; } } else { y_sub -= speed * sign; } } if (y_sub * sign < 1.0f) { y -= 1 * sign; y_sub += 1.0f * sign; } } private void moveX(int sign) { if (!map.coordsAreWithin(x - 1 * sign, y)) return; if (!map.tileOn(x - 1 * sign, y).isTraversable()) { x_sub -= speed * sign; if (x_sub * sign < 0) x_sub = 0; } else { if (y_sub != 0.0f) { if (speed < Math.abs(y_sub)) { if (y_sub < 0) y_sub += speed; else y_sub -= speed; } else { x_sub -= (speed - Math.abs(y_sub)) * sign; y_sub = 0; } } else x_sub -= speed * sign; } if (x_sub * sign < 1.0f) { x -= 1 * sign; x_sub += 1.0f * sign; } } public void move() { switch (next_move) { case LEFT: moveX(1); break; case RIGHT: moveX(-1); break; case UP: moveY(1); break; case DOWN: moveY(-1); break; } next_move = Direction.NONE; }

It's for a Bomberman game, and it is the movement code.
I thought it was the "Random ***LINE*** of Code Thread" :P

Ah hell I'll indulge :D

Code: fld dword [rbuffer + ecx * 4] fmul dword [delayamt] fadd dword [lbuffer + edx * 4] fstp dword [lbuffer + edx * 4] fld dword [lbuffer + ecx * 4] fmul dword [delayamt] fadd dword [rbuffer + edx * 4] fstp dword [rbuffer + edx * 4]


X-Delay :)
added on the 2009-04-21 01:54:08 by ferris ferris
@iq from earlier: Correctly speaking yes, but it's glowfilter code, not just blur ;)
added on the 2009-04-21 01:55:41 by ferris ferris
<marquee> O~~~ </marquee>

(Looks like sperms!)
vec3 n=normalize(vec3(f(t+vec3(.01,0,0))-d,f(t+vec3(0,.01,0))-d,f(t+vec3(0,0,.01))-d));
added on the 2009-04-21 06:58:06 by ferris ferris
I shortened it for you even betterer:

Code: public void move() { x += ( rand() % 3 ) - 1; y += ( rand() % 3 ) - 1; }
added on the 2009-04-21 11:43:47 by doomdoom doomdoom
Code: elif cmd == '353': #NAMES names = tokens[5:] whoisList = list() for name in names: name = name.lstrip(':@+#') whoisList.append(name) if name not in self.irc.users: self.irc.users[name] = user(name, self.irc, dontWhois=True) self.irc.send('WHOIS %s' % ','.join(whoisList))
added on the 2009-04-21 11:50:51 by stijn stijn

login