Skip to content

Instantly share code, notes, and snippets.

View ericfrederich's full-sized avatar

Eric L. Frederich ericfrederich

View GitHub Profile
#!/usr/bin/env python
import os
import sys
import subprocess
import re
regexes = map(re.compile, [
r'(IMG|PANO)_(?P<YEAR>\d{4})(?P<MONTH>\d{2})(?P<DAY>\d{2})_(?P<HOUR>\d{2})(?P<MINUTE>\d{2})(?P<SECOND>\d{2})(?P<EXTRA>.*).jpg',
@ericfrederich
ericfrederich / async_slot2.py
Created March 10, 2016 05:53
Example of async slots with a network request
import math
import sys
import asyncio
from functools import partial
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QGridLayout, QProgressBar
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest
from PyQt5.QtCore import QUrl
from quamash import QEventLoop
@ericfrederich
ericfrederich / async_slot.py
Created March 10, 2016 05:13
Example of using an asyncio coroutine as a Qt slot
import math
import sys
import asyncio
from functools import partial
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QGridLayout, QProgressBar
from quamash import QEventLoop
class MyWidget(QWidget):
#!/usr/bin/env python
# based on slice example from
# https://medium.com/@tucnak/why-go-is-a-poorly-designed-language-1cc04e5daf2#.pr6pifnky
from itertools import count
def log(item, log_counter=count(start=1)):
print next(log_counter), item
@ericfrederich
ericfrederich / bloom_filter.py
Last active August 29, 2015 14:14
Example bloom filter implementation / test in Python
#!/usr/bin/env python
import hashlib
from math import ceil, log
def hasher(x, n):
ret = []
h = hashlib.sha1()
h.update(x)
for i in range(n):
#!/usr/bin/env python
from cleantar import single_prefix
import sys
import os
import time
single, msg = single_prefix(sys.argv[1])
if single:
print 'tar file is clean; just one prefix; will untar',; sys.stdout.flush()
for i in range(5, 0, -1):
#!/bin/sh
if "true" : '''\'
then
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $DIR/venv/bin/activate
exec python "$0" "$@"
exit 127
fi
'''
#
# example output with redirect cache and 301 response
#
# first request to /old
127.0.0.1 - - [11/Jun/2014 13:45:13] "GET /old HTTP/1.1" 301 6
127.0.0.1 - - [11/Jun/2014 13:45:13] "GET /new HTTP/1.1" 301 6
127.0.0.1 - - [11/Jun/2014 13:45:13] "GET /newer HTTP/1.1" 301 6
127.0.0.1 - - [11/Jun/2014 13:45:13] "GET /newest HTTP/1.1" 200 6
# 3 more requests to /old
#!/usr/bin/env python
import sys
port = int(sys.argv[1])
import requests
s = requests.session()
base_url = 'http://localhost:%d' % port
print '-------- request /old'
#!/usr/bin/env python
import sys
from bottle import get, run, response
PORT = int(sys.argv[1])
STATUS = int(sys.argv[2])
@get('/old')
def index():