Skip to content

Instantly share code, notes, and snippets.

@heuristicfencepost
heuristicfencepost / comprehension1.clj
Created November 26, 2011 01:16
Code samples for blog post on list comprehensions
(defn euclidean [x y] (Math/sqrt (+ (Math/pow x 2) (Math/pow y 2))))
(println (for [
[x,y]
[[1,2],[2,3],[3,4]]
:when (> (euclidean x y) 3.0)]
[(euclidean x y),(Math/toDegrees (Math/atan (/ y x)))]))
@heuristicfencepost
heuristicfencepost / sieve_actor.rb
Created January 6, 2012 02:34
Implementation of Sieve of Eratosthenes using actors, JRuby and Akka
require 'java'
require 'lib/akka-actor-1.2.jar'
require 'lib/scala-library.jar'
java_import 'akka.actor.Actors'
java_import 'akka.actor.UntypedActor'
java_import 'akka.actor.UntypedActorFactory'
module Sieve
@heuristicfencepost
heuristicfencepost / nonblocking_controller.rb
Created February 21, 2012 05:36
Controller and model implementations for non-blocking Sieve of Eratosthenes implementation
class Controller < UntypedActor
def initialize
@models = 0.upto(3).map do |idx|
model = Actors.actorOf { SieveNonblocking::Model.new }
model.start
model
end
# Seed models with a few initial values... just to get things going
@heuristicfencepost
heuristicfencepost / redcar.sh
Created April 24, 2012 05:36
Shell script for starting redcar using rvm
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
@heuristicfencepost
heuristicfencepost / geb1.pl
Created July 10, 2012 06:49
GEB MIU system in various languages
# Simple implementation of the productions for the MIU system
open INFILE,"<",$ARGV[0];
while(<INFILE>) {
chomp;
next if $_ =~ /#.*/;
print "$1IU\n" if $_ =~ /^(.+?)I$/;
print "M$1$1\n" if $_ =~ /^M(.+)$/;
print "$1U$2\n" if $_ =~ /^(.*)III(.*)$/;
print "$1$2\n" if $_ =~ /^(.*)UU(.*)$/;