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
package main | |
import ( | |
"compress/gzip" | |
"os" | |
"bufio" | |
"fmt" | |
"log" | |
) |
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 inspect | |
import collections | |
import functools | |
# NB: For all the "make_x_tester" functions the errors raised should use lowercase | |
# "argument" to describe the problem, which will be patched to "return value" | |
# where appropriate! | |
def make_simple_tester(valuetype): | |
def testerfunc(tested_val): |
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 python3 | |
# by Cathal Garvey, copyright 2015, released under the AGPL: https://gnu.org/licenses/agpl.txt | |
# Commissioned by a 4chan user on reddit /r/linux who wanted backups but wget couldn't fetch most JS/CSS | |
# correctly. Only tested on 4chan in keeping with request. | |
# Usage e.g. (papercraft sub on 4chan): | |
# wget --recursive --no-clobber --page-requisites --html-extension --convert-links --no-parent http://boards.4chan.org/po/ | |
# cd boards.4chan.org | |
# # (Directory contains subdirectory "po/" which contains all HTML) | |
# # (Provide root domain of crawled site to help resolve relative links, and target folder) | |
# python3 <this script> boards.4chan.org po |
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
Bio-rad.com has one of those intensely aggravating landing dialogs that demands | |
to know where you are so it can forcibly remove you from what you're trying to | |
view, and perhaps gouge you for more money. | |
This is annoying, invasive and generally not-cool, so here's a little | |
bookmarklet to remove the dialog and get on with things. | |
To use, just copy the below code into a new bookmark using your browser's | |
bookmark manager. Don't omit the "javascript:" bit or the final empty | |
parentheses: "()". |
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
# Pure Python ChaCha20 | |
# Based on Numpy implementation: https://gist.github.com/chiiph/6855750 | |
# Based on http://cr.yp.to/chacha.html | |
# | |
# I wanted an implementation of ChaCha in clean, understandable Python | |
# as a way to get a handle on the algorithm for porting to another language. | |
# There are plenty of bindings but few pure implementations, because | |
# Pure Python is too slow for normal practical use in Cryptography. | |
# | |
# The preceding implementation used NumPy, which avoided a lot of the |
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
# This is a micro-language designed to be embedded in JSON, allowing | |
# data in the JSON tree to specify a formula for how it should be derived | |
# based on the rest of the tree. Formulas are constructed of prefix-notation | |
# lists naming a function and passing arguments, which are recursively | |
# evaluated. | |
# | |
# Operations are mostly mathematical, with one ternary function that allows | |
# for simple conditional operations or code-branching. | |
# | |
# An example: |
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 random | |
import shutil | |
import tty | |
import sys | |
import termios | |
def getchar(): | |
'Linux-only: Could not be bothered making arrow-getting code WinMac-compatible.' | |
fd = sys.stdin.fileno() | |
old_settings = termios.tcgetattr(fd) |
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 strict(func): | |
'''A decorator for methods or functions that requires annotations for all | |
arguments and the return value, throws typeerrors on deviations. | |
Remember that for more than one return value, the return type is "tuple". | |
Container-type arguments or return values are only inspected at top-level. | |
Note that as written, this does not handle catchall argument types "*args", or "**kwargs". | |
''' | |
import inspect, collections | |
NoneType = type(None) | |
def die_on_untyped_annotation(par, ann_type="argument annotation"): |
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
class Prune: | |
'Treat like a function; call Prune.prune on any datatype to prune NoneTypes and empty Tuples/Lists/Dicts.' | |
_t = tuple() # Empty tuple, as "(,)" literal doesn't work. | |
@classmethod | |
def prune(self, some_data): | |
if isinstance(some_data, (list, tuple)): | |
return self.prune_sequence(some_data) | |
elif isinstance(some_data, dict): | |
return self.prune_tree(some_data) |
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 sys as s, itertools as i | |
t,u,i2b,o=b'T',b'U',lambda i:i.to_bytes(1,'big'),[s.stdout.buffer.write,lambda s:0] | |
A,e=s.argv,dict(zip((''.join(x).encode()for x in i.product(*('ACGT',)*4)),map(i2b,range(256)))) | |
with open(A[2],'rb')as I:D,Rr=b''.join(I.read().strip().split()),lambda s:s.replace(t,u) | |
S,R,M,o,d=D[:-1],D[-1]&4,D[-1]&2,o[::-1]if A[1]=="d"else o,dict(zip(e.values(),e)).get | |
[o[0](e.get(q.replace(u,t)+(b'A'*(4-len(q)))))for q in(D[i: i+4] for i in range(0,len(D),4))] | |
o[0](i2b((len( [D[i: i+4] for i in range(0,len(D),4)][-1] )%4)|(4 if u in S else 0))) | |
o[1](b''.join(Rr(d(i2b(x)))if R else d(x)for x in S)[:-M if M else None]+b'\n') |
NewerOlder