Skip to content

Instantly share code, notes, and snippets.

@oscarrenalias
oscarrenalias / git-colors.sh
Created August 24, 2012 18:22
Enabling git integration with Bash in OS X
git config --global color.branch auto
git config --global color.diff auto
git config --global color.status auto
@oscarrenalias
oscarrenalias / node-event-emitter.js
Created September 10, 2012 18:47
An example of an event emitter class in Node.js
var events = require('events'),
util = require('util');
EventGenerator = function() {
events.EventEmitter.call(this);
this.read = function() {
var data = "this is new data";
this.emit("data", data);
}
@oscarrenalias
oscarrenalias / configuration.scala
Created October 2, 2012 21:40
Type-safe configuration in Scala
trait Handler
class Handler1 extends Handler
class Handler2 extends Handler
trait HandlerConfiguration {
val handler1: Handler
val handler2: Handler
}
@oscarrenalias
oscarrenalias / type-bounds.scala
Created October 4, 2012 18:50 — forked from retronym/type-bounds.scala
Tour of Scala Type Bounds
class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
@oscarrenalias
oscarrenalias / framework.scala
Created October 5, 2012 20:20
This is small implementation of a tiny MVC-oriented framework inspired by the design * of the Play Framework 2.0; it is meant as an educational exercise to get more familiar with * the concepts of partial functions, function composition and generic type
/**
* This is small implementation of a tiny MVC-oriented framework inspired by the design
* of the Play Framework 2.0; it is meant as an educational exercise to get more familiar with
* the concepts of partial functions, function composition and generic types in Scala
*
* How to run:
* scalac framework.scala
* scala App
*/
@oscarrenalias
oscarrenalias / gist:3914875
Created October 18, 2012 21:35
Cheatsheet Play enumerators, enumeratees, iterators and iteratees
// --- cheat sheet ---
//
// Enumerator &> -> filters the output of the enumerator through an Enumeratee
// Enumerator >>> -> alias for andThen; adds the output of the second enumerator after the first one is done
// Enumerator |>> -> feeds the output of the enumerator into the given iteratee for processing
// --- end of cheat sheet ---
// Example
// Iteratee that sums up the size of the input:
@oscarrenalias
oscarrenalias / gist:4258354
Created December 11, 2012 12:57
Using Puppet to provision instances from EC2 and automatically install Puppet agent on them
#!/bin/sh
puppet node_aws bootstrap \
--debug \
--image ami-c1aaabb5 \
--keyname 'puppet_provisioner' \
--type 'm1.small' \
--region eu-west-1 \
--security-group puppet-clients \
--login ubuntu \
@oscarrenalias
oscarrenalias / colorize.rb
Created February 21, 2013 08:07
Easily colorize console output in Ruby:
class String
# colorization
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
colorize(31)
end
@oscarrenalias
oscarrenalias / ehcache.xml
Created March 1, 2013 08:28
A better ehcache.xml configuration file for the Play Framework, which out of the box limits the size of the cache based on the number of objects you put in it rather than the number of bytes. I personally think that's not a very smart choice. Also see http://ehcache.org/documentation/2.5/configuration/cache-size#cache-configuration-sizing-attrib…
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd" updateCheck="false">
<!-- This is a default configuration for 256Mb of cached data using the JVM's heap, but it must be adjusted
according to specific requirement and heap sizes -->
<defaultCache
maxBytesLocalHeap="256000000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
# Run this with jboss-cli to deplyo the given module:
module add --name=com.mydomain.placeholder --resources=placeholder\target\placeholder-6.6.6-SNAPSHOT.jar
/subsystem=ee:write-attribute(name="global-modules",value=[{"name" => "com.mydomain.placeholder","slot" => "main"}])