Skip to content

Instantly share code, notes, and snippets.

View clhodapp's full-sized avatar

Chris Hodapp clhodapp

  • San Francisco, California
View GitHub Profile
public Tableau makeArtificial() {
Matrix tmp = getA().mergeRight(Matrix.identity(constraints)).mergeRight(getRHS()); //insert identity
tmp = tmp.mergeDown(new Matrix(1,vars).extend(0,constraints,1d).extend(0,1)); //add new cost row
return new Tableau(tmp);
}
vs
public Tableau makeArtificial() {
Double[][] tmp = new Double[height][width+height-1];
@clhodapp
clhodapp / Ordering.scala
Created February 29, 2012 05:29
Ordering Example
case class A(x: Int)
implicit object AIsOrdered extends Ordering[A] {
def compare(x: A, y: A) = x.x - y.x
}
@clhodapp
clhodapp / Dynamic.scala
Created March 28, 2012 04:32
Dynamic example
object Dynamic {
class DynamicBox1(val value: Any) extends Dynamic {
override def applyDyamic[@specialized A](name: String, arg1: A): Dynamic = {
val method = value.getClass.getMethod(name, arg1.getClass)
boxDynamic(method.invoke(value, arg1.asInstanceOf[AnyRef]))
}
override def as[T] = value.asInstanceOf[T]
}
@clhodapp
clhodapp / scope-demo.scala
Created March 28, 2012 21:02
Implicit Scope
package P {
class A(val v: Int)
class B(val v: Int)
class C {
def getV(x: B) = x.v
}
}
package object P {
implicit def a2b(x: A) = new B(x.v)
@clhodapp
clhodapp / soc2012
Created April 6, 2012 09:10
SOC 2012 Proposal
Name: Christopher Hodapp
Institution: The University of Alabama
Program: Computer Science
Graduation: May 2012
Proposal Title: Dynamic Scala
Email: [email protected]
Phone: +19372199307
About me: I am a 4th (final) year undergraduate Computer Science
student at the University of Alabama. I plan to resume my studies at
@clhodapp
clhodapp / KeyValueParser.scala
Created June 5, 2012 14:59 — forked from chbaranowski/KeyValueParser.scala
Scala RegEx Parser Demo
import scala.util.parsing.combinator.RegexParsers
/**
* Simple parser for a key value string like:
* key01 = Value01 key02=value02 key03 =value03 key04= value04
*
* The parser does not support whitespace in key or values.
*/
object KeyValueParser extends RegexParsers {
@clhodapp
clhodapp / hw.cls
Last active December 11, 2015 20:28 — forked from jhwilson/jhwhw.cls
%=====================================================================
% hw.cls
% Provide hw.cls class
%=====================================================================
%=====================================================================
% Identification
%=====================================================================
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{hw}[2013/1/28 Based on Justin Wilson's Homework Class]
@clhodapp
clhodapp / Example.scala
Last active December 15, 2015 17:39
Most of the macros needed to create a single tuple class that could hold an arbitrary number of items and retain typesafety
// This is an example usage
object Test extends App {
import Macros._
println(countRefs[Int~Int~String~List[Int]~Double]) // prints 2
println(countInts[Int~Int~String~List[Int]~Double]) // prints 2
println(countDoubles[Int~Int~String~List[Int]~Double]) // prints 1
println(whichArray[Int~Int~String~List[Int]~Double]("_0")) // prints Ints
println(whichArray[Int~Int~String~List[Int]~Double]("_2")) // prints References
package tuple
import language.experimental.macros
import language.dynamics
import scala.reflect.macros.Context
sealed trait ~[+A, +B]
private[tuple] object TupleMacros {
@clhodapp
clhodapp / slick-issue-186
Created July 30, 2013 10:57
Log from issue 186
[info] Loading project definition from /Users/clhodapp/gsoc/git/slick/project
[info] Set current project to root (in build file:/Users/clhodapp/gsoc/git/slick/)
[info] Test run started
[info] Test scala.slick.test.memory.DistributedQueryingTest.test1 started
[info] Test run finished: 0 failed, 0 ignored, 1 total, 2.836s
[info] Test run started
[Using test database jdbc:h2:mem:test1]
[info] Test scala.slick.test.jdbc.StatementParametersTest.testExplicit[0] started
[Using test database jdbc:h2:mem:test1]
[info] Test scala.slick.test.jdbc.StatementParametersTest.testImplicit[0] started