Skip to content

Instantly share code, notes, and snippets.

@gennad
gennad / quicksort.py
Created May 29, 2011 16:22
Quikcosrt Python
#Three-way QuickSort in Python
def quicksort(a):
if len(a) == 0:
return []
p = a[(len(a)-1)//2]
less = quicksort([x for x in a if x < p])
greater = quicksort([x for x in a if x > p])
equal = [x for x in a if x == p]
return less + equal + greater
@gennad
gennad / tray.py
Created June 7, 2011 05:19
Tray example in gnome
#!/usr/bin/python
# Copyright (C) 2009 Mauricio Teixeira.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@gennad
gennad / timestamp.py
Created June 10, 2011 07:15
Python string to timestamp
import datetime
import time
def from_string_to_timestamp(st):
if st.find('-') != -1:
splitted = st.split('-')
else:
splitted = st.split('.')
try:
@gennad
gennad / json.py
Created June 10, 2011 08:28
Send json POST request
import urllib2
import json
# Whatever structure you need to send goes here:
jdata = json.dumps({"username":"...", "password":"..."})
urllib2.urlopen("http://www.example.com/", jdata)
@gennad
gennad / randhash.py
Created June 10, 2011 09:07
Generate random hashcode in Python
import random
random.seed()
hash = random.getrandbits(128)
print "hash value: %016x" % hash
@gennad
gennad / sieve.py
Created July 4, 2011 08:41
Eratosthene's sieve
n = input("n = ")
a = range(n+1)
a[1] = 0
lst = []
i = 2
while i <= n:
if a[i] != 0:
lst.append(a[i])
for j in xrange(i, n+1, i):
@gennad
gennad / multithreading.cc
Created August 31, 2011 17:13
Multithreading in Unix
// Compile with g++ -o multithreading.o multithreading.cc -lpthread
#include <pthread.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
@gennad
gennad / templates.cc
Created August 31, 2011 17:57
templates
// function template
#include <iostream>
using namespace std;
template <class T>
T GetMax (T a, T b) {
T result;
result = (a>b)? a : b;
return (result);
}
@gennad
gennad / .zshrc
Created September 23, 2011 08:48
My .zshrc
# Set up the prompt
autoload -Uz promptinit
promptinit
prompt adam1
setopt histignorealldups sharehistory
# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e
@gennad
gennad / gist:2290559
Created April 3, 2012 09:00
My .emacs
(setq org-directory "~/org/")
(load-file "/home/gennad/.emacs.d/emacs-for-python/epy-init.el")
;; To require
;;(add-to-list 'load-path "~/.emacs.d/http")
;;(require 'http-post-curl)
;;(require 'http-twiddle)
;;(load-file "/home/gennad/.emacs.d/http-post-curl.el")