Skip to content

Instantly share code, notes, and snippets.

@fitnr
fitnr / bookmarklet-replaceTextWithFontSize
Last active January 9, 2017 11:31
Replaces all text on a page with the font size. Useful for debugging the page or just replacing wretched content with something less awful.
javascript:%28function%28%29%7Bvar%20n,walk=document.createTreeWalker%28document.body,NodeFilter.SHOW_TEXT,null,0%29%3Bwhile%28n=walk.nextNode%28%29%29%7Bif(n.textContent.trim%28%29.length>0)n.textContent=window.getComputedStyle(n.parentNode).fontSize%3B%7D%7D%29%28%29
states = fl la nc ok va \
al ga ma nd or vt \
ar hi md ne pa wa \
az ia me nh ri wi \
ca id mi nj sc wv \
co il mn nm sd wy \
ct in mo nv tn \
dc ks ms ny tx \
de ky mt oh ut
@fitnr
fitnr / README.md
Last active November 8, 2016 16:20 — forked from stuartlynn/query.sql

Dasymetric Dot Density Mapping for MCNY

All of the code you need to reproduce it is in this gist. You will need to create both the weighted_dot_density.sql and select_random_weights.sql functions in your Carto account (just copy and past them in to the SQL terminal) 

Then you run the query once for each ethnicity which gives you 4 tables with dot density in each for each ethnicity. Oh and after you run the create table queries you need to run 

select cdb_cartodbfytable('account_name', 'table_name') to have it show up in your datasts

You can then ether union them together to make one table or just create 4 layers on the map. You will want to do this through the batch API, I can help you write some scripts to do that if you like. Also the batch API docs are here:

@fitnr
fitnr / eu-referendum-results.csv
Created June 24, 2016 15:14
Results of the June 23, 2016 UK referendum on EU membership, by counting area. Scraped from the BBC.
name leave remain turnout
Aberdeen City 40729 63985 67.9
Aberdeenshire 62516 76445 70.6
Adur 20315 16914 76.4
Allerdale 31809 22429 72.9
Amber Valley 44501 29319 76.3
Angus 26511 32747 68.0
Argyll & Bute 19202 29494 73.1
Arun 56936 34193 77.8
Ashfield 46720 20179 72.8
@fitnr
fitnr / group-by-table-names.sh
Last active April 7, 2019 20:38
Group census API variables.json by data set
curl http://api.census.gov/data/2014/acs5/variables.json |
jq -r '[ .variables | to_entries[] | .value.concept ] | unique[]'
> tables.txt

First, install svgis and breaks. They require some hefty prerequisites. sorry. The last step requires ImageMagick.

brew install gdal numpy scipy # os x
apt-get install python-numpy python-scipy gdal-bin # linux
pip install svgis breaks

Download get-tiger. Optional: edit it to include the Census data fields you desire.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fitnr
fitnr / linux-for-bots.sh
Created January 9, 2016 23:38
set up a ec2 for botting
# make it easier to log in later
ssh-keygen -t rsa -b 4096 -C ec2-user
cat ~/.ssh/id_rsa.pub
# install useful stuff
sudo yum -qy update
sudo yum -qy install git gcc-c++ make mutt zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libjpeg-devel
# install node
curl -s -O https://nodejs.org/dist/v4.2.3/node-v4.2.3.tar.gz
@fitnr
fitnr / git-ics
Created December 28, 2015 23:23
git tool for converting log to ICS file
# git-ics
# Place in your $PATH (e.g. ~/bin)
# Accepts any options that can be passed to git log
# usage: git ics [opts] > cal.ics
echo BEGIN:VCALENDAR
echo METHOD:PUBLISH
echo VERSION:2.0
echo PRODID:-//git-ics//git-ics//EN
echo CALSCALE:GREGORIAN
@fitnr
fitnr / country_codes.csv
Created December 4, 2015 15:21
ISO 3166-1 alpha-2 country codes and country short name
code name
AD Andorra
AE United Arab Emirates
AF Afghanistan
AG Antigua and Barbuda
AI Anguilla
AL Albania
AM Armenia
AO Angola
AQ Antarctica