Skip to content

Instantly share code, notes, and snippets.

@tomviner
tomviner / fabfile.py
Created September 17, 2011 22:51
VirtualEnvWrappers with Fabric
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
@tomviner
tomviner / q1.py
Created September 16, 2011 08:47
Anagram of Palindrome
# -*- 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”.
@tomviner
tomviner / spottylotty.py
Created September 9, 2011 15:43
Spotify Ticket Lottery
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!____