Skip to content

Instantly share code, notes, and snippets.

@matthandlersux
matthandlersux / no column length update with #auto_upgrade!
Created January 12, 2011 21:08
you'll notice that on the call to the second DataMapper.auto_upgrade! there is no "ALTER TABLE" issued to extend the length of the field to varchar(255)
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite:./test.db')
class Post
include DataMapper::Resource
@matthandlersux
matthandlersux / gist:1017176
Created June 9, 2011 16:57
DataMapper gist showing failing query on many to many association
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
@matthandlersux
matthandlersux / dynamic.rb
Created June 14, 2011 06:51
confusing scope example in ruby
# 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
@matthandlersux
matthandlersux / gist:1479353
Created December 15, 2011 00:59
validation order
# 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
@matthandlersux
matthandlersux / tree.markdown
Created March 10, 2012 18:39 — forked from hrldcpr/tree.md
one-line tree datastructure in python

in python:

from pprint import pprint
from collections import defaultdict


# one-line definition of a tree:
def tree(): return defaultdict(tree)
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._
@matthandlersux
matthandlersux / scalatestquestion.scala
Created June 29, 2012 23:50
scala question about traits and parameter access
object Test {
var list = List()
}
abstract class Test(parameter:String) {
}
trait TestTrait {
var parameter:String
@matthandlersux
matthandlersux / unclean creator in companion.scala
Created July 6, 2012 02:01
any way to make this cleaner?
abstract class SuperClass {
var initialized = false
def initialize {
initialized = true
}
}
abstract trait SubclassCompanion {
def create:Any
@matthandlersux
matthandlersux / gist:3344752
Created August 13, 2012 23:18
type matching test
object Holder {
var companions = Set[AnyRef]()
def companionFor[M](m:M) = {
companions.find {
case found:M => true
case _ => false
}
}
}
@matthandlersux
matthandlersux / whywrong.scala
Created August 17, 2012 20:06
pulling out types?
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
}