This file contains hidden or 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 | |
| from __future__ import print_function | |
| import functools | |
| import sys | |
| try: from collections import Counter | |
| except ImportError: | |
| pass # ignore | |
| from collections import defaultdict |
This file contains hidden or 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
| /twistd.pid | |
| /_trial_temp/ |
This file contains hidden or 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
| """''.format_map() in Python 2.x""" | |
| try: | |
| ''.format_map({}) | |
| except AttributeError: # Python < 3.2 | |
| import string | |
| def format_map(format_string, mapping, _format=string.Formatter().vformat): | |
| return _format(format_string, None, mapping) | |
| del string |
This file contains hidden or 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 regex # pip install regex | |
| keywords = ['post', 'another'] | |
| p = regex.compile(ur'(?fi)\L<keywords>', keywords=keywords) | |
| p.findall(u'POST, Post, post, poſt, post, and poſt') | |
| # -> [u'POST', u'Post', u'post', u'po\u017ft', u'po\ufb06', u'po\ufb05'] |
This file contains hidden or 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 | |
| """ | |
| http://stackoverflow.com/questions/9156823/recursive-fibonacci-using-fork-in-c | |
| """ | |
| import os | |
| import sys | |
| def exitcode(pid): | |
| retpid, status = os.waitpid(pid, 0) | |
| assert retpid == pid and os.WIFEXITED(status) |
This file contains hidden or 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
| ## | |
| ## ca-bundle.crt -- Bundle of CA Root Certificates | |
| ## | |
| ## Certificate data from Mozilla as of: Wed Jan 18 00:04:16 2012 | |
| ## | |
| ## This is a bundle of X.509 certificates of public Certificate Authorities | |
| ## (CA). These were automatically extracted from Mozilla's root certificates | |
| ## file (certdata.txt). This file can be found in the mozilla source tree: | |
| ## http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1 | |
| ## |
This file contains hidden or 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 sys | |
| import time | |
| version = sys.hexversion | |
| if 0x03000000 <= version < 0x03010000 : | |
| import tkinter | |
| import ttk | |
| elif version >= 0x03010000: | |
| import tkinter | |
| import tkinter.ttk as ttk |
This file contains hidden or 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
| #file: next_permutation.pyx | |
| from libcpp cimport bool | |
| cimport numpy as np | |
| ctypedef np.int_t dtype_t | |
| cdef extern from "<algorithm>" namespace "std": | |
| bool cpp_next_permutation "std::next_permutation" (dtype_t* first, dtype_t* last) |
This file contains hidden or 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
| #cython: boundscheck=False, wraparound=False | |
| import numpy as np | |
| cimport numpy as np | |
| from cython.parallel cimport prange | |
| def dot(np.ndarray[np.float32_t, ndim=2] a not None, | |
| np.ndarray[np.float32_t, ndim=2] b not None, | |
| np.ndarray[np.float32_t, ndim=2] out=None): | |
| """Naive O(N**3) 2D np.dot() implementation.""" |
This file contains hidden or 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 string | |
| import datrie # pip install datrie | |
| def longest_match_datrie(search, hosts): | |
| trie = datrie.new(alphabet=string.printable) | |
| for url in hosts: | |
| trie[url.decode('ascii')] = 1 | |
| matches = trie.keys(search.decode('ascii')) | |
| return max(matches, key=len) if matches else '' |