Skip to content

Instantly share code, notes, and snippets.

@retronym
retronym / type-bounds.scala
Created December 16, 2009 11:17
Tour of Scala Type Bounds
class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
@defunkt
defunkt / clients.md
Created April 18, 2010 14:09
A list of Gist clients.

Gist Clients

Want to create a Gist from your editor, the command line, or the Services menu? Here's how.

Editor Support

@retronym
retronym / mvn2sbt.scala
Created May 3, 2010 17:17
mvn2sbt: quick hack to turn <dependencies> into SBT
object scala {
val version = "SCALA_VERSION$"
}
val xml = <dependencies>
<dependency>
<groupId>org.scalanlp</groupId>
<artifactId>scalala_${scala.version}</artifactId>
<version>0.3.1</version>
</dependency>
@bmeck
bmeck / paste.cc
Created October 21, 2010 20:33
should print out simple clipboard
// CODE
/* test.cc
* Compile with: g++ `pkg-config --cflags --libs x11` test.cc -o test
* Run with: ./test
*/
#include <stdio.h>//printf
#include <string.h>//strlen
#include <stdlib.h>//atexit
@take-cheeze
take-cheeze / font_path_list.cxx
Created December 3, 2010 15:27
Get Font Path with X11
// g++ font_path_list.cxx $(pkg-config x11 --libs --cflags)
#include <X11/Xlib.h>
#include <cassert>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <iterator>
@border
border / Makefile
Created January 12, 2011 01:36
json example in golang
include $(GOROOT)/src/Make.inc
GOFMT=gofmt -spaces=true -tabindent=false -tabwidth=4
all:
$(GC) jsontest.go
$(LD) -o jsontest.out jsontest.$O
format:
$(GOFMT) -w jsontest.go
@viktorklang
viktorklang / ScalaEnum.scala
Created June 30, 2011 23:12
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
@jamalsa
jamalsa / quran.scala
Created July 4, 2011 06:10
This is scala code to process quran text from Tanzil. This code show how easy to process xml file with scala library.
import scala.xml._
class Aya(source: NodeSeq) {
val text = (source \ "@text").text
}
class Bismillah(source: NodeSeq) extends Aya(source: NodeSeq) {
override val text = (source \ "@bismillah").text
}
@pazdera
pazdera / builder.cpp
Created August 2, 2011 20:33
Example of `builder' design pattern in C++
/*
* Example of `builder' design pattern.
* Copyright (C) 2011 Radek Pazdera
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@pazdera
pazdera / prototype.cpp
Created August 3, 2011 10:36
Example of `prototype' design pattern in C++
/*
* Example of `prototype' design pattern.
* Copyright (C) 2011 Radek Pazdera
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,