鏡像問題:你写过的最坑爹的代码是什么?
话说postgresql的hstore数据类型我一直用得很爽,后来有消息说postgresql 9.4要大幅度强化hstore
当时正在准备做我的nodejs orm,因为我的下一个应用希望用到文档数据库的特性,我又不喜欢mongodb,这个消息实在是让我喜出望外,可以继续用我喜欢的postgresql了
所以,我就干脆自己来撸一个支持新语法的hstore的js encoder/decoder,我应该是nodejs社区里面第一个干这个的,只要9.4一发布,我就可以马上用到新特性,还可以顺便造福社区,很屌吧
hstore-js,这个就是我花了几天时间撸出来的成果,还学习了用状态机做语法分析,挺好玩的
冲得太快容易成为烈士,这是真理!过了几个月,我看到了这个新闻...
学了HTML/JAVASCRIPT3个月 在不懂OO,原型、闭包等概念的情况下硬是搞出了一套基于HTML5-canvans的游戏引擎,代码。。回去找找 如果还能让他跑起来就补个地址
大学第一节C语言课,一节课时间看完整本谭浩强
(之前没有接触过C语言,但是有文曲星GVBASIC基础)
课下研究了下graph mode
,然后第二节上机课,写出俄罗斯方块
,刚看了下只有180行
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#define ESC 0x1B
#define UP 0x48
#define DOWN 0x50
#define LEFT 0x4b
#define RIGHT 0x4d
#define ENTER 13
#define SPACE ' '
#define LEFTSIDE 122
#define UPSIDE 10
#define SIZE 3
#define FULL -1
#define WTTM 1.0
#define BOX bar(LEFTSIDE+xx*22,UPSIDE+(yy-3)*22,LEFTSIDE+xx*22+20,UPSIDE+(yy-3)*22+20);
typedef enum {Continue,Next,Quit,Over} ctrlcode;
typedef enum {No,Yes} bool;
int data[7][4][4]={
{{0x4000,0x4000,0x4000,0x4000},
{0x0000,0x0000,0x0000,0xF000},
{0x4000,0x4000,0x4000,0x4000},
{0x0000,0x0000,0x0000,0xF000}},
{{0x0000,0x0000,0x6000,0x6000},
{0x0000,0x0000,0x6000,0x6000},
{0x0000,0x0000,0x6000,0x6000},
{0x0000,0x0000,0x6000,0x6000}},
{{0x0000,0x2000,0x2000,0x6000},
{0x0000,0x0000,0x4000,0x7000},
{0x0000,0x6000,0x4000,0x4000},
{0x0000,0x0000,0xE000,0x2000}},
{{0x0000,0x4000,0x4000,0x6000},
{0x0000,0x0000,0x7000,0x4000},
{0x0000,0x6000,0x2000,0x2000},
{0x0000,0x0000,0x1000,0x7000}},
{{0x0000,0x4000,0x6000,0x2000},
{0x0000,0x0000,0x3000,0x6000},
{0x0000,0x4000,0x6000,0x2000},
{0x0000,0x0000,0x3000,0x6000}},
{{0x0000,0x2000,0x6000,0x4000},
{0x0000,0x0000,0xC000,0x6000},
{0x0000,0x2000,0x6000,0x4000},
{0x0000,0x0000,0xC000,0x6000}},
{{0x0000,0x4000,0x6000,0x4000},
{0x0000,0x0000,0x7000,0x2000},
{0x0000,0x2000,0x6000,0x2000},
{0x0000,0x0000,0x4000,0xE000}}};
static int aline[24]={0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xE007,0xFFFF};
char scoretext[10]={0};
char block,block2,type,type2;
char x,y,xx,yy,i,ascore;
long allscore=0;
long score[5]={0,1000,3000,6000,10000};
clock_t begin,end;
double waittime=WTTM;
ctrlcode step;
bool wait()
{end=clock();
if((double)(end-begin)/CLK_TCK<waittime)return Yes;
else {waittime=WTTM;return No;}
}
void rndblk()
{block=block2;type=type2;
block2=random(7);type2=random(4);
x=6;y=4;
aline[4]=aline[3]=aline[2]=aline[1]=aline[0]=0xE007;
}
void display()
{setfillstyle(0,BLACK);
bar(210,10,430,450);
setfillstyle(1,WHITE);
for(yy=4;yy<23;yy++)
{for(xx=4;xx<14;xx++)
{if((aline[yy]>>(16-xx))&1)BOX}
}
setfillstyle(1,block+1);
for(yy=y;yy>=y-SIZE&&yy>=SIZE;yy--)
for(xx=x+1;xx<=x+1+SIZE;xx++)
{if((data[block][type][3-y+yy]>>(16-xx+x))&1)BOX}
}
char inkey()
{char _inkey=0;
if(kbhit())
{do{_inkey=getch();}while(kbhit());}
return(_inkey);
}
void work()
{for(i=0;i<=SIZE;i++)
aline[y-i]|=data[block][type][SIZE-i]>>x;
ascore=0;
for(i=0;i<=SIZE;i++)
{if(aline[y-i]==FULL)
{i--;
for(yy=y;yy>0;yy--)aline[yy]=aline[yy-1];
ascore++;
}
}
allscore+=score[ascore];
}
bool pass(char _x,char _y,char _type)
{for(i=0;i<=SIZE;i++)
{if((data[block][_type][SIZE-i]>>_x)&aline[_y-i])return No;}
return Yes;
}
ctrlcode control()
{switch(inkey())
{case UP:if(pass(x,y,(type+1)%4)) type=(type+1)%4;display();break;
case LEFT:if(pass(x-1,y,type))x--;display();break;
case RIGHT:if(pass(x+1,y,type))x++;display();break;
case DOWN:waittime=0;break;
case SPACE:while(pass(x,y+1,type))++y;waittime=0;break;
case ESC:return Quit;
default:;
}
if(!wait())
{waittime=WTTM;
if(pass(x,y+1,type))
{y++;display();
begin=clock();
return Continue;
}
else {work();
return Next;}
}
return Continue;
}
void quit()
{printf("quit!");
getch();
exit(0);
}
void over()
{printf("over!");
getch();
exit(0);
}
void play()
{randomize();
rndblk();
do{rndblk();
display();
begin=clock();
setfillstyle(1,BLACK);
bar(208,455,432,479);
sprintf(scoretext,"SCORE %ld",allscore);
outtextxy(320,465,scoretext);
do{step=control();
}while(step==Continue);
}while(step==Next);
if(step==Quit)quit();
if(step==Over)over();
}
void init()
{int graphdriver=VGA,graphmode=VGAHI;
initgraph(&graphdriver,&graphmode,"c:\\turboc2");
settextjustify(1,1);
settextstyle(1,0,3);
rectangle(208,8,432,452);
rectangle(206,6,434,454);
}
void main()
{init();
play();
}
c++ 协程:
//
//
#if !defined(CO_H)
#define CO_H
#define cobegin switch (coroutine::ip) { case 0:
#define coend coreturn; } COLEND:
#define coreturn do { coroutine::ip = -1; goto COLEND; } while (0)
#define coyield _coyield(__COUNTER__+1)
#define _coyield(x) do { coroutine::ip = x; goto COLEND; case x:; } while (0)
#define coyieldfrom(c) while ((c).coroutine::resume()) { coyield; }
class coroutine
{
public:
coroutine() : ip(0) {}
bool resume() { return ip != -1 && (run(), ip != -1); }
virtual void run() = 0 {}
public:
int ip;
};
#endif
基于 http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
以前写一个充值卡号生成的程序,自己的机器是64位的,写完测试什么的都没问题,可悲的是正式的服务器是32位,溢出了,5000张卡最后其实只有几个号码……然后,我就默默的离开了那家公司。
1 回答391 阅读
1 回答603 阅读
大概算这个吧:
https://github.com/Cirru/interpreter/blob/master/cirru/function.cirru
代码内容就是个 fibonacci 函数, 进行了一次求值.
装逼之处在于语法和解释器都是我设计的, GitHub 上支持对应语法的高亮.
以及设立了对应网站和 GitHub 帐号:
http://cirru.org
http://github.com/Cirru/