Skip to content

Instantly share code, notes, and snippets.

View avalade's full-sized avatar
🌴
On vacation

Aaron D. Valade avalade

🌴
On vacation
View GitHub Profile
@croaky
croaky / paginate_shoulda_macro.rb
Created February 23, 2009 16:15
Testing will_paginate with custom Shoulda macros. Depends on Mocha.
class Test::Unit::TestCase
def paginate(collection)
WillPaginate::Collection.create(1, 10) do |pager|
pager.replace(collection)
pager.total_entries = 25
end
end
# Example:
#
### Cookbook Name:: haproxy
### Recipe:: default
### Author:: Joe Williams <joe@joetify.com>
###
### Copyright 2008, Joe Williams
###
### 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
@Pet3ris
Pet3ris / fsm.clj
Created January 25, 2012 13:27
Finite State Machine in Clojure core.logic
(ns fsm
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
;; Encoding a Finite State Machine and recognizing strings in its language in Clojure core.logic
;; We will encode the following FSM:
;;
;; (ok) --+---b---> (fail)
;; ^ |
@cessationoftime
cessationoftime / AkkaSpecification.scala
Created February 8, 2012 02:12
AkkaSpecification - Specs2 specification trait for using the Akka testkit
package org.specs2
package mutable
import org.specs2.execute.StandardResults
import org.specs2.main.ArgumentsShortcuts
import org.specs2.matcher.MustThrownMatchers
import org.specs2.specification.AutoExamples
import org.specs2.specification.FormattingFragments
import org.specs2.matcher.ShouldThrownMatchers
import org.specs2.specification.SpecificationStructure
@finack
finack / application.rb
Created March 17, 2012 06:18
Example Chef Deploy Revision for Rails 3+
app = node[:rails][:app]
rails_base app[:name] do
ruby_ver app[:ruby_ver]
gemset app[:gemset]
end
%w{config log pids cached-copy bundle system}.each do |dir|
directory "#{app[:app_root]}/shared/#{dir}" do
owner app[:deploy_user]
@tmcw
tmcw / togeo.py
Created August 11, 2012 18:53
geo-assign any arbitrary image to a geotiff usable in tilemill
import subprocess
import sys, re
MERC = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs'
infile = sys.argv[1]
info_output = subprocess.Popen(['gdalinfo', infile], stdout=subprocess.PIPE).communicate()[0]
size_is_re = re.compile('Size is (?P<width>\d+), (?P<height>\d+)')
size_is = filter(lambda x: x, map(lambda x: size_is_re.match(x), info_output.split('\n')))
@folone
folone / gist:3911559
Created October 18, 2012 12:43
Reader exercise (inspired by gist from @tonymorris: https://gist.github.com/3884189)
case class Reader[T, +A](run: T ⇒ A) {
def map[B](f: A ⇒ B): Reader[T, B] =
Reader((r: T) ⇒ f(run(r)))
def flatMap[B](f: A ⇒ Reader[T, B]): Reader[T, B] =
Reader((r: T) ⇒ f(run(r)).run(r))
def &&&[B](x: Reader[T, B]): Reader[T, (A, B)] =
for {
a ← this
@patriknw
patriknw / PeekMailbox.scala
Created November 21, 2012 14:20
PeekMailbox example
package example
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import akka.actor.Actor
import akka.actor.ActorContext
import akka.actor.ActorRef
import akka.actor.ActorSystem
@viktorklang
viktorklang / NettyChannelFutureToScalaFuture.scala
Created December 19, 2012 16:57
Shows how you can use the Promise API of SIP-14 to bridge between Netty ChannelFutures and scala.concurrent.Future
object NettyFutureBridge {
import scala.concurrent.{ Promise, Future }
import scala.util.Try
import java.util.concurrent.CancellationException
import org.jboss.netty.channel.{ Channel, ChannelFuture, ChannelFutureListener }
def apply(nettyFuture: ChannelFuture): Future[Channel] = {
val p = Promise[Channel]()
nettyFuture.addListener(new ChannelFutureListener {
def operationComplete(future: ChannelFuture): Unit = p complete Try(
@GedowFather
GedowFather / aws_vpn_between_vpcgw_and_debian_with_nat.sh
Created January 24, 2014 03:17
BashScript for connecting VPN between VPC G/W and Debian Linux. Connecting from Client to EC2, using NAT on VPN.
#!/bin/bash
#
# Setup VPN between Debian Linux and VPC G/W.
# How to use : ./this_script.sh Generic.txt
#
# For connecting IPsec VPN, you need to allow these connections.
# If VPN has global address, you change FORWARD to OUTPUT.
#
# ex) iptables -A FORWARD -p udp --dport 500 -j ACCEPT
# iptables -A FORWARD -p tcp --dport 500 -j ACCEPT