Skip to content

Instantly share code, notes, and snippets.

@baojie
baojie / hello_multiprocessing.py
Created July 21, 2013 07:04
Python multiprocessing hello world. Split a list and process sublists in different jobs
import multiprocessing
# split a list into evenly sized chunks
def chunks(l, n):
return [l[i:i+n] for i in range(0, len(l), n)]
def do_job(job_id, data_slice):
for item in data_slice:
print "job", job_id, item
# -*- coding: utf-8 -*-
"""
To install pylinkgrammar on Ubuntu
sudo apt-get install liblink-grammar4-dev cmake swig
pip install pylinkgrammar
"""
from pylinkgrammar.linkgrammar import Parser
@baojie
baojie / scan.sh
Last active April 27, 2023 03:57
Double-sided scanning in linux and converting to pdf. Dependency: sudo apt-get install xsane imagemagick
#!/bin/bash
scanimage --batch --batch-double
read -p "Flip papers in the feeder, last page on top. Press [Enter] key to start..."
endpage=$(echo "$(ls *.pnm -1 | wc -l) * 2" | bc)
scanimage --batch --batch-increment -2 --batch-start $endpage
for file in *.pnm; do convert $file $file.jpg; done
rm *.pnm
convert $(ls *.jpg -1v | paste) -compress jpeg -page A4 output.pdf
@baojie
baojie / hashtest.py
Last active January 6, 2023 16:20
python hash function test
import timeit
import random
import string
data = ''.join([random.choice(string.ascii_letters) for x in range(1024*1024)])
print "md5",
print timeit.timeit('hashlib.md5().update(data)', number=10000, setup='import hashlib; data="%s"' % data)
print "sha1",
print timeit.timeit('hashlib.sha1().update(data)', number=10000, setup='import hashlib; data="%s"' % data)
#!/bin/sh
echo "data:image/png;base64,`base64 $1`"

AngularJS-Learning

A bunch of links to blog posts, articles, videos, etc for learning AngularJS. This list is in its early stages. Feel free to submit a pull request if you have some links/resources to add. Also, I try to verify that the articles below have some real content (i.e. aren't 2 paragraph blog posts with little information) to ensure I'm not listing "fluff" pieces. If you have an idea for a better way to organize these links, please let me know. As I find similar posts in the "General Topics" section, I will break them out into their own categories.

Books

// Examples for using socat (and filan)
//"$" means normal user, "#" requires privileges, "//" starts a comment
///////////////////////////////////////////////////////////////////////////////
// similar to netcat
// connect to 10.1.1.1 on port 80 and relay to and from stdio
$ socat - TCP:10.1.1.1:80 # similar to "netcat 10.1.1.1 80"
@baojie
baojie / gist:4460468
Created January 5, 2013 08:09
Arduino Hello World by Morse code
// From http://arduino.cc/forum/index.php/topic,43903.0.html#10
byte text[] = "Hello World"; // Transmittet text
// Morse code generator for the Arduino
// Transmitted text is placed in the first line
// Tempo sets the speed of a dot etc.
// Morde code was tanken from http://en.wikipedia.org/wiki/Morse_code
// Text is looping and prior to transmitting the active pin blinks rapidly
// Version 1.0, made by Fletcher Chr
@baojie
baojie / flask-vs-tornado
Created December 3, 2013 23:42
flask vs tornado benchmark on basic routing and template rendering
Flask, Python 2.7, Single core 271.97 [#/sec] (mean)
Flask, Pypy, Single core 547.11
Flask+Gunicorn, Python, 8Core 1363.06
Flask+Gunicorn, Pypy, 8Core 2701.90
Flask+Gunicorn+Tornado, Python, 8Core 1403.88
Flask+Gunicorn+Tornado, Pypy, 8Core 2582.12
Tornado, Python, Single core 839.65
Tornado, Async, Python, Single core 801.19
Tornado, Pypy, Single core 1841.41
Tornado, Async, Pypy, Single core 1734.37