Skip to content

Instantly share code, notes, and snippets.

@miketahani
miketahani / wtf.py
Created November 5, 2015 22:38
python html parsing inconsistencies
import re
from sys import argv
from bs4 import BeautifulSoup as bs
from pyquery import PyQuery as pq
from lxml import etree
filename = argv[-1]
anchors = re.compile('<a.+?>.+?<\/a>', re.DOTALL|re.I)
with open(filename, 'r') as infile:
@miketahani
miketahani / README.md
Last active November 9, 2015 23:54
d3.unconf ticket

hacky web audio api + d3.

instructions

allow mic access, talk at computer.

view here

@miketahani
miketahani / flickr_photo_scraper.py
Last active June 29, 2016 18:38
get/store flickr photos in a spreadsheet
#!/usr/bin/env python
# get/store flickr photos in a spreadsheet
# you'll need a key: https://www.flickr.com/services/api/keys/apply/
import csv
import json
import sys
from base64 import encodestring as b64
from urllib import urlencode, urlopen as get
from optparse import OptionParser
@miketahani
miketahani / date_finding.py
Last active January 16, 2023 16:22
answer to a NICAR-L question
import re
from datetime import datetime as dt
fake_dates = '10-Jan-2011, 01-Feb-02, ##-Bla-##, 01-Bla-2014'
# you can probably do some lookahead assertion at the end of the regex to only capture 2 digits or the last 2 digits
# instead of the mess below [1]
date_finder = re.compile('(\d{2}-(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{2,4})')
dates = re.findall(date_finder, fake_dates)
@miketahani
miketahani / load-noisejs
Created April 30, 2015 01:51
load noise.js from the console
(function(){var e=document.createElement("script");e.async=!0,e.src="https://rawgit.com/josephg/noisejs/master/perlin.js",e.charset="utf-8",document.body.appendChild(e)})();
@miketahani
miketahani / mapbox-studio-tiles.md
Last active August 29, 2015 14:19
grab mapbox studio tiles

apparently mapbox no longer lets you export mbtiles locally like tilemill used to. this can be a problem when you just spent an hour creating a tileset and suddenly realize that you need to fork over a monthly fee to get your tiles out.

this is the general structure of mapbox studio local tile urls (for styles): http://localhost:3000/style/<z>/<x>/<y>.<ext>?id=tmstyle://<file path>/<style name>.tm2&<autogenerated id>.

after selecting a project, View > Toggle Developer Tools, Network tab, copy the url for a tile, replace the part that corresponds to <z>/<x>/<y> above with {z}/{x}/{y} and you have a template url.

you can use the url to put together a custom provider in tilestache (have to do it yourself, since the proxy provider doesn't seem to support querystring arguments with urls) or if you're doing some rapid prototyping like i was, use this simple script to cache the tiles while you're working on other aspects of the map in the browser.

NOTE: you shou

var request = require('request');
var express = require('express');
var app = express();
app.get('/goofy', function(req, res) {
request('http://images1.wikia.nocookie.net/__cb20120715102950/disney/images/a/a5/Disneygoofy2012.jpeg').pipe(res);
});
app.get('/loop', function(req, res) {
res.render('mypage');
# some convenience functions here, nothing new
'''
# usage:
from easypipe import easy_pipeline
from easypipe import print_metrics
data_folder = "data-hold/20news"
p = easy_pipeline()
print_metrics(p, data_folder)
'''
@miketahani
miketahani / maptile-urls.md
Last active April 14, 2017 02:29
slippy map tile urls
// This is the core Javascript code for http://windhistory.com/
// I haven't done a full open source release, but I figured I'd put the most important
// D3 code out there for people to learn from. [email protected]
/** Common wind rose code **/
// Function to draw a single arc for the wind rose
// Input: Drawing options object containing
// width: degrees of width to draw (ie 5 or 15)
// from: integer, inner radius