Skip to content

Instantly share code, notes, and snippets.

View jdunck's full-sized avatar

Jeremy Dunck jdunck

View GitHub Profile
@jdunck
jdunck / example.html
Created March 17, 2019 18:26
crawl stub
<html>
<body>
<img src="foo"/>
<img src="bar"/>
</body>
</html>
@jdunck
jdunck / heap.py
Created March 13, 2019 04:44
Min/Max heap for python
import heapq
class Heap(object):
def __init__(self, max=False):
self.max = max
self.data = []
@property
def delta(self):
return -1 if self.max else 1
def push(self, item):
@jdunck
jdunck / Example.sh
Created September 28, 2016 20:14
Handmade CJK coverage util
$ ls -1 font-repo/
HelveticaNeue.ttf
LucidaGrande.ttc
meiryo.ttc
ヒラギノ丸ゴ ProN W4.ttc
ヒラギノ角ゴシック W8.ttc
$ python handmade-cjk.py
num desired: 23216
num unsupported: 6640
extras (supported by not desired): 6563
@jdunck
jdunck / email.txt
Created July 9, 2016 02:28
Supporting Django and Rest Framework
We get a lot of value from Django and Rest Framework, both of which are freely-licensed and volunteer-supported. I think it would be good to financially support the projects, at $X per year and $Y per month, respectively.
Details:
Django has a fellowship which funds a full-time developer to shepherd the contribution and release process. This has had a large impact on the project, making releases more reliable and widening the pool of contribution: https://www.djangoproject.com/weblog/2015/jan/21/django-fellowship-retrospective/
Rest Framework is largely the work of a single core contributor, Tom Christie, who quit his job some time back in order to try to make DRF into financial break-even for himself.
Details on sponsorship for both projects are here:
https://www.djangoproject.com/fundraising/
@jdunck
jdunck / example.sh
Created May 16, 2016 19:51
Git tags are repo-wide
mbp3:junk jdunck$ mkdir test
mbp3:junk jdunck$ cd test/
mbp3:test jdunck$ git init
Initialized empty Git repository in /Users/jdunck/junk/test/.git/
mbp3:test jdunck$ echo x > derp
mbp3:test jdunck$ git add derp
mbp3:test jdunck$ git commit -m "Initial"
[master (root-commit) 818e7a7] Initial
1 file changed, 1 insertion(+)
create mode 100644 derp
@jdunck
jdunck / permissions.sql
Created May 10, 2016 23:09
postgres permissions
select usename, nspname || '.' || relname as relation,
case relkind when 'r' then 'TABLE' when 'v' then 'VIEW' end as relation_type,
priv
from pg_class join pg_namespace on pg_namespace.oid = pg_class.relnamespace,
pg_user,
(values('SELECT', 1),('INSERT', 2),('UPDATE', 3),('DELETE', 4)) privs(priv, privorder)
where relkind in ('r', 'v')
and has_table_privilege(pg_user.usesysid, pg_class.oid, priv)
and not (nspname ~ '^pg_' or nspname = 'information_schema')
order by 2, 1, 3, privorder;
@jdunck
jdunck / dms_settings.py
Created April 26, 2016 15:47
DMS database config
# at bottom of settings.prod:
DATABASES = {
"source": local.OLD_DATABASES['default'],
"dest": local.NEW_DATABASES['default']
}
DATABASES['default'] = DATABASES['dest']
@jdunck
jdunck / Example output
Last active February 26, 2016 01:07
Delete from a large table in chunks
delete from x where id < 1;
select sleep(.25);
delete from x where id < 50001;
select sleep(.25);
delete from x where id < 100001;
In nginx.conf, in the Logging Settings section:
log_format replay '[$time_local] $server_name $status $content_type $request_method XX_HOST_XX$request_uri Authorization:"$http_authorization" $request_body_file';
In specific server/location's config:
client_body_in_file_only on;
access_log /var/log/nginx/whatever-replay.log replay;
from psycopg2.extras import DictCursor
from django.db import connections
def get_cursor(alias='default', cursor_factory=None):
"""map from django's ORM layer to the raw DB cursor."""
wrapped_conn = connections[alias]
# hack to ensure connection is immediately opened:
if wrapped_conn.connection is None: