Skip to content

Instantly share code, notes, and snippets.

@wolf0403
wolf0403 / json.l
Created February 26, 2012 22:08 — forked from justjkk/LICENSE
Parsing JSON with lex and yacc
%{
#include<stdio.h>
#include "y.tab.h"
char *strclone(char *str);
/*
#define STRING "str"
#define NUMBER "number"
#define O_BEGIN "o_begin"
#define O_END "o_end"
#define A_BEGIN "a_begin"
@wolf0403
wolf0403 / s.py
Created November 12, 2012 09:14
Python shell that doesn't work
#!/usr/bin/python
import os
from subprocess import call
import subprocess as sp
class _cmd (object):
def __init__(self, sh, cmd):
self.c = cmd
self.sh = sh
@wolf0403
wolf0403 / gist:4363542
Last active December 10, 2015 01:58
Tornado test script
#!/usr/bin/env python
import tornado.ioloop
import tornado.web
import tornado.process
import tornado.netutil
from tornado.httpserver import HTTPServer
import time
class MainHandler(tornado.web.RequestHandler):
@wolf0403
wolf0403 / gist:4371628
Created December 25, 2012 04:34
Test web.py script
#!/usr/bin/env python
import web
import sys, time, os
### URL Routing
urls = (
'(.*)', 'fallback',
);
@wolf0403
wolf0403 / nocomments.py
Last active December 16, 2015 05:38
No comments
#!/usr/bin/env python
import sys, re
from getopt import getopt
'''
Just too lazy figuring out egrep alone, so...
$ ./nocomment.py proc_line < md.c
proc_line (char *line, unsigned len, struct session_args *a) {
@wolf0403
wolf0403 / LoginTest.py
Created April 30, 2013 11:36
Tornado AsyncHTTPTestCase client doesn't handle Cookies within itself thus can't be used to test session based scenarios. This code provides basic support for that.
TEST_URL='/resource'
LOGIN_URL='/login'
LOGOUT_URL='/logout'
application = tornado.web.Application([
(LOGIN_URL, LoginHandler),
(LOGOUT_URL, LogoutHandler),
(TEST_URL, ResourceHandler),
], cookie_secret='cookie_secret', login_url=LOGIN_URL)
@wolf0403
wolf0403 / client.py
Created July 12, 2013 16:10
MongoDB replica setup
# When connecting using pymongo, specify "replicaSet"
# This allows default port running secondary nodes.
pymongo.MongoClient(replicaSet='rs0', slaveOk=True)
@wolf0403
wolf0403 / node-phantom-reverseproxy.js
Created July 22, 2013 05:21
Deajaxify page for Google crawler with Node.js / Phantom.js
var http = require('http'),
phantom=require('node-phantom'), // https://github.com/alexscheelmeyer/node-phantom
urlparse = require('url');
function proxy_url(url, res) {
phantom.create(function(err,ph) {
return ph.createPage(function(err,page) {
@wolf0403
wolf0403 / Makefile
Last active January 1, 2016 04:48
How to define static member functions of class templates correctly.
a.out: a.o b.o def.o
%.o: %.cpp
clang++ -c -o $@ $<
@wolf0403
wolf0403 / workers.py
Created December 30, 2013 14:28
Worker model with Redis and Gevent
#!/usr/bin/env python
from __future__ import print_function
import gevent
import gevent.monkey
gevent.monkey.patch_all()
import gevent.hub
import redis