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 __future__ import division | |
import sys | |
import math | |
import random | |
# http://www.spotify.com/us/jobs/tech/ticket-lottery/ | |
def bc(n, k, f=math.factorial): | |
"""Binomial coefficient in terms of Factorials | |
(n) = ____n!____ |
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 -*- | |
""" | |
1) A string is a palindrome if it reads the same from left-to-right as it does right-to-left. | |
e.g “nolemonnomelon”, “racecar” & “neveroddoreven” are all palindromes. | |
A string is an anagram of another string if it consists of exactly the same characters but in another order. | |
e.g The string “carrace” is an anagram of “racecar”. | |
Write a function `def is_anagram_of_palindrome(str):` | |
such that it returns True if the string str is an anagram of a palindrome, and otherwise returns False. | |
You may assume that str contains only lowercase characters a-z and is not empty. | |
e.g Given str = “carrace” the function should return True as it is an anagram of the palindrome “racecar”. |
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 once(s): | |
"command_prefixes is a list of prefixes" | |
if s not in env.command_prefixes: | |
return s | |
return 'true' | |
@contextlib.contextmanager | |
def mycd(dir): | |
with prefix(once('cd %s' % dir)): | |
yield |
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
BEGIN:VCALENDAR | |
X-WR-CALNAME;VALUE=TEXT:guardiancartoons | |
VERSION:2.0 | |
CALSCALE:GREGORIAN | |
BEGIN:VEVENT | |
DTSTART;VALUE=DATE:20110917T00:00:00Z | |
DTEND;VALUE=DATE:20110918 | |
SUMMARY:Martin Rowson on the arrest of UBS 'rogue trader' - cartoon | |
X-GOOGLE-CALENDAR-CONTENT-TITLE:Martin Rowson on the arrest of UBS 'rogue trader' - cartoon | |
X-GOOGLE-CALENDAR-CONTENT-ICON:http://www.guardian.co.uk/favicon.ico |
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
# eg qs = Product.objects.exclude(is_prebuy=True) | |
print re.sub(r'\b([A-Z]+)\b', r'\n\1\n\t', str(qs.query)) | |
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
{ | |
"auto_complete_commit_on_tab": true, | |
"detect_slow_plugins setting": false, | |
"dictionary": "Packages/Language - English/en_GB.dic", | |
"find_selected_text": true, | |
"fold_buttons": false, | |
"folder_exclude_patterns": | |
[ | |
".svn", | |
".git", |
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
import string | |
def pretty_size(size): | |
"size in bytes" | |
size = int(size) | |
units = ' KMGTPE'+string.lowercase[::-1] | |
bytes = 'B' | |
i = 0 | |
while size>1024: |
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
curl -O http://python-distribute.org/distribute_setup.py | |
python distribute_setup.py | |
curl -O http://pypi.python.org/packages/source/p/pip/pip-0.7.2.tar.gz | |
tar xzf pip-0.7.2.tar.gz | |
cd pip-0.7.2 | |
python setup.py install | |
easy_install pip | |
pip install requests |
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
import os | |
import urllib2 | |
import contextlib | |
import StringIO | |
from django.core.files.storage import get_storage_class, FileSystemStorage | |
from django.core.files import File | |
from django.conf import settings | |
from galleries.models import GalleryImage |
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
$.getJSON('media/js/markers.json', function(data){ | |
$.each(data.markers, function(i, marker){ | |
if (...) { | |
map.addMarker({ | |
id: i, | |
tags: marker.tag, | |
lat: marker.latitude, | |
lng: marker.longitude, | |
infoWindow: { | |
content: '<h2>' + marker.name + '</h2><p>' + marker.address + '</p>' |
OlderNewer