Skip to content

Instantly share code, notes, and snippets.

@onemach
onemach / d
Created April 5, 2012 14:30
JavaScript-like object in python
class D(dict):
def __init__(self):
dict.__init__(self)
def __getitem__(self, key):
val = D()
try:
val = dict.__getitem__(self, key)
except:
dict.__setitem__(self, key, val)
@yefim
yefim / create-repo.sh
Created May 4, 2012 06:10
Create a new GitHub repo
#!/bin/bash
read -s -p "GitHub password: " pass
# I assume the GitHub API and authentication works because I don't want to parse JSON
curl -u "yefim323:$pass" https://api.github.com/user/repos -d "{\"name\":\"$1\"}" > /dev/null
git remote add origin [email protected]:yefim323/$1.git
@pachacamac
pachacamac / clusterize.rb
Created May 22, 2012 19:11
Cluster algorithm for n-dimensional data and a given number of clusters
# A
# B
#
# D
#
# C
# E
#
# F
#
@andreyvit
andreyvit / tmux.md
Created June 13, 2012 03:41
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@marktheunissen
marktheunissen / pedantically_commented_playbook.yml
Last active June 15, 2025 15:49 — forked from phred/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
This playbook has been removed as it is now very outdated.
@vgel
vgel / fileserver.py
Created July 9, 2012 14:16
A very basic HTTP file server in 13 lines of python. Assumes all requests are GETs, and it vulnerable to directory traversal (Run it in ~ and localhost:8080/../../ will ls root), so don't use it online. Will correctly list files in directories.
import sys, os, socket
s = socket.socket()
s.bind((sys.argv[1], int(sys.argv[2])))
s.listen(5)
try:
while True:
conn, addr = s.accept()
path = os.path.join(os.getcwd(), "./"+conn.recv(4096).split("\n")[0].split(" ")[1])
conn.send((open(path).read() if os.path.isfile(path) else reduce(lambda x,s:x+"\n"+s+("/" if os.path.isdir(s) else ""),sorted(os.listdir(path)),"Directory "+path+" ls")) if os.path.exists(path) else '404: '+path)
conn.close()
@vgel
vgel / golfed-msgboard.py
Created July 23, 2012 12:47
A simple message-board-type site in golfed python. Expanded version below if you can't read golfed code or want comments.
import BaseHTTPServer as b,sys,os,json,urlparse
p=(json.loads(open(sys.argv[1]).read()) if os.path.exists(sys.argv[1]) else {})
n="<br/>"
h="""<form action=%s method="post">Post: <textarea name="a"></textarea><input type="submit" value="Post!"/></form>"""
y=lambda s:urlparse.parse_qs(s)['a'][0]
class F(b.BaseHTTPRequestHandler):
def do_GET(s):
s.send_response(200)
s.send_header("Content-type","text/html")
s.end_headers()
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@bergundy
bergundy / echo.py
Created August 27, 2012 21:39
tornado_subprocess
import sys
while True:
l = raw_input()
sys.stdout.write(l+"\n")
sys.stdout.flush()
@preshing
preshing / sort1mb.cpp
Created October 25, 2012 11:28
Sort one million 8-digit numbers in 1MB RAM
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef unsigned int u32;
typedef unsigned long long u64;
//-------------------------------------------------------------------------
// WorkArea
//-------------------------------------------------------------------------