Skip to content

Instantly share code, notes, and snippets.

@williamho
williamho / textarea.js
Last active August 29, 2015 14:24
Replaces window with textarea. Useful as a bookmarklet.
(function(d) {
d.open();
d.write('<textarea id="input" spellcheck="false" style="flex:1;height:100%;resize:none;outline:none;font:15px monospace;color:#fff;background:#111;padding:10px;"><html>\n<head></head>\n<body>\nClick here to render\n</body>\n</html></textarea>');
d.write('<iframe id="iframe" style="flex:1;height:100%;"></iframe>');
d.close();
var s = d.body.style;
s.display = 'flex';
s.margin = 0;
var i = d.getElementById('input');
@williamho
williamho / .vimiumrc
Created September 13, 2015 02:59
vimium mappings
map <c-u> scrollPageUp
map <c-d> scrollPageDown
unmap u
unmap d
unmap r
unmap p
unmap P
unmap t
unmap x
@williamho
williamho / README.md
Last active October 23, 2015 17:15
work pipeline statsd

Work pipeline dashboard example

work-pipeline-grafana.json:

  • example grafana dashboard json (assumes the metrics will be prefixed in the format someNamespace.somePipelineName)

WorkPipelineSample.scala

  • scala example code for using the workpipeline and generating some metrics

you can use this to set up grafana/graphite/statsd locally: https://github.com/kamon-io/docker-grafana-graphite

@williamho
williamho / mapValues.scala
Created November 5, 2015 17:01
mapValues doesn't map the values until the object is evaluated
// See https://issues.scala-lang.org/browse/SI-7005
scala> val m = Map(1 -> 2, 3 -> 4)
m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 3 -> 4)
scala> val m1 = m.mapValues { x => println("mapValues is being evaluated"); x + 2 }
mapValues is being evaluated
mapValues is being evaluated
m1: scala.collection.immutable.Map[Int,Int] = Map(1 -> 4, 3 -> 6)
@williamho
williamho / FicusSpec.scala
Last active November 5, 2015 18:22
ficus
import org.specs2.mutable._
import com.typesafe.config._
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
class HelloSpec extends Specification {
case class MyConfig(
key1: String,
key2: String,
@williamho
williamho / index.js
Last active November 17, 2015 18:27
db-ip to mongoimport
// From a db-ip csv file, generate a mongoimport-compatible file, converting IPs to Longs.
// Ignores IPv6 because byte arrays are annoying to work with. Sorry.
// Usage: node index.js <input.csv >output.txt
var ipModule = require('ip')
, parse = require('csv-parse')
, transform = require('stream-transform')
;
var parser = parse({ columns: ['startIp', 'endIp', 'countryCode'] });
@williamho
williamho / index.js
Created November 17, 2015 20:34
convert marineregions geojson to mongodb 2.4 mongoimport compatible file
/*
Convert marineregions json (converted from shapefile) to mongodb 2.4 compatible format (for mongoimport)
Mongo 2.4 doesn't support `MultiPolygon` type, so split `MultiPolygon` into multiple individual `Polygon`s.
Also convert ISO alpha 3 to alpha 2.
Usage:
Convert the marineregions shapefile (EEZ_land_v2_201410.shp) to a geojson file:
ogr2ogr -f GeoJSON -t_srs crs:84 -clipsrc -180 -90 180 90 countries.geojson *.shp
(function() {
var d = document;
var img = d.createElement('img');
img.style.cssText = 'right:0; top:0; position:fixed;';
d.body.appendChild(img);
var elems = d.querySelectorAll('a[href^="./"]');
Array.prototype.forEach.call(elems, function(elem) {
elem.addEventListener('mouseover', function() {
# In Gemfile:
# gem 'google-api-client', '0.9.pre3'
require 'google/apis/customsearch_v1'
Customsearch = Google::Apis::CustomsearchV1
search = Customsearch::CustomsearchService.new
# https://cse.google.com/cse/all
# Click name of CSE to edit
@williamho
williamho / twitter.css
Created December 20, 2015 04:52
custom styles for twitter
li.js-moments-tab {
display: none;
}
ol.expanded-conversation div.AdaptiveMedia.is-square {
max-height: none !important;
overflow: auto;
}
ol.expanded-conversation div.AdaptiveMedia-singlePhoto img {