Skip to content

Instantly share code, notes, and snippets.

View snahor's full-sized avatar

Hans Roman snahor

  • Wakanda
View GitHub Profile
from threading import Thread
import cProfile
import pstats
def enable_thread_profiling():
'''Monkey-patch Thread.run to enable global profiling.
Each thread creates a local profiler; statistics are pooled
to the global stats object on run completion.'''
@snahor
snahor / gist:5550458
Created May 9, 2013 20:42
Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida, nisl consectetur dignissim euismod, ante tortor rutrum libero, ac euismod mauris elit non augue. Morbi vel placerat mi. In enim metus, commodo nec adipiscing eget, vestibulum ut turpis. In lacinia justo sit amet erat tristique in pharetra nisl condimentum. Vivamus at diam ac nibh placerat egestas id sit amet velit. Mauris sed enim eu metus congue hendrerit. Duis sem nibh, rutrum venenatis pretium eget, auctor sit amet odio. Vivamus nisl ligula, interdum vitae scelerisque et, feugiat quis ipsum. Morbi vel dolor ut nunc pharetra placerat. Pellentesque id quam lacus, ut placerat purus.
@snahor
snahor / timeit.py
Last active December 14, 2015 20:38
def timeit(fn):
def time_fn(*arg, **kw):
import time
now = time.time()
fn(*arg, **kw)
total = time.time() - now
print "total time for %s: %d" % (fn.__name__, total)
return time_fn
@snahor
snahor / scrollbars-dimensions.js
Last active December 10, 2015 14:08
Get scrollbars dimensions. Taken from http://stackoverflow.com/a/8221501/94746
function getScrollBarDimensions() {
var elm = document.documentElement.offsetHeight ? document.documentElement : document.body,
curX = elm.clientWidth,
curY = elm.clientHeight,
hasScrollX = elm.scrollWidth > curX,
hasScrollY = elm.scrollHeight > curY,
prev = elm.style.overflow,
r = { vertical: 0, horizontal: 0 };
if ( !hasScrollY && !hasScrollX )
#!/bin/bash
if [ -n "$1" ]
then
ps xu | grep $1 | awk '{print $2}' | xargs kill -9
else
echo "Usage: die <process-name>"
fi

“Conectándose para una mejor salud materno-infantil en el Perú”

@snahor
snahor / disqus_requirements.txt
Created May 12, 2012 19:54 — forked from kracekumar/disqus_requirements.txt
disqus requirements.txt
# dev
django-debug-toolbar==0.9.4
django-data-tools==0.1
django-devserver==0.3
nashvegas==0.8-disqus-5
Sphinx>=1.0.7
piplint==0.1.1
# global
amqplib==1.0.0
<?php
class Persona
{
public $nombres = '';
public $ape_paterno = '';
public $ape_materno = '';
public $edad = null;
public function ponerNombresApellidos($nombres, $ape_pat, $ape_mat)
{
import urllib
URL = 'http://api.tropo.com/1.0/sessions'
TOKEN = ''
def send_sms(to, shout):
params = urllib.urlencode({
'action': 'create',
'token': TOKEN,
'shout': shout,
@snahor
snahor / admin.py
Created January 4, 2012 14:20
Django admin export all the records of the current queryset to XLS
import xlwt
from django.http import HttpResponse
def export_xls(modeladmin, request, queryset):
meta = modeladmin.model._meta
filename = '%s.xls' % meta.verbose_name_plural.lower()
def get_verbose_name(fieldname):
name = filter(lambda x: x.name == fieldname, meta.fields)