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
<?php | |
class TangentLabs_Sniffs_BestPractice_SensibleTernarysSniff implements PHP_CodeSniffer_Sniff | |
{ | |
/** | |
* @return array | |
*/ | |
public function register() | |
{ | |
return array(T_INLINE_THEN); | |
} |
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 TwillTestCase(TestCase): | |
""" | |
Simple wrapper around Twill to make writing TestCases easier. | |
Commands availabel through self.command are: | |
- go -> visit a URL | |
- back -> back to previous URL | |
- reload -> reload URL | |
- follow -> follow a given link | |
- code -> assert the HTTP response code |
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 logging import FileHandler as BaseFileHandler | |
import os | |
class EnvFileHandler(BaseFileHandler): | |
""" | |
Custom filehandler that uses the LOG_ROOT setting to determine the folder | |
to store log files in. | |
We have to do some tricky stuff to avoid circular imports. To this end, |
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 curry(f, *args, **kwargs): | |
def curried(*more_args, **more_kwargs): | |
return f(*(args+more_args), **dict(kwargs, **more_kwargs)) | |
return curried | |
class Person(object): | |
def __init__(self, name, gender): | |
self.name = name | |
self.gender = gender |
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
#!/bin/bash | |
# Extract version number from setup.py | |
RELEASE_NUM=`grep version setup.py | cut -d\' -f2` | |
# Push to PyPi | |
python setup.py sdist upload | |
# Tag in Git and push to remote | |
git tag $RELEASE_NUM -m "Tagging release $RELEASE_NUM" |
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
#!/usr/bin/env python | |
import sys | |
from optparse import OptionParser | |
import unittest | |
from collections import defaultdict | |
# Constants for each hand | |
ROYAL_STRAIGHT_FLUSH = 10 | |
STRAIGHT_FLUSH = 9 | |
FOUR_OF_A_KIND = 8 |
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
#!/usr/bin/env python | |
import os | |
import re | |
import subprocess | |
import sys | |
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)') | |
CHECKS = [ |
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
# Hacky script for downloading videos from PyVideo and converting them to m4v | |
# format so they can be synced onto your apple device. Useful if you | |
# want to see everything that happened at PyCon while commuting. | |
# | |
# Requirements: | |
# * pip install requests BeautifulSoup | |
# * youtube-dl (from https://github.com/rg3/youtube-dl/) - add this to the | |
# directory where this script runs and ensure its execute bit is set. | |
# This was the only YouTube downloader I found that worked. It doesn't | |
# really have a good Python API so I call it through os.system. |
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 requests | |
from someurllib import URL | |
# 1. Build request URL | |
url = URL(host='maps.google.com') | |
url.path('/geocoding/xml/') | |
.param('q', 'Some address string') | |
.param('sensor', 'False') | |
.fragment('something') |
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 random | |
import time | |
def pick_winners(candidates, num_winners): | |
for i in range(num_winners): | |
time.sleep(1) | |
winner = random.choice(candidates) | |
print "Winner %d: %s" % (i+1, winner) | |
candidates.remove(winner) | |
print "\nSorry %s\n" % ", ".join(candidates) |
OlderNewer