Skip to content

Instantly share code, notes, and snippets.

@berngp
berngp / Fib.scala
Last active August 29, 2015 14:01
Fibonacci
def fib: Stream[Long] = {
def tail(h: Long, n: Long): Stream[Long] = h #:: tail(n, h + n)
tail(0, 1)
}
@berngp
berngp / example.sh
Last active August 29, 2015 14:01
ZSH Function Wrappers for JDK and SCALA HOME setup.
with-scala210 with-jdk7 ./make-distribution.sh --hadoop=2.4.0 --tgz --name=mesos-hadoop-2.4.0
@berngp
berngp / cleanApp.groovy
Created March 11, 2011 07:11
Grails cleanApp scripts, removes what Clean would except the plugins at ~/.grails/<version>/projects/<your project>
/*
* Copyright 2004-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@berngp
berngp / ThrowableXMLMarshaller.groovy
Created April 13, 2011 19:26
ThrowableXMLMarshallerSpec.groovy
package org.osscripters.grails.common.web.converters.marshaller
import grails.converters.XML
import org.codehaus.groovy.grails.web.converters.exceptions.ConverterException
import org.codehaus.groovy.grails.web.converters.marshaller.NameAwareMarshaller
import org.gcontracts.annotations.Requires
/**
* User: berngp
* Date: 4/12/11
@berngp
berngp / SomeLegacyStatus.groovy
Created April 19, 2011 19:27
Trying to simplify access to a legacy Lookup Table
package org.some.package
class SomeLegacyStatus {
enum Status {
NONE,
ACTIVE,
PENDING,
SUSPENDED,
BANNED,
@berngp
berngp / setup.groovy
Created April 22, 2011 01:33
Missing renderer for Unit Testing within Grails
controller.metaClass.render = {Map map, Closure closure ->
renderArgs.putAll(map)
switch(map.contentType) {
case null:
break
case 'application/xml':
case 'text/xml':
def smb = new StreamingMarkupBuilder()
if (map.encoding){
@berngp
berngp / grails-app.conf.JMSSpringBeans.groovy
Created May 3, 2011 19:19
Splitting SpringBeans files in Grails (Examples with JMS and JMX Bean files)
//grails-app/conf/JMSSpringBeans.groovy
import grails.util.Environment
import org.apache.activemq.spring.ActiveMQConnectionFactory
import org.springframework.jms.connection.SingleConnectionFactory
import grails.util.Environment
import org.apache.activemq.spring.ActiveMQConnectionFactory
import org.springframework.jms.connection.SingleConnectionFactory
beans {
0. Sudo
1. Setup your Clojure distributions, including clojure-contrib
e.g.
root@bowman-europa:/usr/local/clojure# ll
total 8
drwxr-xr-x 8 root root 4096 2011-07-14 19:32 clojure-1.2.1
drwxr-xr-x 6 root root 4096 2010-08-19 11:02 clojure-contrib-1.2.0
lrwxrwxrwx 1 root root 13 2011-07-14 19:37 current -> clojure-1.2.1
lrwxrwxrwx 1 root root 21 2011-07-14 20:50 current-contrib -> clojure-contrib-1.2.0
@berngp
berngp / gist:1358895
Created November 11, 2011 19:06
Lift RestHelper and the SI-1133
/**
* Fails with https://issues.scala-lang.org/browse/SI-1133
* Workaround: Split the <i>cases</i> inside <i>serve</i> into two or more
* <i>serve</i> blocks.
*
* Note: To avoid noise all cases bellow are returning a NotFoundResponse().
*/
object CategoryAdminResource extends RestHelper with Loggable {
@berngp
berngp / Measurable.scala
Created January 4, 2012 01:32
Trait with NewRelic and Scala Metrics.
import com.newrelic.api.agent.NewRelic
import collection.mutable.{HashMap, SynchronizedMap}
import com.yammer.metrics.{Timer, MetricsGroup}
trait Measurable {
protected lazy val metricsGroup = new MetricsGroup(this.getClass)
private val timers = new HashMap[String, Timer] with SynchronizedMap[String, Timer]