Skip to content

Instantly share code, notes, and snippets.

View gatspy's full-sized avatar

CG.gatspy gatspy

View GitHub Profile
@retronym
retronym / generalised-type-constraints.scala
Created November 8, 2009 08:02
Demo of generalised type constraints in Scala 2.8
// scala 2.7 simple type constraint. This can only constrain a type parameter of this function.
// Below, in ListW.sumint28, we can't use this approach because we want to constrain T,
// a type param of the enclosing trait.
def sumint27A[T <: Int](l: List[T]) : Int = l.reduceLeft((a: Int, b: Int) => a + b)
trait IntLike[X] extends (X => Int)
object IntLike {
implicit val intIntLike: IntLike[Int] = new IntLike[Int] { def apply(x: Int) = identity(x) }
}
// Literals
val dogs = List("Barnie", "Princess", "Mungo")
val empty = List()
// * Parameterised Types - you can't have an unparameterised List type
val noStrings = List[String]()
// Immutable (by default)
// * The default type of List is immutable. (the mutable List type must be imported specifically)
@cowboy
cowboy / HEY-YOU.md
Last active February 27, 2025 12:24
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@jagregory
jagregory / gist:710671
Created November 22, 2010 21:01
How to move to a fork after cloning
So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!
Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.
* Off the top of my head *
1. Fork their repo on Github
2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it
git remote add my-fork [email protected]
@jehiah
jehiah / simple_args_parsing.sh
Created March 4, 2011 16:56
a simple way to parse shell script arguments
#!/bin/sh
#
# a simple way to parse shell script arguments
#
# please edit and use to your hearts content
#
ENVIRONMENT="dev"
@jboner
jboner / SBT.sublime-build
Created May 6, 2011 09:47
Sublime Editor SBT build setup
{
"cmd": ["sbt-no-color compile"],
"file_regex": "^\\[error\\] ([.a-zA-Z0-9/-]+[.]scala):([0-9]+):",
"selector": "source.scala",
"working_dir": "${project_path:${folder}}",
"shell": "true"
}
@itang
itang / sbt.sublime-build
Created July 6, 2011 08:53
sbt build script for sublime text editor [windows]
{
"cmd": ["xsbt compile"],
"file_regex": "^\\[error\\] ([.a-zA-Z0-9/-]+[.]scala):([0-9]+):",
"selector": "source.scala",
"working_dir": "${project_path:${folder}}",
"shell": "true",
"encoding": "GBK"
}
@kylelemons
kylelemons / enum.go
Created September 8, 2011 18:49
Enum types (bitshifted too)
package main
import (
"fmt"
"strings"
)
type foo int
const (
One foo = iota
@notyy
notyy / gist:2093930
Created March 19, 2012 03:54
monad
class Monadic[A, B](val f1: (A => Option[B])) {
def then[C]: (B => Option[C]) => (A => Option[C]) = thenDo(f1) _
def thenDo[A, B, C](fa2ob: (A => Option[B]))(fb2oc: (B => Option[C])): (A => Option[C]) = { a =>
fa2ob(a) match {
case None => None
case Some(b) => fb2oc(b)
}
}
@datagrok
datagrok / gist:2199506
Last active December 16, 2024 16:14
Virtualenv's `bin/activate` is Doing It Wrong