Skip to content

Instantly share code, notes, and snippets.

View christianromney's full-sized avatar
🏠
Working from home

Christian Romney christianromney

🏠
Working from home
View GitHub Profile
@christianromney
christianromney / core.clj
Created October 17, 2012 20:35 — forked from ddeaguiar/core.clj
Simple functions to calculate weighted averages in Clojure
(ns rubric.core)
(defn average
"Averages a set of scores"
[& scores]
(/ (apply + scores) (count scores)))
(defn- sum-of
"Sum the collection after applying the given function"
[f coll]
@christianromney
christianromney / gist:3889041
Created October 14, 2012 16:08 — forked from ddeaguiar/gist:3889008
One way to identify neighbors
(ns simple-csp.core
( :refer-clojure :exclude [==])
(:use clojure.core.logic))
(defne arco [x y]
([:sa :wa])
([:sa :nt])
([:sa :q])
([:sa :nsw])
([:sa :v])
@christianromney
christianromney / gist:3889040
Created October 14, 2012 16:08 — forked from ddeaguiar/gist:3889008
One way to identify neighbors
(ns simple-csp.core)
(def arcs [
#{:sa :wa}
#{:sa :nt}
#{:sa :q}
#{:sa :nsw}
#{:sa :v}
#{:wa :nt}
#{:nt :q}
@christianromney
christianromney / knn.clj
Created September 16, 2012 15:04 — forked from davidandrzej/knn.clj
k-Nearest Neighbors (kNN) supervised classifier
; Standard k nearest neighbors classifier
; Does not handle
; > 2 classes
; even values of k
; any bad input, really
;
; David Andrzejewski ([email protected])
;
; Command-line arguments
; 0 training data filename
/*
Hi, I'm Reservation.
I dont need an interface because I am a carrier of data.
Like a good carrier, I can be instantiated in any layer and used
in any other layer.
[CR] Nomenclature! "Data carriers" are *not* domain models. They are
DataTransferObjects (DTOs). What I call domain model, you seem to call
Service Object, whereas what I mean by "Service Object" is something
altogether different...so maybe this is part of the reason we're not
/* This is my interface, my API, my contract. */
interface IReservation {
IList<IGuest> getGuests();
Duration getLength();
Amount getBalance();
Amount getTotal();
bool cancel();
// By the way pay() could have been in IPaymentMethod as well but you know what?
// I called first and so I win!
// Or both of us would end up implementing pay() in which case we would smartly delegate
module SQLGrowler
class Subscriber < ActiveRecord::Railties::Subscriber
def sql(event)
super
g('%s (%.1fms) %s' % [event.payload[:name], event.duration, event.payload[:sql].squeeze(' ')])
end
end
def self.enable
if Kernel.respond_to?(:g)
#!/usr/bin/env ruby
puts "looking for the gems to upgrade..."
gem_info = Struct.new(:name, :version)
to_reinstall = []
Dir.glob('/Library/Ruby/Gems/**/*.bundle').map do |path|
path =~ /.*1.8\/gems\/(.*)-(.*?)\/.*/
name, version = $1, $2
bundle_info = `file path`
to_reinstall << gem_info.new(name, version) unless bundle_info =~ /bundle x86_64/
end
#!/usr/bin/env ruby
require 'rubygems'
require 'octopi'
require 'choice'
include Octopi
Choice.options do
header ''
@christianromney
christianromney / gist:170804
Created August 20, 2009 03:43 — forked from retr0h/gist:132506
Ubuntu Chef Bootstrapper
#!/bin/sh
trap "exit 2" 1 2 3 13 15
OPTS="--no-rdoc --no-ri"
if [ -f "/etc/lsb-release" ]; then
### bootstrap with git.
apt-get update -y && apt-get upgrade -y --force-yes && apt-get install -y git-core vim