Skip to content

Instantly share code, notes, and snippets.

View jamiecook's full-sized avatar

Jamie Cook jamiecook

View GitHub Profile
class User < ActiveRecord::Base
# new columns need to be added here to be writable through mass assignment
attr_accessible :email, :password, :password_confirmation # :username,
attr_accessor :password, :password_salt
before_save :prepare_password
#validates_presence_of :username
#validates_uniqueness_of :username, :email, :allow_blank => true
validates_uniqueness_of :email, :allow_blank => false
@jamiecook
jamiecook / git-shell
Created May 25, 2012 04:52
Simple version of git-shell which passes arguments straight through to bash
#!/usr/bin/env bash
shift # strip the ruby version number
exec bash "$@"
[:id, :tag, :type, :type_name].each { |y|
define_method "#{object_type}_#{y}" do |id|
@object_ids ||= {}
@object_ids[[$Ot.currentVariant, object_type]] ||= self.send("get_x_to_#{y}_hash", object_type.to_sym)
if [:type,:type_name].include?(y)
rv = @object_types[object_type][nr][serie.to_serie]
return (rv.is_a?(Fixnum) || rv.is_a?(String)) ? rv : nil
else
return @object_ids[object_type][id]
end
@jamiecook
jamiecook / gist:2892206
Created June 7, 2012 22:58
What happens in the temp directory when you run SL
REM - WHAT'S THE TIME AND WHAT'S MY TEMP DIR
C:\Users\jamie.cook\AppData\Local\Temp>echo %TEMP%
D:\Temp
C:\Users\jamie.cook\AppData\Local\Temp>date /T
08:53 AM Fri 06/08/2012
C:\Users\jamie.cook\AppData\Local\Temp>dir %TEMP%\tgc*.tmp tgc*.tmp
Volume in drive D is New Volume
Volume Serial Number is 0E92-4B73
" Lets get crontab editing working
if $VIM_CRONTAB == 'true'
set nobackup
set nowritebackup
endif
@jamiecook
jamiecook / test_linear_regression.rb
Created March 3, 2013 05:51
test some linear regression shit yo!
require 'ml4r_test_case'
require 'ml4r/ml4r'
require 'ml4r/linear_regression'
class TestLinearRegression < Ml4rTestCase
DELTA = 0.0001
def test_simple_regression
lr = Ml4r::OLSLinearRegression.new([[1.0],[2.0],[3.0]], [1.0, 2.0, 3.0])
assert_kind_of(Ml4r::LinearRegression, lr)
@jamiecook
jamiecook / configuration.rb
Created March 4, 2013 08:04
capistrano to configure ntp to brisbane
desc "Configure the time zone to Australia/Brisbane"
task :timezone, :roles => [:tempest_node, :ws_node, :grid_nodes] do
sudo "apt-get -qy install ntp"
sudo "rm -f /etc/localtime"
sudo "ln -s /usr/share/zoneinfo/Australia/Brisbane /etc/localtime"
sudo "sed -i \"`grep -n ^server /etc/ntp.conf | head -n 1 | awk -F : '{print $1}'` i\\server pool.ntp.org\" /etc/ntp.conf"
sudo "/etc/init.d/ntp restart"
end
mat1 = OtMatrix.new(2)
mat1[] = 55
mat2 = OtMatrix.new(2)
mat2[] = 50
mat2[1,1] = 99999
p mat2
mat_out = OtMatrix.new(2)
class AirportTripsReporter
def self.get_trips(iter, serie, pmtu, group_by, blend = false)
args = [iter, serie, pmtu, group_by, blend]
p args.inspect
@trips ||= {}
return @trips[args] if @trips[args]
@trips[args] = TripsExtractor.extract_trips(iter, serie, pmtu, group_by, blend)
@trips[args]
end
end
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Risk where
import Control.Monad.Random
import Control.Monad
import Data.List
------------------------------------------------------------
-- Die values