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 https://raw.githubusercontent.com/Anorov/PySocks/cd6844dfc4dbe4550e30d9271d8d29cca23e3702/sockshandler.py | |
| """ | |
| SocksiPy + urllib2 handler | |
| version: 0.2 | |
| author: e<e@tr0ll.in> | |
| This module provides a Handler which you can use with urllib2 to allow it to tunnel your connection through a socks.sockssocket socket, with out monkey patching the original socket... | |
| """ |
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 | |
| """Measure relative performance of "count overlapping substrings" functions. | |
| http://hashcode.ru/questions/404985/python-%D1%85%D0%B8%D1%82%D1%80%D0%BE%D0%B5-%D0%B2%D1%85%D0%BE%D0%B6%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5-%D0%BF%D0%BE%D0%B4%D1%81%D1%82%D1%80%D0%BE%D0%BA%D0%B8-%D0%B2-%D1%81%D1%82%D1%80%D0%BE%D0%BA%D1%83 | |
| """ | |
| import re | |
| def count_overlapping_substrings(haystack, needle): | |
| count = 0 | |
| i = -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
| #!/usr/bin/env python | |
| """Run `snort -A console` command using a pipe. | |
| Warning! Alerts are delayed until snort's stdout buffer is flushed. | |
| """ | |
| from __future__ import print_function | |
| from subprocess import Popen, PIPE, STDOUT | |
| snort_process = Popen(['snort', '-A', 'console', '-c', 'snort.conf'], | |
| stdout=PIPE, stderr=STDOUT, bufsize=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
| #!/usr/bin/env python | |
| """Test POSIX definition of "seconds since Epoch". | |
| Assert that posix_time(), calendar.timegm(), and timegm() (mktime() in | |
| UTC) behave the same. Check `datetime.timestamp()` and the explicit | |
| formula (d - epoch) too. | |
| """ | |
| import calendar | |
| import itertools |
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
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
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://ru.stackoverflow.com/q/427088/23044 | |
| """ | |
| import grako # $ pip install grako | |
| grammar_ebnf = """ | |
| record = type name teacher auditory $ ; | |
| type = "pr." | "lab." | "c." ; | |
| name = { word }+ ; |
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 | |
| # -*- coding: utf-8 -*- | |
| r"""Support for IEEE 754 half-precision binary floating-point format: binary16. | |
| >>> [binary16(f) for f in [0.006534, -.1232]] == [b'\xb0\x1e', b'\xe2\xaf'] | |
| True | |
| """ | |
| from __future__ import division | |
| import struct | |
| from math import copysign, frexp, isinf, isnan, trunc |
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 | |
| """Parallel version of | |
| http://stackoverflow.com/a/32741930/ | |
| """ | |
| import collections | |
| import os | |
| import select | |
| import signal | |
| import subprocess | |
| import threading |
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
| # Byte-compiled / optimized / DLL files | |
| __pycache__/ | |
| *.py[cod] | |
| *$py.class | |
| # C extensions | |
| *.so | |
| # Distribution / packaging | |
| .Python |
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 | |
| """Get TAI-UTC difference in seconds for a given time using tzdata. | |
| i.e., find the number of seconds that must be added to UTC to compute | |
| TAI for any timestamp at or after the given time[1]. | |
| >>> from datetime import datetime | |
| >>> import leapseconds | |
| >>> leapseconds.dTAI_UTC_from_utc(datetime(2005, 1, 1)) | |
| datetime.timedelta(seconds=32) |