Skip to content

Instantly share code, notes, and snippets.

import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.gen
from tornado import httpclient
@tornado.gen.coroutine
def fetch_json(url):
response = yield httpclient.AsyncHTTPClient().fetch(url)
#include <iostream>
template<unsigned long n>
struct Factorial {
enum {value = n * Factorial<n-1>::value};
};
template<>
struct Factorial<0> {
enum {value = 1};
#!/usr/bin/python
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (jspenguin@jspenguin.org)
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
@cedricporter
cedricporter / signal_handler_surprise_me.py
Created July 10, 2014 11:41
signal handler surprises me
# print 1,2,3,4,5,-1,6,7,8...
import signal
import sys
count = 0
def signal_handler(signum, frame):
global count
count = -1
print 'sig', count
@cedricporter
cedricporter / signal_handler_me_understand.py
Created July 10, 2014 11:42
signal handler that me understand
# 1,2,3,4,5,-1,0,1,2...
import signal
import sys
count = 0
def signal_handler(signum, frame):
global count
count = -1
print 'sig', count
@cedricporter
cedricporter / increasing_file.py
Created July 10, 2014 11:43
make increasing file
# python increasing_file.py >> out.log
import os
import time
import sys
while True:
print "asdf"
sys.stdout.flush()
time.sleep(0.01)
@cedricporter
cedricporter / gen_elisp_opcode_replace.py
Created July 10, 2014 12:11
Generate Elisp code for python opcode replace.
"""
opcode module - potentially shared between dis and other modules which
operate on bytecodes (e.g. peephole optimizers).
"""
__all__ = ["cmp_op", "hasconst", "hasname", "hasjrel", "hasjabs",
"haslocal", "hascompare", "hasfree", "opname", "opmap",
"HAVE_ARGUMENT", "EXTENDED_ARG"]
cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is',
@cedricporter
cedricporter / python-opcode-translate-emacs-lisp.el
Last active August 29, 2015 14:03
Python Opcode translator for Emacs
; Made by Stupid ET <et@everet.org>
(progn
(replace-string "[opcode: 0]" "[opcode: 0 STOP_CODE]")
(beginning-of-buffer)
(replace-string "[opcode: 1]" "[opcode: 1 POP_TOP]")
(beginning-of-buffer)
(replace-string "[opcode: 2]" "[opcode: 2 ROT_TWO]")
(beginning-of-buffer)
(replace-string "[opcode: 3]" "[opcode: 3 ROT_THREE]")
(beginning-of-buffer)
@cedricporter
cedricporter / show-pmset-in-alfred.py
Last active August 29, 2015 14:03
Print pmset in alfred
from subprocess import Popen, PIPE
output = Popen(["pmset", "-g", "assertions"], stdout=PIPE).communicate()[0]
def createItem(line, tag="title"):
return """<item arg="textEncoded"><%s>%s</%s></item>""" % (tag, line.strip(), tag)
def search(searchWord, tag="title"):
@cedricporter
cedricporter / backup_db.sh
Last active August 29, 2015 14:04
MySQL backup script
#!/bin/sh
# # m h dom mon dow user command
# 30 4 * * 1,3,4 root /root/backup_db.sh
# 41 4 * * 1,3,4 root /root/dropbox.py start
# 57 4 * * 1,3,4 root /root/dropbox.py stop
mysqldump -u root -p'password' --all-databases | gzip > /root/Dropbox/backups/mysql_bak/`date +%F`.sql.gz