Skip to content

Instantly share code, notes, and snippets.

import sys
from_string = sys.argv[1]
to_string = sys.argv[2]
with open("input.txt") as f:
text = f.read()
text = text.replace(from_string, to_string)
/* Why do this ... */
load: function(url) {
setTimeout(function () { doload(url) }, 1);
}
doload: function (url) {
/* synchronous XHR */
xhr.open("GET", url, false);
xhr.send(null);
@avian2
avian2 / check-firefox-passwords.py
Last active February 26, 2017 18:31
Check saved Firefox passwords against the list of domains that use Cloudflare
#!/usr/bin/python3
import glob
import json
import sys
import os
from urllib.parse import urlparse
# download from https://github.com/pirate/sites-using-cloudflare/
cloudflare_tlds = frozenset(map(lambda x:x.strip(),
open("sites-using-cloudflare-master/sorted_unique_cf.txt")))
@avian2
avian2 / ocsp_age_
Created December 15, 2016 12:49
Munin plugin for monitoring age of stapled OCSP responses.
#!/usr/bin/python
import re
import subprocess
import sys
import time
import datetime
def parse_date(date):
dt = datetime.datetime.strptime(date, "%b %d %H:%M:%S %Y GMT")
import traceback
import re
def debug_var(a):
s = traceback.extract_stack(limit=2)[0][3]
g = re.match("\w+\((\w+)\)", s)
print("%s = %r" % (g.group(1), a))
def main():
foo=1
### Hettinger's way
# robot.py
class Robot(object):
def move(self):
print('Movement')
class CleaningRobot(Robot):
def clean(self):
# pizza.py
class DoughFactory(object):
def get_dough(self):
return 'insecticide treated wheat dough'
class Pizza(DoughFactory):
def order_pizza(self, *toppings):
@avian2
avian2 / gist:0635215fb6a664690444
Created February 20, 2015 08:48
Spectrum Wars proposed interface
class Player:
"""Base class for the algorithm controlling a receiver and/or transmitter.
Users should derive their own classes from this one and override
methods as necessary.
class MyPlayer(Player):
...
The system creates two instances: one controlling the receiver and one
py32-latest create: /home/avian/dev/opencontracting/jsonmerge/.tox/py32-latest
py32-latest installdeps: jsonschema
ERROR: invocation failed, logfile: /home/avian/dev/opencontracting/jsonmerge/.tox/py32-latest/log/py32-latest-1.log
ERROR: actionid=py32-latest
msg=getenv
cmdargs=[local('/home/avian/dev/opencontracting/jsonmerge/.tox/py32-latest/bin/pip'), 'install', 'jsonschema']
env={'PYTHONIOENCODING': 'utf_8', 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'WINDOWPATH': '7', 'LOGNAME': 'avian', 'USER': 'avian', 'GNOME_KEYRING_CONTROL': '/home/avian/.cache/keyring-im0pyK', 'LC_PAPER': 'sl_SI.UTF-8', 'PATH': '/home/avian/dev/opencontracting/jsonmerge/.tox/py32-latest/bin:/home/avian/src/depot_tools:/home/avian/local/eagle-5.11.0/bin:/home/avian/local/bin:/home/avian/syn/bin:/usr/local/bin:/usr/sbin:/sbin:/usr/bin:/bin', 'DISPLAY': ':0', 'SSH_AGENT_PID': '12184', 'LANG': 'en_US.utf8', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'XDG_SESSION_COOKIE': '4aaab8b188ece36029e4747a00000014-1407223324.605827-1316331910',
# vim:ts=4 sw=4 expandtab softtabstop=4
import json
import jsonschema
def main():
record = json.load(open("blank-ocds.json"))
schema = json.load(open("../standard/standard/schema/record-schema.json"))
jsonschema.validate(record, schema)
main()