Skip to content

Instantly share code, notes, and snippets.

Chris Lewis chrislewis

Block or report user

Report or block chrislewis

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
View gist:152965
import java.util.{Calendar, Date}
import Calendar._
class TimeIncrement(val increment: Int /* FIXME */, val amount: Int)
class IntDate(val number: Int) {
def days = new TimeIncrement(DATE, number)
}
View gist:168742
case class Employee(val dailyRate: Double) {
def getDailyRate = dailyRate
}
trait Calculator {
def calculate(dailyRate: Double, noOfDays: Int): Double
}
trait Calendar {
def noOfDays: Int
View gist:168743
import java.util.ArrayList;
import java.util.List;
class Employee {
private Double dailyRate;
public Employee(Double dailyRate) {
this.dailyRate = dailyRate;
}
View gist:180141
class User(val firstName: String, val lastName: String)
trait UserDao {
def findByFirstName(firstName: String): User
}
object defaultUserDao extends UserDao {
override def findByFirstName(firstName: String) = new User(firstName, "Lewis")
}
View gist:183168
var EventAttacher = Class.create({
events: "click,focus".split(","),
initialize: function(element, handler) {
this.element = $(element);
this.handler = handler;
this.events.each(this._buildObservationMethod.bind(this));
},
View gist:183209
Array.prototype.toList = function() {
var list = new Element("ul")
$A(this).each(function(e) { list.appendChild(new Element("li").update(e)) } )
return list
}
document.body.appendChild([1,2,3].toList())
View gist:186301
trait XmlRenderer {
val handlers = Map(
"span" -> ((n: Node) =>
<handled>
<div class="boink">
{n.label}
</div>
</handled>
)
)
View gist:190442
/*
* An object for building an object of handler methods, which can
* can then be added via Element.addMethods. Example result:
*
* {
* mousedown: function(element, fn) {
* element = $(element);
* element.observe("mousedown", fn.bind(element));
* return element;
* },
View gist:190475
/*
* Extension that makes it easy to convert an array to a "hash"
* (a bland JSON object), given an array of desired keys.
*/
Array.prototype.toObject = function(keys) {
var obj = {};
for(var i = 0; i < keys.length; i++) {
obj[keys[i]] = this[i];
}
return obj;
View gist:193789
/*
* Recursive xml transformation util. Provides a simplistic tool for
* registering transforms as functions, which will be called recursively
* on each node of the tree.
*/
import scala.xml._
trait XmlRenderer {
val handlers: Map[(Node) => Boolean, (Node) => Node]
You can’t perform that action at this time.