Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Post Code

Name: Anonymous 2011-03-04 21:33

One recurring complaint is that nobody talks about code on /prog/. So everyone write go and write some code, any code, that does something, anything, and post it. A small explanation wouldn't go amiss either.

Name: Anonymous 2011-03-21 16:40


          ∧_∧  / ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
          ( ´‿ゝ`) < Hi there.
        /    |    \________
       /       .|     
       / "⌒ヽ |.イ |
   __ |   .ノ | || |__
  .    ノく__つ∪∪   \
   _((_________\
    ̄ ̄ヽつ ̄ ̄ ̄ ̄ ̄ ̄ | | ̄
   ___________| |
    ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| |

Name: Anonymous 2011-03-21 16:51

faggot cat

Name: Anonymous 2011-03-21 18:45


          ∧_∧  / ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
          ( ≖‿≖) < Hax my anus.
        /    |    \________
       /       .|     
       / "⌒ヽ |.イ |
   __ |   .ノ | || |__
  .    ノく__つ∪∪   \
   _((_________\
    ̄ ̄ヽつ ̄ ̄ ̄ ̄ ̄ ̄ | | ̄
   ___________| |
    ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| |

Name: Anonymous 2011-03-21 22:37


loadUnit path
 -> type:(split \/ path).rhd.asStr
 -> u:("$path/unit.txt".fget |> map ?.asChr.{\Newline->\Space; x->x} |> parseST
       |> map [_ a b]~>[a.asStr b.eval] |> sort by=lhd)
 -> s:("$path/gfxes/".ls |> map (drop fullPrefix.len+1 ?)
       |> map x~>[(split \. x.asFilename).lhd x] |> sort by=lhd
       |> bmap (loadUnitFrames u."building".{ye?->1; _->5} ?))
 -> !s."default" |> (_ [5++dummyGfx])
 -> for [t _] in tilesets s.t.{no? -> s.t=:s."default"}
 -> [@!u "type"=type "gfxes"=(bdel "default" s) "layer"=tileMasks.(u."layer")
         "frame"=0 "wounds"=0]
 -> u."moveMask"=:(fnd [c@_]~>u.c moveClasses|>?,1 |>map tileMasks.? |> [0@?] |> fold or)
 -> !u."hp"     |> (_ 1)
 -> !u."size"   |> (_ [1 1])
 -> !u."selSize"|> (_ u."size"*32)
 -> !u."sight"  |> (_ 0)
 -> !u."attack" |> (_ "melee")
 -> for dir in (ls "$dataPrefix/units/$(u."type")/sounds/")
      u."sounds".(split \/ dir |> ?.rtl.rhd) =: dir.ls
 -> !u."sounds"."selected" |> (_ ["$dataPrefix/sounds/ui/click.wav"])
 -> u."building".{ye?
     -> u."sounds"."dead" =: "$dataPrefix/sounds/misc/wreckage/".ls}
 -> [type=u @!unitTypes]

Name: Anonymous 2011-03-21 22:40

>>244

layer=2 land=ye corpse="orc_corpse" attack="sword"
hp=60 damage=6 range=1 armor=2 speed=10 sight=4 organic=ye
cost=["gold"=600 "time"=60]
anims=["still"=[@stillAnim 'rotate]
       "move"='((0 2 3) (5 1 3) (5 2 3) (10 1 2) (10 1 3) (0 1 2)
                (0 2 3) (15 1 3) (15 2 3) (20 1 2) (20 1 3) (0 1 2))
       "death"='((45 3) (50 3) (55 100))
       "attack"='((25 3) (30 3) (35 3) attack (40 5) (0 10))]

Name: Anonymous 2011-03-21 23:04

>>244,245
Valid perl code.

Name: Anonymous 2011-03-21 23:15

>>246
It has nothing to do with perl.

Name: Anonymous 2011-03-21 23:31

>>247
It's valid perl code.

Name: Anonymous 2011-03-22 0:57

>>246
VALID BBCODE.

Name: Anonymous 2011-03-22 6:55

>>248
doesn't compile

Name: Anonymous 2011-03-22 9:35

>>250
Any code is valid perl code.

Name: Anonymous 2011-03-22 21:19

I'll not let this thread die.

Name: Anonymous 2011-03-22 21:56

>>2
Someone's assuming the use of an optimizing compiler
Guess what?  Not all compilers are optimizing compilers!

Name: Anonymous 2011-03-22 22:05

>>253
The only difference is the order of the instructions, then.

Name: Anonymous 2011-03-22 22:20

>>254
which is the only difference in the source
are you retarded?

Name: Anonymous 2011-03-22 22:28

>>255
No. YHBT.

Name: Anonymous 2011-03-22 22:31

>>256
troll harder, faggot

Name: Anonymous 2011-03-22 23:11

>>257
YHBT, YWNBT.

Name: Anonymous 2011-03-31 9:43

I miss this thread

Name: Anonymous 2011-03-31 10:15

>>259
Take some R5RS module system code. http://paste.lisp.org/display/121037

Bump over the shit.

Name: Anonymous 2011-03-31 12:05

BUMP

Name: Anonymous 2011-03-31 12:35

Pantsu

Name: Anonymous 2011-03-31 12:51

>>260
fuck you lithper

Name: Anonymous 2011-03-31 13:47


// Warning: Faggotry ahead.
package faggotry;

public class Faggotry {
  private final static String[] PUNCTUATION_LIST = {"\"", "\'", "?"};
  private final static String SUBJECT = "GOTO";
  private final static String PREDICATE = " Considered Harmful";
  private final static void outputFeculence(String[] punctuationList, String subject, String predicate) {
    String feculence = subject + predicate;
    int i = 1;
    int n = (int) Float.POSITIVE_INFINITY;
    while (i <= n) {
      System.out.println(feculence);
      i++;
      boolean isOdd = i % 2 == 1;
      boolean isLast = i == n;
      String punctuation = isOdd ? punctuationList[0] : punctuationList[1];
      feculence = punctuation + feculence + punctuation + predicate;
      if (isLast) {punctuation = punctuationList[2];}
      feculence = isLast ? feculence + punctuation : feculence;
    }
  }
  public final static void main(String[] args) {
    outputFeculence(PUNCTUATION_LIST, SUBJECT, PREDICATE);
  }
}
// Warning: Faggotry behind.

Name: Anonymous 2011-03-31 13:52

Whoops, forgot to fix line 21.

// Warning: Faggotry ahead.
package faggotry;

public class Faggotry {
  private final static String[] PUNCTUATION_LIST = {"\"", "\'", "?"};
  private final static String SUBJECT = "GOTO";
  private final static String PREDICATE = " Considered Harmful";
  private final static void outputFeculence(String[] punctuationList,
                                            String subject, String predicate) {
    String feculence = subject + predicate;
    int i = 1;
    int n = (int) Float.POSITIVE_INFINITY;
    while (i <= n) {
      System.out.println(feculence);
      i++;
      boolean isOdd = i % 2 == 1;
      boolean isLast = i == n;
      String punctuation = isOdd ? punctuationList[0] : punctuationList[1];
      feculence = punctuation + feculence + punctuation + predicate;
      if (isLast) {
        punctuation = punctuationList[2];
        feculence = feculence + punctuation;
      }
    }
  }
  public final static void main(String[] args) {
    outputFeculence(PUNCTUATION_LIST, SUBJECT, PREDICATE);
  }
}
// Warning: Faggotry behind.

Name: Anonymous 2011-03-31 20:48

Name: Anonymous 2011-04-01 2:18

Name: Anonymous 2011-04-01 2:24

This is you when you come to prog

youtube.com watch?v=wPXk_rcrUjY

Name: Anonymous 2011-04-01 3:48

Clipboard.c

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char ** argv)
{
int ret = 0;
FILE * file = fopen(argv[1], "r");
ret = fseek(file, 0, SEEK_END);
if (ret != 0)
{
msg("Can't allocated this much, hurrr");
fclose(file);
exit(1);
}

fclose(file);
return 0;
}

Name: Anonymous 2011-04-01 4:41

#include <stdio.h>

int main(){
  unsigned int b[] = {0x002a2a2a, 0x92a67bad, 0x5a949663, 0x594a5a19,
                      0x735d92f1, 0x400fd9ae, 0}, *a=b+1;
  char c[] = "\n\0        ";
  while((*a>>=4-3*(*a&1))&~7?1:*a++)
    printf("%s",*a&1?(char*)b:!(12-*a&15)?c:c-((*a&15)>>1)+9);
  return 0;
}

Name: Anonymous 2011-04-01 4:45

>>270
Have you exploited your buffer overflows today?

Name: Anonymous 2011-04-01 4:48

>>272
I never overflow.

Name: Anonymous 2011-04-01 7:41

http://codepad.org/03QsZHfW
It outputs something resembling a tree. Clever pointer tricks like this are the reason C always has an edge on "safe languages".

Name: Anonymous 2011-04-01 8:13

and here is the "/prog/" version. a lot more messy but less data
http://codepad.org/LCvbTSU2
#include <stdio.h>
int main(){
  char *z =  "    ***\0   ";
  unsigned int b[] = { 0x77770000, 0x55155515, 0x40017717, 0x70014001, 0}, *c=b-1, i=0;

  while(printf(!*(c+=++i-8&1)*8+" %s\t\n%s\t"+(!(i-1))*5, z+(i>5?7:i-1+!i), z+(i>4?7:i)))
  do printf("%s", z+(8>>(*c&1)));
  while((*c>>=1)&&!(*c>>15&1 && !(*c>>16)&&(*c>>=1)));


  return 0;
}

Name: Anonymous 2011-04-01 21:35


doHarvest u -> a:u."act" d:a."dst"
 -> d.{[p@_] -> r:a."res"
             -> r.{no? -> r=:(canHarvest p a."harvests") -> u."act"."res"=:r}
             -> if u.r>=100
                then {-> o:unitTypes."store"
                      -> order [@o "back"=d "res"=r "depot"=a."depot"] u}
      ;id -> [[id u."id"] @!hideUnits]
          -> o:unitTypes."harvest_inside"
          -> u."act"=:[@o "dst"=d "depot"=a."depot" "range"=1
                          "res"=(canHarvest id a."harvests")]}
 -> u

fixHarvest u -> a:u."act" d:a."dst" r:a."res" hs:a."harvests"
 -> cnd{u.r>=100
         -> order [@unitTypes."store" "back"=d "res"=r "depot"=a."depot"] u
       ;t:(findTile u."tile" (pointInRect wr ?) (canHarvest ? hs) (abs xy-?) l=6).rhd
         -> [@!u."act" "dst"=[t [1 1]] "r"=no]
       ;ye -> u."act"=:no}
 -> u

doHarvestInside u -> r:u."act"."res"
 -> if u.r<100 then [[u."id" 5]@!nqs.(u."parent")."harvest"]
               else {-> a:u."act" [u."id"@!showUnits]
                     -> o:unitTypes."store"
                     -> order [@o "back"=a."dst" "res"=r "depot"=a."depot"] u}
 -> u


doStore u
 -> a:u."act" r:a."res" depot:a."depot" t:(if depot units,depot)
 -> t.{dead? -> depot.{no? -> depot=:(findDepot r u)}
             -> depot.{ye? -> u."act"."depot"=:depot
                      ;_  -> notify "Nowhere to store $r" -> u."act"=:no}
      ; _ -> if x:u."anims".r  u."anims"."move"=:x
          -> if a."near"
             then {-> [[u."id" r u.r]@!nqs.(u."owner")."+"] -> u.r=:0
                   -> u."anims"."move" =: unitTypes.(u."type")."anims"."move"
                   -> o:unitTypes."harvest"
                   -> order [@o "dst"=a."back" "depot"=a."depot"] u}
             else {-> u."act"."near"=:ye -> u."act"."dst"=:depot}}
 -> u

Name: Anonymous 2011-04-01 21:36

>>275

layer=3 air=ye speed=999 range=1
harvests=["gold" "wood"] show="attack" effect=["harvest" 5]
rule=harvestRule do=doHarvest fix=fixHarvest

Name: Anonymous 2011-04-01 21:46

Name: Anonymous 2011-04-01 23:15


  [@!ui @(u."acts" |> map x~>
      ["icon"=icons.x "tint"=tints.(u."color")
       "onClick"={->a:unitTypes.x if a."targets" == ["self"]
                                  then order a u else uiTargeting=:a}
       "onHover"={->do t:unitTypes.x c:(t."cost"||t."ucost")
                   [["text"="$(t.prettyName)"]
                    @(map [? c.?] resNames |> keep ?,1 |>
                      map [r n]~>["icon"=resIcons.r "text"="$n"])]}])]

Name: BAMPU KOODO 2011-04-02 22:58


#lang racket/base
(require (for-syntax racket/base))
(require ffi/unsafe)

#|
Based on Python's struct.unpack

(unpack-bytes fmt bytestring)
  fmt         : string?
  bytesstring : bytes?

Unpacks bytestring according to fmt.

The first character of fmt determines the byte order, size and alignment of the data.
If omitted, (default-unpack-character) will be used.

Character  Byte order      Size     Alignment
@          native          native   native
#          native          native   none
=          native          fixed    none
<          little-endian   fixed    none
         big-endian      fixed    none
!          network         fixed    none

Meaning of the format characters:
(define *table*
  (make-hasheqv
   `((#\c ,@(make-table char #f))
     (#\b ,@(make-table byte #f))
     (#\B ,@(make-table ubyte #f))
     (#\? ,@(make-table bool #f))
     (#\h ,@(make-table short))
     (#\H ,@(make-table ushort))
     (#\i ,@(make-table int))
     (#\I ,@(make-table uint))
     (#\l ,@(make-table long))
     (#\L ,@(make-table ulong))
     (#\q ,@(make-table llong))
     (#\Q ,@(make-table ullong))
     (#\f ,@(make-table float))
     (#\d ,@(make-table double))
     (#\P ,@`((#\@ . ,unpack-pointer/na)
              (#\# . ,unpack-pointer/n))))))

Format   C Type         Racket Type    Size (=,>,<,!)
#\x      N/A            (pad byte)     1
#\c      char           char?          1
#\b      signed char    fixnum?        1
#\B      unsigned char  byte?          1
#\?      bool           boolean?       1
#\h      short          fixnum?        2
#\H      unsigned short fixnum?        2
#\i      int            fixnum?        4
#\I      unsigned int   fixnum?        4
#\l      long           fixnum?        4
#\L      unsigned long  fixnum?        4
#\q      long long      fixnum?        8
#\Q      unsigned long  fixnum?        8
         long
#\f      float          flonum?        4
#\d      double         flonum?        8
#\P      void*          fixnum?        N/A

TODO: count, defineable format characters, pack.

|#

; @, #, =, <, >, !
(define (unpack-char bytes idx)
  (cons (add1 idx)
        (integer->char (bytes-ref bytes idx))))

; @, #, =, <, >, !
(define (unpack-byte bytes idx)
  (cons (add1 idx)
        (let ((x (bytes-ref bytes idx)))
          (if (> x #x7F) (+ (- x) #x80) x))))

; @, #, =, <, >, !
(define (unpack-ubyte bytes idx)
  (cons (add1 idx)
        (bytes-ref bytes idx)))

; @, #, =, <, >, !
(define (unpack-bool bytes idx)
  (cons (add1 idx)
        ((compose not zero? bytes-ref) bytes idx)))

; big-endian = #t
(define ((unpack1 sign endianess size) bytes idx)
  (cons (+ idx size)
        (integer-bytes->integer bytes sign endianess idx (+ idx size))))
(define ((unpack2 endianess size) bytes idx)
  (cons (+ idx size)
        (floating-point-bytes->real bytes endianess idx (+ idx size))))

(define ((unpack-ctype1 sign type) bytes idx)
  (cons (+ (bitwise-and (+ idx (sub1 (ctype-alignof type)))
                        (bitwise-not (sub1 (ctype-alignof type)))))
        (integer-bytes->integer bytes sign (system-big-endian?) idx (+ idx (ctype-sizeof type)))))
(define ((unpack-ctype2 sign type) bytes idx)
  (cons (+ (bitwise-and (+ idx (sub1 (ctype-alignof type)))
                        (bitwise-not (sub1 (ctype-alignof type)))))
        (floating-point-bytes->real bytes (system-big-endian?) idx (+ idx (ctype-sizeof type)))))

(define (unpack-ctype1/noalign sign type)
  (unpack1 sign (system-big-endian?) (ctype-sizeof type)))
(define (unpack-ctype2/noalign sign type)
  (unpack2 (system-big-endian?) (ctype-sizeof type)))

(define-syntax (define-all stx)
  (define (suffix end)
    (case (syntax-e end)
      ((#t) "/BE")
      ((#f) "/LE")
      (else "")))
  (define (dat->stx sym end)
    (datum->syntax
     stx
     (string->symbol
      (string-append "unpack-" (symbol->string sym) (suffix end)))))
  (syntax-case stx ()
    ((~ e)
     (with-syntax ((unshort (dat->stx 'short #'e))
                   (unushort (dat->stx 'ushort #'e))
                   (unint (dat->stx 'int #'e))
                   (unuint (dat->stx 'uint #'e))
                   (unlong (dat->stx 'long #'e))
                   (unulong (dat->stx 'ulong #'e))
                   (unllong (dat->stx 'llong #'e))
                   (unullong (dat->stx 'ullong #'e))
                   (unfloat (dat->stx 'float #'e))
                   (undouble (dat->stx 'double #'e)))
       #'(begin
           (define unshort
             (unpack1 #t e 2))
           (define unushort
             (unpack1 #f e 2))
           (define unint
             (unpack1 #t e 4))
           (define unuint
             (unpack1 #f e 4))
           (define unlong
             (unpack1 #t e 4))
           (define unulong
             (unpack1 #f e 4))
           (define unllong
             (unpack1 #t e 8))
           (define unullong
             (unpack1 #f e 8))
           (define unfloat
             (unpack2 e 4))
           (define undouble
             (unpack2 e 8)))))))

(define-syntax (define-all2 stx)
  (define (suffix a)
    (case (syntax-e a)
      ((#t) "/na")
      ((#f) "/n")))
  (define (dat->stx sym end)
    (datum->syntax
     stx
     (string->symbol
      (string-append "unpack-" (symbol->string sym) (suffix end)))))
  (syntax-case stx ()
    ((~ e u1 u2)
     (with-syntax ((unshort (dat->stx 'short #'e))
                   (unushort (dat->stx 'ushort #'e))
                   (unint (dat->stx 'int #'e))
                   (unuint (dat->stx 'uint #'e))
                   (unlong (dat->stx 'long #'e))
                   (unulong (dat->stx 'ulong #'e))
                   (unllong (dat->stx 'llong #'e))
                   (unullong (dat->stx 'ullong #'e))
                   (unfloat (dat->stx 'float #'e))
                   (undouble (dat->stx 'double #'e))
                   (unpointer (dat->stx 'pointer #'e)))
       #'(begin
           (define unshort
             (u1 #t _short))
           (define unushort
             (u1 #f _ushort))
           (define unint
             (u1 #t _int))
           (define unuint
             (u1 #f _uint))
           (define unlong
             (u1 #t _long))
           (define unulong
             (u1 #f _ulong))
           (define unllong
             (u1 #t _llong))
           (define unullong
             (u1 #f _ullong))
           (define unfloat
             (u2 #f _float))
           (define undouble
             (u2 #f _double))
           (define unpointer
             (u1 #f _pointer)))))))

; <
(define-all #f)

; >, !
(define-all #t)

; =
(define-all (system-big-endian?))

; @
(define-all2 #f unpack-ctype1 unpack-ctype2)

; #
(define-all2 #t unpack-ctype1/noalign unpack-ctype2/noalign)

(define-syntax (make-table stx)
  (define (sym-suffix sym suffix)
    (datum->syntax
     stx
     (string->symbol
      (string-append "unpack-" (symbol->string (syntax-e sym))
                     suffix))))
  (syntax-case stx ()
    ((~ sym)
     #``((#\@ . ,#,(sym-suffix #'sym "/na"))
         (#\# . ,#,(sym-suffix #'sym "/n"))
         (#\= . ,#,(sym-suffix #'sym ""))
         (#\> . ,#,(sym-suffix #'sym "/BE"))
         (#\< . ,#,(sym-suffix #'sym "/LE"))
         (#\! . ,#,(sym-suffix #'sym "/BE"))))
    ((~ sym #f)
     #``((#\@ . ,#,(sym-suffix #'sym ""))
         (#\# . ,#,(sym-suffix #'sym ""))
         (#\= . ,#,(sym-suffix #'sym ""))
         (#\> . ,#,(sym-suffix #'sym ""))
         (#\< . ,#,(sym-suffix #'sym ""))
         (#\! . ,#,(sym-suffix #'sym ""))))))
        

(define *table*
  (make-hasheqv
   `((#\c ,@(make-table char #f))
     (#\b ,@(make-table byte #f))
     (#\B ,@(make-table ubyte #f))
     (#\? ,@(make-table bool #f))
     (#\h ,@(make-table short))
     (#\H ,@(make-table ushort))
     (#\i ,@(make-table int))
     (#\I ,@(make-table uint))
     (#\l ,@(make-table long))
     (#\L ,@(make-table ulong))
     (#\q ,@(make-table llong))
     (#\Q ,@(make-table ullong))
     (#\f ,@(make-table float))
     (#\d ,@(make-table double))
     (#\P ,@`((#\@ . ,unpack-pointer/na)
              (#\# . ,unpack-pointer/n))))))

(define default-unpack-character
  (make-parameter #\@ (λ (x) (if (mode-char? x) x (error 'default-unpack-character "no")))))

(define (mode-char? x)
  (case x
    ((#\@ #\# #\=
      #\< #\> #\!) #t)
    (else #f)))

(define (bytes-unpack fmt bytes)
  (let ((mode (if (mode-char? (string-ref fmt 0))
                  (string-ref fmt 0) #\@))
        (l (string-length fmt)))
    (let loop ((i (if (mode-char? (string-ref fmt 0)) 1 0))
               (idx 0)
               (r '()))
      (cond ((= i l) (reverse r))
            ((char=? (string-ref fmt i) #\x) (loop (add1 i) (add1 idx) r))
            ((char-whitespace? (string-ref fmt i)) (loop (add1 i) idx r))
            (else
             (let* ((x (hash-ref *table* (string-ref fmt i) (λ () (error 'bytes-unpack "what the fuck is a ``~a''?" (string-ref fmt i)))))
                    (x (cond ((assv mode x) => cdr) (else (error 'bytes-unpack "``~a'' has no mode ``~a''" (string-ref fmt i) mode))))
                    (x (x bytes idx)))
               (loop (add1 i)
                     (car x)
                     (cons (cdr x) r))))))))

#|
(bytes-unpack "> ii" #"\0\0\0\1\0\0\0\2") ; => '(1 2)
(bytes-unpack "< ii" #"\0\0\0\1\0\0\0\2") ; => '(16777216 33554432)
|#

Name: Anonymous 2011-04-03 15:11


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List