Skip to content

Instantly share code, notes, and snippets.

Avatar

James McKinney jpmckinney

View GitHub Profile
@jpmckinney
jpmckinney / tz_identifiers_to_rails_identifiers.rb
Created Jan 5, 2011
Maps tz database time zone identifiers to Rails time zone identifiers
View tz_identifiers_to_rails_identifiers.rb
# blog post: http://blog.slashpoundbang.com/post/2613268281/changing-from-tz-database-identifiers-to-rails-friendly
{
"Australia/Adelaide" => "Adelaide",
"Australia/Broken_Hill" => "Adelaide",
"America/Anchorage" => "Alaska",
"America/Juneau" => "Alaska",
"America/Nome" => "Alaska",
"America/Yakutat" => "Alaska",
"Pacific/Gambier" => "Alaska",
"Asia/Almaty" => "Almaty",
@jpmckinney
jpmckinney / flaticon_to_iso2.py
Last active Dec 2, 2021
Renames flags from Flaticon to use ISO 3166-1 alpha 2 codes.
View flaticon_to_iso2.py
import os
import sys
from hdx.location.country import Country
# https://www.flaticon.com/packs/rectangular-country-simple-flags?word=flags
FLAG_PATH = 'path/to/flaticon/folder'
excluded = {
# Non-ISO states with limited recognition
@jpmckinney
jpmckinney / opml_generator.rb
Last active Nov 25, 2021
Given an array of URLs, outputs an OPML file to STDOUT
View opml_generator.rb
# blog post: http://blog.slashpoundbang.com/post/3385815540/how-to-generate-an-opml-file-with-ruby
require 'open-uri'
require 'builder'
require 'truffle-hog'
require 'nokogiri'
# CHANGE ME
urls = %w(http://example.com/ http://example.org/)
@jpmckinney
jpmckinney / unpack_and_beautify.h
Created Dec 27, 2010
unpack_and_beautify.js as char array
View unpack_and_beautify.h
// blog post: http://blog.slashpoundbang.com/post/2488598258/running-javascript-from-the-command-line-with-v8
const char unpack_code[] = {
0x2f,0x2f,0x20,0x62,0x6c,0x6f,0x67,0x20,0x70,0x6f,0x73,0x74,0x3a,0x20,0x68,0x74,
0x74,0x70,0x3a,0x2f,0x2f,0x62,0x6c,0x6f,0x67,0x2e,0x73,0x6c,0x61,0x73,0x68,0x70,
0x6f,0x75,0x6e,0x64,0x62,0x61,0x6e,0x67,0x2e,0x63,0x6f,0x6d,0x2f,0x70,0x6f,0x73,
0x74,0x2f,0x32,0x34,0x32,0x38,0x35,0x35,0x37,0x30,0x30,0x37,0x2f,0x75,0x6e,0x70,
0x61,0x63,0x6b,0x2d,0x61,0x6e,0x64,0x2d,0x62,0x65,0x61,0x75,0x74,0x69,0x66,0x79,
0x2d,0x6a,0x61,0x76,0x61,0x73,0x63,0x72,0x69,0x70,0x74,0x0a,0x0a,0x2f,0x2f,0x20,
0x41,0x73,0x73,0x75,0x6d,0x65,0x73,0x20,0x6a,0x73,0x5f,0x62,0x65,0x61,0x75,0x74,
@jpmckinney
jpmckinney / fix_invalid_json.py
Last active May 10, 2021
Fixes errors in invalid JSON. Running time is (length of input) x (number of errors).
View fix_invalid_json.py
#!/usr/bin/env python
import json
import sys
def run(filename):
with open(filename) as f:
s = f.read()
# This code will re-read the file from the beginning after fixing each error, which is slow. A better solution
@jpmckinney
jpmckinney / pelican_check_export.py
Last active Apr 26, 2021
Exports the descriptions of data quality checks from Pelican.
View pelican_check_export.py
# Generates:
# https://docs.google.com/document/d/1l5SL1hUR9n8IDYVLSYsU85hdB3L_u2e3iD-txQPc0zU/edit
# https://docs.google.com/spreadsheets/d/1WPPOSf7xM9LR3VlTGx7wyzc8q_5xQ3HyMoB8eaEWHDM/edit#gid=0
# Gist: https://gist.github.com/jpmckinney/f3bdbb62620a9974ba1ff254392f6b6d
# GitHub: https://github.com/open-contracting/pelican/issues/63
# CRM: https://crm.open-contracting.org/issues/5908
import csv
import json
View convert_recommonmark_to_myst.py
import json
import os
import re
import sys
from textwrap import dedent
tables_replacements = {
'```eval_rst': '',
'```': '',
}
@jpmckinney
jpmckinney / proxy.php
Created Mar 19, 2012 — forked from evolvingweb/proxy.php
An AJAX-Solr proxy written in PHP.
View proxy.php
<?php
/**
* @file
* Implements a Solr proxy.
*
* Currently requires json_decode which is bundled with PHP >= 5.2.0.
*
* You must download the SolrPhpClient and store it in the same directory as this file.
*
@jpmckinney
jpmckinney / .block
Last active Jun 29, 2020
WeWork Place Ville-Marie Mac OS X Printing Instructions
View .block
license: cc-by-4.0
@jpmckinney
jpmckinney / README.md
Last active Nov 30, 2019
Compare differences after making changes to Sphinx
View README.md

Written as part of open-contracting/standard_profile_template#33

curl -O https://gist.githubusercontent.com/jpmckinney/ba38d531e245c175e254ea3bc4218001/raw/bbb015f613ba936b3b42f25c576e833d196e5181/diff-reduce.py
python diff-reduce.py
diff -rq build t | grep Only | sort
diff -ru -x '*.js' -x '.buildinfo' -x '_sources' build t | less