Skip to content

Instantly share code, notes, and snippets.

View devth's full-sized avatar
Deep Work

Trevor Hartman devth

Deep Work
View GitHub Profile
@devth
devth / dominos.html
Created March 20, 2012 03:58 — forked from jacktandrew/gist:2131145
Create Dominoes
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<style>
div.tile {height: 70px; width: 35px; border-radius: 7px; float: left; margin: 10px;}
div.tile, div.bar {border: 2px outset #444;}
div.pips {height: 30px; width: 35px;position: relative; margin-top: 2px;}
div.pips div {border-radius: 5px; height: 4px; width: 5px; background: #333; position: absolute; border:2px inset #444;}
@devth
devth / previous.js
Created March 14, 2012 20:49
Backbone 0.9.0 "previous" weirdness if you override its "change"
var Foo = Backbone.Model.extend({
initialize: function() {
_.bindAll(this, 'change');
this.bind('change', this.change);
},
change: function() { console.log(this.previous('foo'), "to", this.get('foo')) }
});
var f = new Foo({foo: 1});
var View = Backbone.View.extend({ foo: function() { View.render(); }}, { render: function() { console.log("static render"); } })
new View().foo()
# Checkout first git revision before a given date
# Example usage: gcodate 2011-06-20
# Note that HEAD must be at a commit *after* the date you're targeting.
gcodate(){ git checkout "`git rev-list HEAD -n 1 --first-parent --before=$@`" && git show HEAD --stat }
// Build filtered, sorted map of compared ratings
val compared = ListMap(
productFeatureComparison.getProductComparedRatings.asScala.toMap
// Filter out products that have no offers
.filterNot { case (pid, _) => lowestOffer(products.get(pid)) == None}
// Sort by similarity descending
.sortBy{-_._2.getSimilarity}:_*)
// Use the first 10
.take(10)
object =^ { def ^= = "meow" }
// defined module $eq$up
=^.^=
// res10: java.lang.String = meow
@devth
devth / patternMatching.scala
Created February 15, 2012 19:24
A comparison of pattern matching and equivalent imperative solution
// groups only holds lists of "good" things and "bad" things
val groups = Map('good -> List("beer", "bikes"), 'bad -> List("flat tires"))
// But we're interested in both "good" things and "not too bad" things
val known = (groups.get('good), groups.get('notTooBad)) match {
case (Some(goodThings), Some(notTooBadThings)) => "i know about good and not-too-bad things"
case (Some(goodThings), None) => "i know about good things only"
case (_, None) => "i might know about good things but nothing else"
case _ => "i may or may not know anything"
}
def getRecommendedProducts = {
val featureRatings = productFeatureComparison.getFeatureRatings
val compared = productFeatureComparison.getProductComparedRatings
// Loop the products being compared
compared groupBy { case (pid, comparedRatings: ComparedRatings) =>
// Run a comparison on all of feature ratings against this compared product.
val groups = featureRatings groupBy { case (p) =>
val (key: String, fr: ProductFeatureComparison.FeatureRating) = (p.getKey, p.getValue)
[merge]
tool = opendiff
[core]
excludesfile = /Users/trevorhartman/.gitignore
editor = vim
[alias]
st = status -sb
ci = commit
co = checkout
br = branch
ns("decide").ApplicationModel = Backbone.Model.extend({
sync: function(method, model, options) {
// Our overriden sync supports these events:
// sync:start
// sync:success
// sync:error
// sync:complete
//
// Params dispatched with the event: