Skip to content

Instantly share code, notes, and snippets.

@tmaybe
tmaybe / parse.py
Created February 24, 2013 05:02
Simple Python script for reading from a file, changing something about it with a regular expression, and writing the result to a new file.
import re
read_in = open("original.plist")
write_out = open("new.plist","w")
minus = 280
pat = re.compile('\t\t\t\t<real>([0-9]*)<')
for line in read_in:
mo = pat.search(line)
if mo:
value = int(mo.group(1))
@tmaybe
tmaybe / gist:5357731
Created April 10, 2013 19:34
Snippet for a quick UIButton in Objective-C
UIButton *tmpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
tmpButton.frame = CGRectMake(0, 0, 100, 50);
[tmpButton addTarget:self action:@selector(pressButton:) forControlEvents:UIControlEventTouchUpInside];
[tmpButton setTitle:@"TEST" forState:UIControlStateNormal];
[self.view addSubview:tmpButton];
@tmaybe
tmaybe / README.md
Last active September 26, 2018 08:05
Scrubbable Moving Image

A simulated scrubbable animated gif.

Mouse over the video to scrub it. Works by rapidly changing the position of a jpeg sprite sheet in the background of a div.

Inspired by GIFCTRL

@tmaybe
tmaybe / PROCESS.md
Last active December 19, 2015 17:09
Afghanistan Albers

Convert shape file to GeoJSON file

ogr2ogr -f GeoJSON provincial.json admin2_poly_32.shp

Convert and combine GeoJSON files into a single TopoJSON file, making the contents of either DIST_32_NA or PRV_NAME the id attribute, renaming the PROV_32_NA property to province, and preserving the province property

topojson --id-property DIST_32_NA,PRV_NAME -p province=PROV_32_NA -p province -o combined.json international-geo.json provinces-geo.json districts-geo.json

@tmaybe
tmaybe / README.md
Last active December 20, 2015 11:39 — forked from tommaybe/LICENSE.md
Heat Grid Showing Survey Results
@tmaybe
tmaybe / README.md
Last active January 5, 2018 01:31
Stacked to Normalized Stacked Bar Chart

Based on mbostock's examples Stacked Bar Chart and Normalized Stacked Bar Chart. Adds transitions between the two states.

Data shows answers to the question "Generally speaking, do you think things in Afghanistan today are going in the right direction, or do you think they are going in the wrong direction?" in the Asia Foundation's 2012 Survey of the Afghan People broken down by gender, age, location, ethnicity, income, education and region.

@tmaybe
tmaybe / README.md
Last active December 21, 2015 03:59
two methods of displaying data from a Google spreadsheet compared

Testing two different methods for pulling data from a google spreadsheet for display on a web page:

  • using a direct link to the automatically generated csv as described by Kristin Henry.

  • using Tabletop.js to parse the spreadsheet automatically generated in 'Web page' format.

It appears that the csv version of the data generated by Google updates less frequently than the 'Web page' version, so using Tabletop.js is more reliable if you need immediate updates on data without manual refresh.

@tmaybe
tmaybe / strip_quoted_newlines.py
Last active September 27, 2016 20:30
strip quoted newlines from a folder-full of CSV files
import csv
import re
import glob
for input_filename in glob.glob("./*.csv"):
print("working on {}".format(input_filename))
with open(input_filename, 'rU') as infile:
output_filename = "./strp-{}.csv".format(input_filename.lower().rstrip(".csv").lstrip("./"))
with open(output_filename, 'a') as outfile:
output_writer = csv.writer(outfile)
@tmaybe
tmaybe / check_non_utf8.py
Created February 11, 2014 21:41
Check a file for non-UTF-8 characters
import re
with open("calon-dprd_diy.csv", 'rU') as f:
for line in f:
if re.search(r'[\x80-\xFF]', line):
print 'bad string in line ' + line
@tmaybe
tmaybe / DPD_results_current.json
Last active August 29, 2015 13:56
before and after examples of JSON output for the geographic endpoint
{
"results": {
"count": 1,
"polygons": [{
"id_polygon": 22848,
"provinsi DPD": "Daerah Khusus Ibukota Jakarta",
"caleg_results": {
"count": 35,
"caleg": []
}