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 | |
__version__ = '0.2' | |
__releasedate__ = '2009-12-23' | |
__author__ = 'Ryan McGreal <[email protected]>' | |
__homepage__ = 'http://quandyfactory.com/insult' | |
__repository__ = 'http://gist.github.com/258915' | |
__copyright__ = 'Copyright (C) 2009 by Ryan McGreal. Licenced under GPL version 2. http://www.gnu.org/licenses/gpl-2.0.html' | |
def generate_insult(): |
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_longurl(path): | |
""" | |
Code to run Wayne MacPhail's URL Lengthener. | |
TODO: re-populate form fields on failed post. | |
""" | |
output = [] | |
addline = output.append | |
formfields = web.input(longurl='', url='') | |
longurl = tools.strip_html(formfields.longurl.strip().lower().replace('http://', '').replace('/','_')) | |
url = tools.strip_html(formfields.url.strip().lower()) |
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 iterchars(): | |
""" | |
Creates an iterator of ascii characters from 32 (space) to 126 (tilde) | |
""" | |
for x in range(32, 127): | |
yield x |
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
# if there are any others who don't care much for try ... catch AttributeError | |
def hasmethods(obj, *meth_names): | |
return all( | |
hasattr( | |
# if it calls like a method it's a method | |
getattr(obj, m, None), | |
'__call__' | |
) for m in meth_names | |
) |
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 anagram(string1, string2, ignore_whitespace=False): | |
"""Determines whether two strings are anagrams.""" | |
if ignore_whitespace==True: | |
import re | |
string1, string2 = re.sub('\s', '', string1), re.sub('\s', '', string2) | |
if len(string1) != len(string2): return False | |
list1, list2 = [c for c in string1].sort(), [c for c in string2].sort() | |
if list1 != list2: return False | |
return True |
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 fizzbuzz(start=1, end=100, fizzval=3, buzzval=5): | |
"""Implements Reginald Braithwaite's FizzBuzz text.""" | |
for i in range(start, end+1): | |
fizz = 'Fizz' if i % fizzval == 0 else '' | |
buzz = 'Buzz' if i % buzzval == 0 else '' | |
print i if fizz+buzz == '' else fizz+buzz |
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
<textarea style="width: 90%; height: 90%; display: block; margin: 2% auto auto auto;"></textarea> | |
<!-- open this in a modern browser and you have built-in spell checking with no other clutter --> |
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 make_table(data, delim='\t', table_id='make_table', classname=''): | |
""" | |
Converts delimited data into an HTML table. | |
- `data` is a string, with rows delimited by newlines. | |
- Default cell delimiter for each row is a tab. | |
""" | |
output = [] | |
output.append('<table id="%s" class="%s">' % (table_id, classname)) | |
for row in data.strip().split('\n'): | |
cells = row.strip().split(delim) |
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 | |
""" | |
Simple command-line based Rock Paper Scissors game in Python. | |
""" | |
import random | |
vals = 'R P S'.split(' ') | |
msg_win = "You win this round." | |
msg_lose = "You lose this round." | |
msg_tie = "Tie! You both picked " |
OlderNewer