Skip to content

Instantly share code, notes, and snippets.

View iainmcgin's full-sized avatar

Iain McGinniss iainmcgin

  • San Francisco, CA
View GitHub Profile
@iainmcgin
iainmcgin / plus_one_rt.js
Created December 11, 2013 16:47
Example of using the W3C Resource Timing API to display the resource timing information of +1 buttons. This code can be pasted into the Javascript console in Chrome on any page.
(function() {
// request PerformanceResourceTiming info for all resources on the page
var resources = window.performance.getEntriesByType('resource');
// filter all resources to just +1 button iframes with timing information
var p1Resources = resources.filter(function(rtInfo) {
return rtInfo.name.indexOf('_/+1/fastbutton') != -1 &&
rtInfo.responseStart != 0;
});
@iainmcgin
iainmcgin / LazyViews.scala
Created February 18, 2013 20:47
Use of lazy views to prevent multiple transformations on a list.
val numbersAsStrings = Seq("1", "4", "5", "7", "8", "20", "10")
val ints = (numbersAsStrings.view map { _.toInt } filter {_ % 2 == 0}).force
@iainmcgin
iainmcgin / graphics.ml
Last active December 13, 2015 17:28
Stubbed version of the OCaml Graphics module, which is missing in the OSX HomeBrew version of OCaml 4.00.1
(***********************************************************************)
(* Graphics module stub *)
(***********************************************************************)
exception Graphic_failure of string
(* mutable state *)
let win_size = ref (0,0)
let current_pos = ref (0,0)
@iainmcgin
iainmcgin / Properties.scala
Created September 5, 2011 18:30
Style-sheet like properties
object UnitType extends Enumeration {
val Em = Value("em")
val Px = Value("px")
val Pc = Value("%")
}
import UnitType._
case class Dimension(
val length : Double = 0.0,
@iainmcgin
iainmcgin / JavaPuzzle2.java
Created August 26, 2011 16:50
Java Puzzle 2
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.System.*;
class Main {
public static void main(String[] args) {
List<Integer> list = asList(1, 2, 3, 4, 5, 6);
Stack<Integer> filtered = new Stack<Integer>();
Iterator<Integer> it = list.iterator();
@iainmcgin
iainmcgin / JavaPuzzle.java
Created August 26, 2011 16:31
Java Puzzle
class A {
public void x(byte b) { System.out.println("byte"); }
public void x(long l) { System.out.println("long"); }
}
class B extends A {
public void x(short s) { System.out.println("short"); }
public void x(int i) { System.out.println("int"); }
}
@iainmcgin
iainmcgin / plaid.JSON-tmLanguage
Created July 27, 2011 17:13
Sublime Text 2 syntax highlighter for Plaid language
{ "name": "Plaid",
"scopeName": "source.plaid",
"fileTypes": ["plaid"],
"patterns": [
{
"name": "keyword.source.plaid",
"match": "\\b(case|default|import|match|new|of|package|requires|state|override|with)\\b",
"comment": "keywords"
},
{
@iainmcgin
iainmcgin / GADT.scala
Created July 20, 2011 01:21
Simple evaluator in Scala
abstract class Term[A]
case class Val[A](v : A) extends Term[A]
case class Fn[A, B](f : A => B) extends Term[A => B]
case class Apply[A, B](fn : Term[A => B], input : Term[A]) extends Term[B]
def eval[A](input : Term[A]) : A = input match {
case Val(v) => v
case Fn(f) => f
case Apply(m,d) => eval(m)(eval(d))