Skip to content

Instantly share code, notes, and snippets.

Peter Robinett pr1001

Block or report user

Report or block pr1001

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
pr1001 / objc.h
Last active Feb 26, 2016
Objective C Property and Protocol Problems in Swift
View objc.h
@protocol MyProtocol
- (void)myValue;
@interface MyClass
@property myValue;
pr1001 /
Created Feb 5, 2015
Programmatically calling segues without implementing `prepareForSegue:sender:`


This is a category which adds methods on UIViewController to provide a handler at the spot that you programmatically perform a segue. This avoids a mess of if, else if, else statements in prepareForSegue:sender:. In fact, you don't even need to implement the method at all if you don't need do anything before the segues called from actions in your storyboard.


NSNumber *blogPostID = @1;
[self performSegueWithIdentifier:@"BlogPost" handler:^(BlogPostVC *blogPostVC) {
    blogPostVC.blogPostID = blogPostID;
pr1001 / composer.json
Created Feb 22, 2012
Composer autoloading issue
View composer.json
"name": "bubblefoundry/Request",
"type": "library",
"description": "Request is a simple webapp framework that focusing on routing HTTP requests and returing responses.",
"keywords": ["http", "request", "response", "route"],
"authors": [{
"name": "Peter Robinett",
"email": "",
"homepage": ""
pr1001 / gist:1664232
Created Jan 23, 2012
How to get Enumeration values back when using Scala parser combinators.
View gist:1664232
// ISO 3166-1 alpha-2 two letter country codes from
object Country extends Enumeration {
val Andorra = Value("ad") // Andorra
val UAE = Value("ae") // United Arab Emirates
val Afghanistan = Value("af") // Afghanistan
// ...
trait CountryParser extends JavaTokenParsers {
// would love to get rid of the silly regex
pr1001 /
Created Nov 20, 2011
Immutable Javascript object properties

Wish you had some immutability in Javascript? Now you can!

var t = {a: 1, b: 2}.immutable();
console.log(t.a, t.b);
try {
  t.a = 3; // ->  Uncaught Error: a is immutable and cannot be modified.
} catch (e) {
var t2 = t.copy({a: 3});
pr1001 / Nat.scala
Created Nov 14, 2011
Some experiments with natural numbers in Scala _without_ type class wizardry. As long at you use Nat() you are guaranteed a non-negative natural number.
View Nat.scala
object Nat {
object Zero extends Nat(0)
class Nat(val number: Int) {
def to(n: Nat): Option[IndexedSeq[Nat]] = if(number <= n.number) Some((number to n.number).flatMap(apply(_))) else None
def +(n: Nat): Nat = new Nat(number + n.number)
def +(n: Int): Option[Nat] = this.+(apply(n))
def +(n: Option[Nat]): Option[Nat] = + _)
pr1001 / Conditional.scala
Created Nov 12, 2011
Ruby-style trailing conditionals in Scala
View Conditional.scala
class Conditional[T](left: => T) {
def iff(right: => Boolean): Option[T] = if (right) Some(left) else None
def unless(right: => Boolean): Option[T] = if (!right) Some(left) else None
implicit def any2Unless[T](left: => T) = new Conditional(left)
pr1001 / gist:1351495
Created Nov 9, 2011
I need to tell the Dutch government how often I'm out of the country when I renew my permit. Luckily ScalaTime makes that easy to calculate.
View gist:1351495
import org.joda.time._
import org.scala_tools.time.Imports._
// do +1 day to be inclusive on start and end days
val intervals = List (
// One Day
new DateMidnight(2011, 1, 19) to (new DateMidnight(2011, 1, 19) +,
// Several Days
new DateMidnight(2011, 2, 5) to (new DateMidnight(2011, 2, 13) +
View gist:1331842
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:e="">
<info organisation="com.miogiro" module="util_2.9.1" revision="0.1" status="release" publication="20111101213155">
<conf name="compile" visibility="public" description=""/>
<conf name="runtime" visibility="public" description="" extends="compile"/>
View gist:1331815
name := "util"
organization := "com.miogiro"
version := "0.1"
scalaVersion := "2.9.1"
crossScalaVersions := Seq("2.8.1", "2.9.1")
You can’t perform that action at this time.