Skip to content

Instantly share code, notes, and snippets.

@olasitarska
olasitarska / pgessays.py
Created November 18, 2012 10:11
Builds epub book out of Paul Graham's essays.
# -*- coding: utf-8 -*-
"""
Builds epub book out of Paul Graham's essays: http://paulgraham.com/articles.html
Author: Ola Sitarska <[email protected]>
Copyright: Licensed under the GPL-3 (http://www.gnu.org/licenses/gpl-3.0.html)
This script requires python-epub-library: http://code.google.com/p/python-epub-builder/
"""
@stew
stew / fizzbuzz.scala
Created November 14, 2012 20:55
fizzbuzz in the scala type system
package fizzbuzz
// This is church encoding of natural numbers
sealed trait Num {
def toInt : Int
override def toString = toInt.toString
}
final case object Z extends Num {
def toInt : Int = 0
@tixxit
tixxit / fizzbuzz.scala
Created November 14, 2012 16:04
Compile time FizzBuzz in Scala.
package net.tixxit
import shapeless._
import Nat._
final class Fizz
final class Buzz
trait FizzBuzzAux[A <: Nat, B <: HList] {
def apply(): List[String]
C:\Users\brianf>curl -I --insecure "https://repository.apache.org/service/local/
artifact/maven/redirect?r=snapshots&g=org.apache.maven&a=maven-core&v=3.1-SNAPSH
OT&e=jar"
HTTP/1.1 301 Moved Permanently
Date: Tue, 06 Nov 2012 17:19:19 GMT
Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V4
Content-Type: application/xml; charset=ISO-8859-1
Location: https://repository.apache.org/service/local/repositories/snapshots/con
tent/org/apache/maven/maven-core/3.1-SNAPSHOT/maven-core-3.1-20121105.160646-45.
jar
@tonymorris
tonymorris / Balance.scala
Created September 23, 2012 01:43
Balance Parentheses
// Missing support libraries
object MissingLibraries {
case class State[S, +A](run: S => (A, S)) {
def map[B](f: A => B): State[S, B] =
State(s => {
val (a, t) = run(s)
(f(a), t)
})
def flatMap[B](f: A => State[S, B]): State[S, B] =
@gclaramunt
gclaramunt / Ids.scala
Created September 9, 2012 03:05
Tagged Ids using Phantom types
trait Entity
trait User extends Entity
trait Product extends Entity
case class Id[T<:Entity](id:String)
def buy(pId:Id[Product],uId:Id[User])="Bought product %s for user %s".format(pId.id,uId.id)
val pId=new Id[Product]("1")
@eed3si9n
eed3si9n / kind.scala
Created September 3, 2012 16:40
calculates a type's kind
// requires Scala 2.10.0-M7
def kind[A: scala.reflect.TypeTag]: String = {
import scala.reflect.runtime.universe._
def typeKind(sig: Type): String = sig match {
case PolyType(params, resultType) =>
(params map { p =>
typeKind(p.typeSignature) match {
case "*" => "*"
case s => "(" + s + ")"
}
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@lenary
lenary / heroku_pg_backup.sh
Created August 4, 2012 10:00
Auto-migrator for heroku databases
# ALL destructive actions still need to be confirmed manually by the user.
# It's also worth pointing out that in special cases, things may not work.
# Most of this info is gleaned from https://devcenter.heroku.com/articles/migrating-from-shared-database-to-heroku-postgres
set -e
APP=$1
echo "APP = $APP"
heroku addons:add heroku-postgresql:dev -a $APP
@olamy
olamy / gist:3052495
Created July 5, 2012 09:08
maven-3 git svn init
cd .git;wget http://git.apache.org/authors.txt; cd ..
git config svn.authorsfile ".git/authors.txt"
git svn init --prefix=origin/ --tags=tags --trunk=trunk --branches=branches https://svn.apache.org/repos/asf/maven/maven-3
git svn rebase