Skip to content

Instantly share code, notes, and snippets.

CREATE OR REPLACE FUNCTION r_scatter(title text, sql text)
RETURNS text AS
$BODY$
str <- pg.spi.exec (sql);
pdf('/tmp/scatter_plot.pdf');
plot(str,main=title,cex=0.3, pch=20,col=rgb(255,0,0,2,maxColorValue=255),ylim=c(0,100));
dev.off();
print('done');
$BODY$
LANGUAGE 'plr' VOLATILE;
/*********************************************
* OPL 5.0 Model
* Author: Andrew Fecheyr Lippens
* Creation Date: 9/05/2009 at 23:49
*********************************************/
// Setup
int horizon = 60*24*21-1; // Number of minutes in a week
int blocktime = 5;
@andruby
andruby / my_lib.erl
Created November 23, 2009 23:53
[Erlang] lists:seq for floats
%% This lets you do stuff like
1> my_lib:seq_float(10.01,10.13,0.02).
[10.01,10.03,10.05,10.07,10.09,10.11,10.13]
@andruby
andruby / ps_avg.rb
Created January 23, 2010 17:17
Sample the CPU Load and Memory usage of an application over time and returns the average, standard deviation and min-max range.
# Sample the CPU Load and Memory usage of an application over time and
# returns the average, standard deviation and min-max range.
# processname to check as $1, number of samples as $2
# eg: ruby ps_avg.rb safari 100
process_name = ARGV[0]
sample_count = ARGV[1] || 120
samples_per_seconds = 3
sleep_time = (1/samples_per_seconds.to_f)
@andruby
andruby / dyndns_update.rb
Created April 17, 2010 11:01
Zerigo dynamic dns updater
#!/usr/bin/env ruby
# Dynamic DNS updater by Andruby for Zerigo
# www.andrewsblog.org
ApiKey = 'myzerigoapikey' # your Zerigo API key
Host = 'test.example.com' # the host you want to dynamically update
User = '[email protected]' # your Zerigo username
NameServer = 'a.ns.zerigo.net' # Zerigo nameserver to query
LastIpTmpFile = '/tmp/dyn_update_last_ip' # a temporary file where we store the last ip adress
# Script to setup swap space on a Amazon AWS instance
# Takes about 1 minute per GB of swap size
# run it like this:
# ruby aws_swap.rb 4G
SWAP_LOCATION = "/mnt/swapfile"
def run(cmd)
if ARGV.join(' ').include?('-p')
puts cmd
@andruby
andruby / problem.rb
Created May 8, 2010 23:27
My solution to Google's CodeJam 2010
# Helper class for file I/O and time measurement
class Problem
def initialize(input_file,output_file=nil)
@output_file = output_file
@start_time = Time.now
@input_file = input_file
@output_file ||= input_file.gsub('.txt','').gsub('.in','.out')
File.delete(@output_file) if File.exists?(@output_file)
end
# Application Generator Template
# Modifies a Rails app to use Mongoid, Devise, jQuery, Haml
# Usage: rails new app_name -m http://gist.github.com/raw/452364/gistfile1.txt
# More info: http://github.com/fortuity/rails3-mongoid-devise/
# If you are customizing this template, you can use any methods provided by Thor::Actions
# http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html
# and Rails::Generators::Actions
# http://github.com/rails/rails/blob/master/railties/lib/rails/generators/actions.rb
@andruby
andruby / deploy.rb
Created January 26, 2011 19:48
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
@andruby
andruby / gist:992773
Created May 26, 2011 08:28
Find the first 1000 primes quickly in Ruby
getal = 2
primes = [2]
begin
getal += 1
primes << getal unless primes.any? { |deler| getal % deler == 0 }
end until primes.size >= 1000
p primes