Skip to content

Instantly share code, notes, and snippets.

@fitnr
fitnr / insertdatetime.py
Created September 18, 2012 18:59
Insert date and time in Sublime Text 2
import sublime_plugin
import time
class InsertDateTimeCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
sel = self.view.sel()
output = self.date(args)
@fitnr
fitnr / apportion.py
Last active August 4, 2016 16:33
Apportionment algorithm for the US House of Representatives
# Uses method of least proportions to apportion House members among states.
# http://en.wikipedia.org/wiki/United_States_congressional_apportionment#The_Method_of_Equal_Proportions
# use like this:
# python apportion.py --built-in 2010
# python apportion.py --file file.csv --key <column name>
# python apportion.py --file file.csv --key <column name> --reps 444
# python apportion.py --file file.csv --key <column name> --distsize 500000
from __future__ import division, print_function
import sys
import csv
@fitnr
fitnr / Makefile
Last active March 3, 2016 14:35
A snapshot of the CLUI Land Use Database http://clui.org/ludb
# run make to create clui-database.geojson
# Requires jq https://stedolan.github.io/jq/
PATTERN = .gmap.auto1map.markers | map({ \
properties: { \
title: .opts.title, \
url: (.text | sub(".+href=."; "http://clui.org") | sub(". target.+"; ""))\
}, \
geometry: { \
type: "Point", \
@fitnr
fitnr / csstidytest.php
Last active December 16, 2015 03:59
Minimal use of [CSSTidy PHP](https://github.com/Cerdic/CSSTidy) library.
#!/usr/bin/php
<?php
include 'csstidyphp/class.csstidy.php' ;
$css = new csstidy();
// place the CSS that breaks here
$input = "body .foo {
*width: 10px;
width: 50px;
@fitnr
fitnr / snd_parse.py
Last active March 14, 2018 16:09
The New York City Street Name Dictionary is in an insane fixed-width format. This python script parses it into a CSV.
from csv import writer
from collections import OrderedDict
'''
The New York City Street Name Dictionary is in an insane fixed-width format.
This python script parses it into a CSV.
http://www.nyc.gov/html/dcp/html/bytes/applbyte.shtml
'''
FIELDS_S = OrderedDict([
('_', 1),
@fitnr
fitnr / .bash_profile
Created May 3, 2013 19:05
command line prompt with dir, pizza and current git branch
if [ -f /usr/bin/git-completion.sh ]; then
. /usr/bin/git-completion.sh
else
echo "could not find git completion"
fi
export PS1='\W$(__git_ps1 " (%s) ") 🍕 '
export PATH="/usr/local/mysql/bin:$PATH"
@fitnr
fitnr / hexToRGB.js
Last active December 17, 2015 16:29
convert hex to rgb
// Adapted from http://www.javascripter.net/faq/hextorgb.htm
function hexer(h, from, to) { return parseInt((h.charAt(0)=="#" ? h.substring(1,7):h).substring(from,to), 16); }
function hexToR(h) {return hexer(h, 0, 2);}
function hexToG(h) {return hexer(h, 2, 4);}
function hexToB(h) {return hexer(h, 4, 6);}
function rnd(x) {return Math.round(100*x) / 100;}
function hexToIntRGB(h) { return [hexToR(h), hexToG(h), hexToB(h)]; }
function hexToDecRGB(h) { return [rnd(hexToR(h)/256), rnd(hexToG(h)/256), rnd(hexToB(h)/256)]; }
function decRGBToIntRGB(rgb) { return rgb.map(function(r) { return parseInt(r * 256);}); }
function intRGBToDecRGB(rgb) { return rgb.map(function(r) { return r / 256;}); }
@fitnr
fitnr / address-splitter.js
Last active February 6, 2021 01:45
Split an address into number and street parts
// http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric/1830844#1830844
function isNumber(n) { return !isNaN(parseFloat(n)) && isFinite(n); }
// Check if character is a fraction, e.g. ¼
function isFractionalChar(n) {
c = n.charCodeAt();
return (c >= 188 && c <= 190) || (c >= 8531 && c <= 8542);
}
// return the first fractional character in a string
@fitnr
fitnr / formalize-street-names.js
Last active December 18, 2015 19:39
A tool for formalizing street names. Given as a Sublime Text 2 plugin and a javascript function
function formalizeStreet(street) {
var streetPatterns = [
// Full Street Extension
// See below for Street, Drive and Lane
[/\baly\b\.?/gi, 'Alley'],
[/\bave?\b\.?/gi, 'Avenue'],
[/\bfr?wy\b\.?/gi, 'Freeway'],
[/\brd\b\.?/gi, 'Road'],
[/\bbl(vd)?\b\.?/gi, 'Boulevard'],

Custom Twitter Stylesheet

Craig Mod does a bigger overhaul with Twitter for Minimalists, but this will only do the following:

  • Hides promoted tweets and trends
  • Hides the useless “Expand” link that appears under every tweet
  • Tones down the blue conversation line to a barely-visible gray

You can add this CSS in Safari with this extension. The URL to target is twitter.com/*.