Skip to content

Instantly share code, notes, and snippets.

View fedesilva's full-sized avatar
👁️‍🗨️

federico silva fedesilva

👁️‍🗨️
View GitHub Profile
# backports_apt_package.rb
#
# Resource and provider to correctly install packages from Debian's
# backports, which are a non-default apt source. Creates
# backports_apt_package resource which does the Right Thing.
#
# Drop this file into cookbook's libraries/ dir.
require 'chef/provider/package/apt'
require 'chef/resource/package'
@fedesilva
fedesilva / mapreduce.py
Created April 24, 2011 01:03 — forked from laclefyoshi/mapreduce.py
MapReduce with Akka/Actor and Jython
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2011/03/04
from akka.actor import Actors, UntypedActor
# from akka.dispatch import Futures
import collections
@fedesilva
fedesilva / xvfb_daemon.sh
Created May 5, 2011 20:40 — forked from tommeier/xvfb_daemon.sh
Xvfb startup init script for headless selenium started via Jenkins
#!/bin/bash
# /etc/init.d/xvfb_daemon
# Xvfb startup script.
# Tom Meier <[email protected]>
#
### BEGIN INIT INFO
# Provides: xvfb
# Short-Description: Start/stop/restart daemon
# Description: Controls the Xvfb daemon which starts/stops the X Virtual Framebuffer server
### END INIT INFO
##
# Rack configuration for use with Phusion Passenger.
#
# Updated with Blake's suggestions from: http://gist.github.com/98711
log = File.new('log/sinatra.log', 'a')
$stdout.reopen(log)
$stderr.reopen(log)
require 'YOUR_APPLICATION'
@fedesilva
fedesilva / irb
Created May 13, 2011 01:26 — forked from quirkey/irb
[08:48 AM:gist-99771(master)] $ irb -rubygems -r myapp.rb -r rack/test
>> app = Rack::Test::Session.new(Sinatra::Application)
=> #<Rack::Test::Session:0x17e8820 @headers={}, @app=Sinatra::Application>
>> app.get '/'
=> #<Rack::Response:0x17ad4dc @block=nil, @writer=#<Proc:0x0189f7b4@/opt/local/lib/ruby/gems/1.8/gems/rack-0.9.1/lib/rack/response.rb:24>, header{"Content-Type"=>"text/html", "Content-Length"=>"7"}, body["testing"], length7, status200
>> app.body
NoMethodError: undefined method `body' for #<Rack::Test::Session:0x17e8820>
from (irb):3
@fedesilva
fedesilva / arguments.scala
Created May 24, 2011 00:50
A very naive but cool arguments parser.
class Arguments(val rawArgs:Array[String], val flagNames:Seq[String] = Seq()) {
import Arguments._
val flags:Seq[Argument] =
rawArgs.intersect(flagNames).toList.map{ s => Flag(s) }
val values:Seq[Argument] =
rawArgs.diff(flags).grouped(2).toList.collect{ case Array(n,v) => Value(n,v)}
@fedesilva
fedesilva / 3nightclubs.scala
Created June 17, 2011 15:52 — forked from oxbowlakes/3nightclubs.scala
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.8.x and scalaz 5.0)
*/
import scalaz._
import Scalaz._
@fedesilva
fedesilva / SAfeUnsafeWithEither.scala
Created August 15, 2011 17:07
Scala Option *will* save you from NullPointerException
class SafeUnsafe {
def unsafe[T](x: =>T):Option[T]=
try {
Option(x)
} catch {
case _ => None
}
@fedesilva
fedesilva / LensTest.scala
Created November 9, 2011 23:00 — forked from wrwills/LensTest.scala
playing with some of the ideas from the Haskell fclabels library using the new Lens functionality in scalaz
import scalaz._
/**
* playing with some of the ideas from the Haskell fclabels library
* using the new Lens functionality in scalaz
*
* http://hackage.haskell.org/package/fclabels
*/
object LensTest {
@fedesilva
fedesilva / service
Created December 19, 2011 21:39 — forked from brentkirby/service
Unicorn + Runit + RVM
#!/bin/bash -e
#
# Since unicorn creates a new pid on restart/reload, it needs a little extra love to
# manage with runit. Instead of managing unicorn directly, we simply trap signal calls
# to the service and redirect them to unicorn directly.
#
# To make this work properly with RVM, you should create a wrapper for the app's gemset unicorn.
#
function is_unicorn_alive {