from pprint import pprint
from collections import defaultdict
# one-line definition of a tree:
def tree(): return defaultdict(tree)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'dm-core' | |
require 'dm-migrations' | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, 'sqlite:./test.db') | |
class Post | |
include DataMapper::Resource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'datamapper' | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'sqlite3::memory:') | |
class Item | |
include DataMapper::Resource | |
property :id, Serial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is the usage that confused me: | |
# it's a different situation than in your example. i had heard someone mention | |
# that this worked due to dynamic scoping, but after looking into it, it's actually achieved | |
# with reflection. glad we figured this out. hifive! o/ \o | |
require 'sinatra' | |
helpers do | |
def login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# works: | |
with_options :if => Proc.new {|r| !r.session_based? } do |o| | |
o.validates_presence_of :event_date, :giver, :title | |
end | |
with_options :if => Proc.new {|r| !r.session_based? && !r.event_date.nil? } do |o| | |
o.validate :money_due_date_before_event_date | |
o.validate :gift_votes_date_if_no_idea_selected | |
o.validate :gift_votes_date_before_other_dates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aaop.humanfacebigdata.controllers | |
import org.bowlerframework.controller.{Controller,FunctionNameConventionRoutes} | |
import org.bowlerframework.model.{ ParameterMapper, Validations} | |
import org.bowlerframework.view.{Renderable} | |
import org.bowlerframework.model.Validations | |
import org.bowlerframework.view.{Renderable, ViewPath} | |
import org.bowlerframework.view.scalate.DefaultLayout | |
import org.bowlerframework._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Test { | |
var list = List() | |
} | |
abstract class Test(parameter:String) { | |
} | |
trait TestTrait { | |
var parameter:String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class SuperClass { | |
var initialized = false | |
def initialize { | |
initialized = true | |
} | |
} | |
abstract trait SubclassCompanion { | |
def create:Any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Holder { | |
var companions = Set[AnyRef]() | |
def companionFor[M](m:M) = { | |
companions.find { | |
case found:M => true | |
case _ => false | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test { | |
def pullOutType[V](f:Map[String, V] => Unit) { | |
var map = Map[String, V]() | |
val params = Map("string" -> "string", "int" -> 20, "list" -> List("ok", "then")) | |
params.foreach { | |
case (field, value) => value match { | |
case v:V => map = map + (field -> v) | |
case _ => null | |
} |
OlderNewer