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
def queryset_generator(queryset, chunksize=1000): | |
""" | |
Iterate over a Django Queryset ordered by the primary key | |
This method loads a maximum of chunksize (default: 1000) rows in its | |
memory at the same time while django normally would load all rows in its | |
memory. Using the iterator() method only causes it to not preload all the | |
classes. | |
Note that the implementation of the generator does not support ordered query sets. |
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
def time(f): | |
"""Wrapper function to time python callables.""" | |
import datetime | |
d = datetime.datetime.today() | |
print 'Timing callable %s' % f.__name__ | |
print '------------------' | |
f() | |
print '------------------' | |
print datetime.datetime.today() - d |
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 last_occurrence(object): | |
"""Last occurrence functor.""" | |
def __init__(self, pattern, alphabet): | |
"""Generate a dictionary with the last occurrence of each alphabet | |
letter inside the pattern. | |
Note: This function uses str.rfind, which already is a pattern | |
matching algorithm. There are more 'basic' ways to generate this | |
dictionary.""" |
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
$ git status | |
# On branch master | |
nothing to commit (working directory clean) | |
$ find_replace.sh "TODO" "s/TODO/REMEMBER/g" apps/ | |
Command: egrep -lrZ --binary-files=without-match "TODO" "/home/user/apps/" | xargs -0 -l sed -i -e "s/TODO/REMEMBER/g" | |
Really execute (y/n)? y | |
[danilo@dev5 db]$ git status | |
# On branch master |
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
# WARNING: Ugly hack. | |
import re | |
import requests | |
from BeautifulSoup import BeautifulSoup | |
import imdb | |
print 'Getting data from Wikipedia...' |
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
Full repository -> https://github.com/gwrtheyrn/twtrack |
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 -*- | |
""" | |
ReST directive for embedding Youtube and Vimeo videos. | |
There are two directives added: ``youtube`` and ``vimeo``. The only | |
argument is the video id of the video to include. | |
Both directives have three optional arguments: ``height``, ``width`` | |
and ``align``. Default height is 281 and default width is 500. |
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
def get_free_port(): | |
s = socket.socket() | |
s.bind(('', 0)) | |
port = s.getsockname()[1] | |
s.close() | |
return port |
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 subprocess import Popen, PIPE, STDOUT | |
import time | |
def process_line(line): | |
print 'New line: "%s"' % line.strip('\n') | |
proc = Popen(['bash', 'print_lines.sh'], stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) | |
while True: | |
line = proc.stdout.readline() | |
if line != '': |
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
$(document).ready(function () { | |
$('.switch').each(function () { | |
var radio_yes = $(this).children('input[type=radio][value=1]')[0]; | |
var toggle = $(this).children('label.switch-toggle'); | |
if (radio_yes) { | |
// checkbox.addClass('hidden'); | |
toggle.removeClass('hidden'); |
OlderNewer