Skip to content

Instantly share code, notes, and snippets.

@clowwindy
clowwindy / 12306.user.js
Created January 8, 2012 10:46 — forked from quietlynn/12306.user.js
12306 Auto Query => A javascript snippet to help you book ticket
/*
12306 Auto Query => A javascript snippet to help you book tickets online.
Copyright (C) 2011-2012 Jingqin Lynn
Includes jQuery
Copyright 2011, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
Includes Sizzle.js
@clowwindy
clowwindy / gist:1699170
Created January 29, 2012 14:58
json to Python object
input_str = "{'a':[{'b':'1','d':'3',},{'b':'2','d'='a'},{'b':'3','d':'4'}],'c':'1'}"
import json
class storage(object):
def __init__(self, dct):
self.__dict__ = dct
result = json.loads(input_str.replace("'",'"').replace("=", ":").replace(",}","}"), object_hook=storage)
@clowwindy
clowwindy / gist:2643869
Created May 9, 2012 11:28
decode escaped unicode
var stringToParse = '\\u4f60\\u8bd5\\u8bd5';
JSON.parse('"'+ stringToParse + '"');
<a href="#" title="blue">blue</a>
<a href="#" title="red">red</a>
<script>
function bgc() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; ++i) {
links[i].onclick = (function() {
var color = links[i].title;
return function() {
document.body.style.backgroundColor = color;
import os
import sys
import getpass
import subprocess
password = getpass.getpass('input password:')
for line in open('server_list.txt'):
line = line.strip()
print line
os.system('scp init_directory.sh %s:~/' % line)
s = subprocess.Popen(['ssh', line, "sudo", "-S", "bash", "init_directory.sh"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@clowwindy
clowwindy / print_current_frame.py
Created August 3, 2012 07:45
print current frame
#!/usr/bin/python
import inspect
LINES_TO_PRINT = 5
# blarblarblar
# foobar
frame = inspect.currentframe()
@clowwindy
clowwindy / print_current_frame.py
Created August 3, 2012 07:46
print current frame
#!/usr/bin/python
import inspect
LINES_TO_PRINT = 5
# blahblahblah
# foobar
frame = inspect.currentframe()
@clowwindy
clowwindy / gist:3480048
Created August 26, 2012 14:20
different
$ curl https://raw.github.com/cheshirecats/CuriousWall/2d1387e6d15571e7c6986e0cb30df1114b1c8030/account.php > 1
$ curl https://raw.github.com/cheshirecats/CuriousWall/master/account.php > 2
$ hexdump -c 1 | head -n 2
0000000 < ? p h p \r \n e r r o r _ r
0000010 e p o r t i n g ( E _ A L L ) ;
$ hexdump -c 2 | head -n 2
0000000 < ? p h p \n e r r o r _ r e
@clowwindy
clowwindy / node-websockets.js
Created September 24, 2012 11:30
node websockets
var srv = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('okay');
});
srv.on('upgrade', function(req, socket, head) {
socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
'Upgrade: WebSocket\r\n' +
'Connection: Upgrade\r\n' +
'\r\n');
@clowwindy
clowwindy / test2-no-sib.s
Created September 28, 2012 06:42
-fno-optimize-sibling-calls
.file "test.c"
.text
.p2align 4,,15
.globl fibonacci
.type fibonacci, @function
fibonacci:
.LFB11:
.cfi_startproc
movq %rbx, -48(%rsp)
movq %rbp, -40(%rsp)