Skip to content

Instantly share code, notes, and snippets.

View banterability's full-sized avatar

Jeff Long banterability

View GitHub Profile
@banterability
banterability / us.json
Created January 25, 2023 19:54
states
[
{ "code": "SC", "name": "South Carolina" },
{ "code": "AL", "name": "Alabama" },
{ "code": "NE", "name": "Nebraska" },
{ "code": "WV", "name": "West Virginia" },
{ "code": "ID", "name": "Idaho" },
{ "code": "MO", "name": "Missouri" },
{ "code": "AK", "name": "Alaska" },
{ "code": "UT", "name": "Utah" },
{ "code": "IA", "name": "Iowa" },
"Arkansas",
"Washington, D.C.",
"Delaware",
"Florida",
"Georgia",
"Kansas",
"Louisiana",
"Maryland",
"Missouri",
"Mississippi",
@banterability
banterability / intcomma.js
Created August 31, 2010 21:07
Add commas to integers (2000000 -> 2,000,000) in javascript
var intcomma = function(value) {
// inspired by django.contrib.humanize.intcomma
var origValue = String(value);
var newValue = origValue.replace(/^(-?\d+)(\d{3})/, '$1,$2');
if (origValue == newValue){
return newValue;
} else {
return intcomma(newValue);
}
};
@banterability
banterability / battery.coffee
Last active January 14, 2016 00:37
Get iPhone battery life over time from Reporter App's (http://www.reporter-app.com/) logs in Dropbox
async = require 'async'
fs = require 'fs'
{filter, flatten} = require 'underscore'
OBJ_C_EPOCH = 978307200
DROPBOX_DIR = #"<path to your dropbox folder >/Dropbox/Apps/Reporter-App/"
fs.readdir DROPBOX_DIR, (err, files) ->
throw new err if err?
dataFiles = filter files, (filename) -> /.json/.test filename
@banterability
banterability / ctaIcons.js
Created August 14, 2013 23:16
Generate images from groups of CTA L lines and generate data URLs for use as iOS home screen icons.
var ctaColors = {
blue: '#00A1DE',
brown: '#62361B',
green: '#009B3A',
orange: '#F9461C',
pink: '#E27EA6',
purple: '#522398',
red: '#C60C30',
yellow: '#F9E300'
}
function flashSupported(){
if (window.ActiveXObject){
try {
new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
return true;
} catch (e) {
return false;
}
} else {
return Array.from(navigator.plugins).some(function(plugin){
<script src="http://media.scpr.org/assets/scripts/webtrends.v2.js"></script>
<script>
//<![CDATA[
var _tag=new WebTrends();
_tag.dcsGetId();
//]]>
</script>
<script>
//<![CDATA[
_tag.dcsCustom=function(){
@banterability
banterability / code2doc.coffee
Created January 11, 2011 21:03
Bookmarklet to switch between GitHub code & documentation in GitHub pages
h = location.href
docStr = /^http:\/\/(\w*).github.com\/(\w*)(?:\/.*)?/
codeStr = /^https?:\/\/github.com\/(\w*)\/(\w*)(?:\/.*)?/
docTmp = "http://$user.github.com/$proj"
codeTmp = "https://github.com/$user/$proj"
isDoc = h.match(docStr)
isCode = h.match(codeStr)
redirect = (loc) ->
@banterability
banterability / score.py
Created December 1, 2010 23:25
Time-based ranking algorithm influenced by Hacker News
# based on http://amix.dk/blog/post/19574
from datetime import datetime, timedelta
GRAVITY = 0.5 # HN default: 1.8
WINDOW = 36 # max age in hours
now = datetime.now()
def hours_from_dt(dt):
@banterability
banterability / eml_parser.py
Created October 7, 2010 22:22
Rough sketch of a parser for California election data feeds
import os
import shutil
import urllib2
import zipfile
from lxml import etree # requires lxml & friends
# TODO:
# - Total vote counts
# - County-level results