Skip to content

Instantly share code, notes, and snippets.


Matti Lankinen milankinen

  • Finland
Block or report user

Report or block milankinen

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
class MyClass
foo: ->
alert "foobar"
bar: ->
alert "barfoo"
View gist:4261912
class MyClass
simple: ->
alert "hello!"
another: ->
alert "hi!"
withParams: (a, b) ->
alert a + " - " + b
withReturnValue: (a) ->
return 2 * a
View _MultiModuleResourceMapper.groovy
package com.tunkkaus
import org.grails.plugin.resource.ResourceMeta
import org.grails.plugin.resource.ResourceProcessor
import org.grails.plugin.resource.mapper.MapperPhase;
import org.grails.plugin.resource.module.ModuleBuilder
import org.springframework.util.AntPathMatcher
* We are using prefix '_' because we want that this resource mapper
View resources.groovy
import com.tunkkaus._MultiModuleResourceMapper
beans = {
# PART 1: tweak backbone validation a little bit
# ===============================================
# first, allow errorous inputs to update our model
forceUpdate: true
# then disable default callbacks for backbone validation events
_.extend Backbone.Validation.callbacks,
valid: (view, attr, selector) ->
# PART 2: bind our backbone view to validation events and also for
# input changes so that model changes automatically when input changes
# =======================================================================
# This defines which element's attribute will be used for linking
inputSelector = 'name'
# model update function, which is called when input changes
updateModel = (model, attr, value) ->
model.set(attr, value || null)
jQuery ->
# Simple person model with two attributes
class Person extends Backbone.Model
required: true
min: 10
required: true
msg: "All persons have a name..."
View example-layoyt.html
<script type="text/x-template" id="person-form-template">
<div class="form-horizontal">
<div class="control-group">
<label class="control-label" for="name">Name</label>
<div class="controls"><input class="input" type="text" name="name" id="name" value="{{name}}" /></div>
<div class="control-group">
<label class="control-label" for="age">Age</label>
<div class="controls"><input class="input" type="number" name="age" id="age" value="{{age}}" /></div>
milankinen / OrderingDSLExample.scala
Last active Dec 26, 2015
Scala ordering DSL example
View OrderingDSLExample.scala
object OrderingDSLExample extends App {
case class My(num: Int, str: String)
val myValues = List(My(3, "foo"), My(3, "bar"), My(5, "bar"), My(5, "foo"))
import OrderingDSL._
require(myValues.sortBy(m => (asc(m.num), asc(m.str))) ==
List(My(3, "bar"), My(3, "foo"), My(5, "bar"), My(5, "foo")))
require(myValues.sortBy(m => (asc(m.num), desc(m.str))) ==
List(My(3, "foo"), My(3, "bar"), My(5, "foo"), My(5, "bar")))
milankinen / OrderingDSL.scala
Last active Dec 26, 2015
Scala ordering DSL
View OrderingDSL.scala
object OrderingDSL {
case class AscendingOrder[T](value: T)(implicit ord: Ordering[T]) extends Ordered[AscendingOrder[T]] {
def compare(that: AscendingOrder[T]): Int =, that.value)
case class DescendingOrder[T](value: T)(implicit ord: Ordering[T]) extends Ordered[DescendingOrder[T]] {
def compare(that: DescendingOrder[T]): Int =, that.value)
def asc[T](value: T)(implicit ord: Ordering[T]) = AscendingOrder(value)
You can’t perform that action at this time.