Skip to content

Instantly share code, notes, and snippets.

@fitnr
fitnr / websetup.md
Last active October 3, 2015 17:46
Setting up a local LAMP web server on OS X

Spinning up a local web server on OS X shouldn't be difficult, but it's a little fussy. This is a reminder list.

MySQL

Install MySQL

Update the path of the mysql socket. This fixes an OS X bug.

If you have a file at /tmp/mysql.sock but none at /var/mysql/mysql.sock, then:

@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 / polyencode.py
Created October 20, 2015 18:55
Quick cli tool for encoding coordinates with Google's encoded polyline algorithm. Requires polyencode (pip install polyencode).
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import gpolyencode
"""
polyencode.py
Encode list of x,y coordinates with Google's encoded polyline algorithm
see: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
@fitnr
fitnr / zip-prefix-adjacency
Created October 28, 2015 20:32
This lists the first two zip code numbers for each state and its bordering states. e.g., the NY list includes "10", found in Manhattan as well as "07", found in NJ.
WA = 99 83 97 98
DE = 15 21 17 16 19 18 08 20 07
DC = 24 20 21 22 23
WI = 48 49 55 54 56 51 50 53 52 60 61 62
WV = 24 25 23 15 21 17 16 19 18 44 45 22 43 40 41 26 20 42
HI = 96
FL = 39 33 32 31 30 36 35 34
WY = 59 57 82 83 68 69 80 81 84
NH = 02 03 01 04 05
NJ = 11 10 13 12 15 14 17 16 19 18 08 07
@fitnr
fitnr / index.html
Last active November 21, 2015 19:27
leaflet fullscreen and mapbox geocoder don't play nicely together
<!DOCTYPE html>
<html>
<head>
<title>geocontrol and fullscreen example</title>
<style>
#map {
width: 960px;
height: 500px;
}
</style>
@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
@fitnr
fitnr / git-archive-file.sh
Last active December 4, 2015 23:42
Great a nicely-named archive file from your git repository
#!/bin/bash
# Save this somewhere in your path as "git-archive-file"
# and do 'chmod u+x git-archive-file'
# If run at tag "v10.0", archvie file will be named "repo-v10.0.zip"
# If run after one commit after a tag, file will be named "repo.v10.0-1-gdc03bc1.branchname.zip"
# adapted from
# http://blog.thehippo.de/2012/03/tools-and-software/how-to-create-a-custom-git-command-extension/
@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 / .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;}); }