Skip to content

Instantly share code, notes, and snippets.

View jboynyc's full-sized avatar
🍜

John Boy jboynyc

🍜
View GitHub Profile
@jboynyc
jboynyc / playing-with-macros.rkt
Created March 27, 2018 23:17
racket macro experimentation
#lang racket
(define-syntax define-html-tag
(syntax-rules ()
[(_ element)
(define element
(let ([es (symbol->string 'element)])
(make-keyword-procedure
(lambda [keys vals . contents]
(let ([properties (string-join
@jboynyc
jboynyc / new_key_announcement.txt
Created February 14, 2018 22:39
I have a new pgp key
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
I am transitioning to using a new pgp key with fingerprint 272B9BDD29CFE9509A3DC60629A105A586DEB641.
You can get it from keyservers or keybase.io/jboy now.
This message is signed with my current key (74A7A4B33DE1D395), which expires in a few days.
-----BEGIN PGP SIGNATURE-----
iQIzBAEBCgAdFiEEsQFdpc0ErrdEdt31mR24sJ2K5NgFAlqEujsACgkQmR24sJ2K
@jboynyc
jboynyc / give_me_text.py
Created July 21, 2017 08:54
Give Me Text
import requests
def pdf_to_text(pdf_file):
'''
See http://givemetext.okfnlabs.org/#api for a description of the API.
'''
r = requests.put('http://beta.offenedaten.de:9998/tika', open(pdf_file, 'rb'))
r.raise_for_status()
r.encoding = 'utf-8'
@jboynyc
jboynyc / rolx.py
Created February 7, 2017 17:19
Run SNAP RolX role extraction on an IGraph network graph.
import subprocess
from collections import defaultdict
from tempfile import NamedTemporaryFile
import igraph as ig
ROLX_BIN = 'Snap-3.0/examples/rolx/testrolx'
def extract_roles(input_graph, min_roles=2, max_roles=3):
@jboynyc
jboynyc / setup-snappy.sh
Created February 7, 2017 17:05
Set up SNAP Python package in a virual environment
set -e
snap_env=snap_env
snap_pkg=snap-3.0.2-3.0-centos6.5-x64-py2.6
virtualenv -p python2.7 ${snap_env}
source snap_env/bin/activate
if [-d $snap_pkg ]
then wget http://snap.stanford.edu/snappy/release/${snap_pkg}.tar.gz && tar xzf ${snap_pkg}.tar.gz
fi
@jboynyc
jboynyc / Flying_Circus.ipynb
Last active January 26, 2017 12:16
Flying Circus Python course notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jboynyc
jboynyc / quicksort.scm
Created November 23, 2016 15:57
quicksort in Chicken Scheme
(use srfi-1) ; provides filter
(define (quicksort elems)
(if (null? elems) (list)
(let [[middle (car elems)]
[others (cdr elems)]]
(let [[left (filter (lambda (x) (<= x middle)) others)]
[right (filter (lambda (x) (> x middle)) others)]]
(append (quicksort left) (cons middle (quicksort right)))))))
@jboynyc
jboynyc / mapillary.py
Last active November 18, 2016 10:52
simple Mapillary API wrapper (for Python 3.4+)
# coding=utf-8
import requests
from yaml import load as yaml_load
from functools import partialmethod
from urllib.parse import urlencode, quote
class Mapillary(object):
def __init__(self, token='token.yaml'):
self._base_url = 'https://a.mapillary.com/v2'
@jboynyc
jboynyc / amsterdam_bounds.wkt
Created November 17, 2016 14:03
Amsterdam municipality bounds
MULTIPOLYGON (((4.7567178999999999 52.3778378000000020, 4.7564339000000002 52.3777635000000000, 4.7569860000000004 52.3770463000000030, 4.7575304999999997 52.3761888000000010, 4.7580470000000004 52.3750653000000030, 4.7583805000000003 52.3740153000000030, 4.7585170000000003 52.3732593000000010, 4.7585676000000001 52.3727554000000030, 4.7585964000000001 52.3722175999999990, 4.7585747999999999 52.3715943999999990, 4.7585107999999998 52.3712412000000000, 4.7584413999999997 52.3709575999999970, 4.7579834999999999 52.3692393999999980, 4.7578265000000002 52.3687134999999980, 4.7567178999999999 52.3778378000000020)), ((4.7590846000000004 52.3807575000000010, 4.7590851000000001 52.3807377999999990, 4.7590902000000002 52.3805027000000010, 4.7590915000000003 52.3804415999999970, 4.7590922000000004 52.3804074000000030, 4.7590925999999998 52.3803957000000010, 4.7591020999999998 52.3800388000000010, 4.7591023999999997 52.3800254000000010, 4.7591028000000000 52.3800136999999990, 4.7591124999999996 52.3797112000000030, 4.75
@jboynyc
jboynyc / snarf-all-pdfs.py
Last active June 8, 2016 10:23
Easily download all linked PDFs from a web page using the IPython/Jupyter console
from bs4 import BeautifulSoup as bs
r = !curl -s 'https://example.net'
s = bs(''.join(r))
for link in s.findAll('a', {'href': lambda x: x.endswith('pdf')}):
loc = link['href']
!curl -O $loc