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 contextlib import contextmanager | |
# cache = ... | |
class DistributedLinkedList(object): | |
 def __init__(self, cache_key_name, cache_timeout=86400): | |
 self.cache_key_name = cache_key_name | |
self.cache_timeout = cache_timeout | |
 self.head_key_ref = f'distributed-list-{cache_key_name}-head' | |
 self.tail_key_ref = f'distributed-list-{cache_key_name}-tail' |
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 bs4 import BeautifulSoup | |
def max_tree_height(html): | |
''' | |
Calculate the number of HTML tag levels, iteratively | |
>>> max_tree_height('') | |
0 | |
>>> max_tree_height('<div></div>') |
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
## Nested lists using tabs: | |
1. FOO | |
2. FOO | |
[tab]a. FOO | |
[tab]b. FOO | |
[tab][tab]i. FOO | |
[tab][tab]ii. FOO | |
3. FOO | |
4. FOO |
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
/* | |
Fermat Near-Miss Finder | |
Written by David X. Cohen | |
February 3, 1998, 3:24 AM. | |
This program generated the equation: | |
3987^12 + 4365^12 = 4472^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
from urllib import unquote, quote | |
a = u'\u2022' | |
print a | |
b = a.encode('utf-8') | |
print b | |
c = quote(b) | |
print c |
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 urllib2 import quote, unquote | |
import sqlite3 | |
def fix_the_things(name): | |
name = name[6:] | |
name = quote(unquote(name), '-_.!()') | |
name = name.replace('.rar%2F', '.rar/') | |
bits = name.split('%') | |
res = [bits[0]] |
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 decorator import decorator | |
from line_profiler import LineProfiler | |
@decorator | |
def profile_each_line(func, *args, **kwargs): | |
profiler = LineProfiler() | |
profiled_func = profiler(func) | |
try: | |
profiled_func(*args, **kwargs) | |
finally: |
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 | |
""" | |
ignore_moves.py v0.2 | |
Filter relocated lines from a unified diff format stream. | |
Offered under the terms of the MIT License at github.com | |
Taken from http://stackoverflow.com/questions/1380333/ | |
""" | |
import sys | |
from optparse import OptionParser |
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/sh | |
main() { | |
configure_ssh_known_hosts | |
configure_mysql_ram_disk | |
configure_idle_tracking | |
} | |
configure_ssh_known_hosts() { | |
echo configuring ssh known hosts |
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
%form.form-horizontal{method:'post'} | |
%fieldset | |
%legend Select Users to Assign | |
.control-group | |
%label.control-label | |
These users or groups | |
.controls | |
.tokenizer | |
.tokenarea | |
%span.label.label-info.removeable.token{title:'Yippie'} |
NewerOlder