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 Data.List.Zipper as Z | |
main = do | |
let string = "yabbadabbadoo" | |
print $ maximum $ palindromeSizes string | |
-- Find the size of the largest palindrome centered at each location in | |
-- a string. There will be 2*n-1 locations, because we count even and odd | |
-- centers. Go along the zipper, checking the sizes of palindromes to the left | |
-- and right as we go. |
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
""" | |
Python implementation of the Luhn algorithm. | |
Refer to: http://en.wikipedia.org/wiki/Luhn_algorithm | |
>>> is_luhn_valid(79927398713) | |
True | |
>>> is_luhn_valid(79927398714) | |
False | |
>>> is_luhn_valid(4532990475689429) |
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 digits_of(n, base=10): | |
""" | |
Split the number into its digits. | |
>>> digits_of(0) | |
[0] | |
>>> digits_of(123) | |
[1, 2, 3] | |
>>> digits_of(0xabc, base=16) | |
[10, 11, 12] |
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 re | |
from hashlib import md5 | |
def gfm(text): | |
# Extract pre blocks. | |
extractions = {} | |
def pre_extraction_callback(matchobj): | |
digest = md5(matchobj.group(0)).hexdigest() | |
extractions[digest] = matchobj.group(0) | |
return "{gfm-extraction-%s}" % digest |
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
""" | |
Flatten a nested list structure. | |
* Works for nested structures of lists, tuples, generators, or any other iterable. | |
* Special-cases string types and treats them as non-iterable. | |
* Is not limited to the system recursion limit. | |
* Yields items from the structure instead of constructing a new list, and can | |
work on non-terminating generators. | |
This is basically a non-recursive version of the following: |
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 | |
SSHAGENT=/usr/bin/ssh-agent | |
SSHAGENTARGS="-s" | |
PARENT_JOB=pstat_master_unittest | |
KEY_PATH=$HOME/policystat/fabric/pstat_dev.key | |
PROJECT_ROOT=/var/www/pstattest.com/ | |
if [ ! -z "$WORKSPACE" ]; then | |
WORKSPACE=/vol/fs/var/lib/hudson/home/jobs/pstat_master_deploy/workspace |
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 print_function | |
""" | |
Utilities for 256 color support in terminals. | |
Adapted from: | |
http://stackoverflow.com/questions/1403353/256-color-terminal-library-for-ruby | |
The color palette is indexed as follows: | |
0-15: System colors |
NewerOlder