This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Pool | |
def is_prime(number): | |
if number == 2 or number == 3: | |
return number, True | |
if number % 2 == 0 or number < 2: | |
return number, False | |
for i in range(3, int(number**0.5) + 1, 2): | |
if number % i == 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Timer(object): | |
def __init__(self, verbose=False): | |
self.verbose = verbose | |
def __enter__(self): | |
self.start = time.time() | |
return self | |
def __exit__(self, *args): | |
self.end = time.time() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render_to_response | |
from django.template import RequestContext | |
def render_to(tmpl): | |
def renderer(func): | |
def wrapper(request, *args, **kw): | |
output = func(request, *args, **kw) | |
if not isinstance(output, dict): | |
return output | |
return render_to_response(tmpl, output, context_instance=RequestContext(request)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function curry(f) { | |
return function(x) { | |
var g = f.bind(this, x); | |
if(g.length == 0) return g(); | |
if(arguments.length > 1) return curry(g).apply(this, [].slice.call(arguments, 1)); | |
return curry(g); | |
}; | |
} | |
var sum = curry(function(x, y) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_array = [i for i in range(10)] | |
sum(map(lambda k:k if k % 2 else 0, my_array)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -p "This script writes all flac files in this directory to CD. Insert blank CD and press enter" | |
flac -d ./*.flac; | |
cdrecord -v -pad speed=1 dev=0,0,0 -dao -swab ./*.wav; | |
rm ./*.wav |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding:utf-8 -*- | |
#!/usr/bin/env python | |
import os | |
import sys | |
import urllib2 | |
from BeautifulSoup import BeautifulSoup as bs | |
def download(u): | |
soup = bs(urllib2.urlopen(u)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# On computer A with IP 192.168.1.11 | |
$ tar -cf - /data | nc -l -p 34343 | |
# On computer B | |
$ nc 192.168.1.11 34343 | tar -xf - |