Skip to content

Instantly share code, notes, and snippets.

Avatar
🐦
tsers

Matti Lankinen milankinen

🐦
tsers
  • Finland
View GitHub Profile
View aspect_example.coffee
class MyClass
foo: ->
alert "foobar"
bar: ->
alert "barfoo"
@foo()
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 = {
_MultiModuleResourceMapper.enable()
}
View validation-improvements.coffee
# PART 1: tweak backbone validation a little bit
# ===============================================
# first, allow errorous inputs to update our model
Backbone.Validation.configure
forceUpdate: true
# then disable default callbacks for backbone validation events
_.extend Backbone.Validation.callbacks,
valid: (view, attr, selector) ->
View view-improvements.coffee
# 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)
View example-usage.coffee
jQuery ->
# Simple person model with two attributes
class Person extends Backbone.Model
validation:
age:
required: true
min: 10
name:
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>
<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>
</div>
@milankinen
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
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 = ord.compare(value, that.value)
}
case class DescendingOrder[T](value: T)(implicit ord: Ordering[T]) extends Ordered[DescendingOrder[T]] {
def compare(that: DescendingOrder[T]): Int = -ord.compare(value, that.value)
}
def asc[T](value: T)(implicit ord: Ordering[T]) = AscendingOrder(value)
You can’t perform that action at this time.