Skip to content

Instantly share code, notes, and snippets.

View eskil's full-sized avatar

Eskil Heyn Olsen eskil

View GitHub Profile
@eskil
eskil / prettyretarded
Created May 18, 2012 20:07
Emacs config to use the right tabs for yelp codes...
(defun my-yelp-python-mode-hook ()
(setq tab-width 4)
(setq py-indent-offset 4)
(setq indent-tabs-mode (or (string-match "/pg/yelp-main/" (buffer-file-name))
(string-match "/pg/yelp_conn/" (buffer-file-name))
(string-match "/pg/yelp_lib/" (buffer-file-name))
(and (string-match "/pg/services/" (buffer-file-name))
(not (or (string-match "/zygote/" (buffer-file-name))
(string-match "/google/" (buffer-file-name))
)
@eskil
eskil / m2crypto-certificates.py
Created April 8, 2012 17:07
Example of generating CA certs and CA signed certs using python m2crypto.
"""
Tools for creating a CA cert and signed server certs.
Divined from http://svn.osafoundation.org/m2crypto/trunk/tests/test_x509.py
The mk_temporary_xxx calls return a NamedTemporaryFile with certs.
Usage ;
# Create a temporary CA cert and it's private key
cacert, cakey = mk_temporary_cacert()
@eskil
eskil / pycurl_curlmulti_ssl.py
Created April 4, 2012 00:48
Example code doing SSL using pycurl and CurlMulti
# Example code doing SSL using pycurl and CurlMulti
import pycurl
import cStringIO
response_buffer = cStringIO.StringIO()
multi = pycurl.CurlMulti()
curl = pycurl.Curl()
curl.setopt(pycurl.URL, 'https://www.yammer.com')
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
"CREATE TRIGGER Dive_Update AFTER "
"UPDATE OF dive_datetime ON Dive BEGIN "
"UPDATE Dive "
"SET dive_number= "
" (SELECT CASE "
" WHEN dive_id = NEW.dive_id THEN "
" /* The updated dive, set the number to the number of older dives */ "
" 1 + (SELECT COUNT(*) FROM Dive WHERE dive_datetime < NEW.dive_datetime) "
" WHEN NEW.dive_datetime > OLD.dive_datetime "
" /* All other dive, move by +/- 1 depending on whether we've moved the datetime "
@eskil
eskil / gdivelog new dive trigger
Created March 18, 2012 20:32
The ORM is inside me.
DROP TRIGGER Dive_Insert;
/*
if no dives predate this then
if lowest number is > 1:
lowest number - 1
else
1
else
pick most recent +1