Skip to content

Instantly share code, notes, and snippets.

MAX_ITER=1000
MAX_THREADS=10
MAX_REPETITIONS=10
def benchmark fun, file
File.unlink file if File.exists? file
(1..MAX_THREADS).each do |thread_count|
total_time = 0.0
mean_time = 0.0
(1..MAX_REPETITIONS).each do |repetitions|
import Database.HDBC
import Database.HDBC.PostgreSQL
import Data.List
type SQL = String
data Relation = Relation SQL
deriving (Show)
sql (Relation sql) = sql
@diogob
diogob / gist:425431
Created June 4, 2010 13:53
relational_sample
:module Database.HDBC Database.HDBC.PostgreSQL
:load relational.hs
let dept = Relation "dept"
let emp = Relation "emp"
let teste = (π ["empno", "ename", "dname"] (emp ⋈ dept))
conn <- connectPostgreSQL "host=localhost dbname=teste"
printTuples conn teste
[[SqlRational (7902 % 1),SqlByteString "FORD",SqlByteString "RESEARCH"],[SqlRational (7654 % 1),SqlByteString "MARTIN",SqlByteString "SALES"],[SqlRational (7521 % 1),SqlByteString "WARD",SqlByteString "SALES"],[SqlRational (7839 % 1),SqlByteString "KING",SqlByteString "ACCOUNTING"],[SqlRational (7876 % 1),SqlByteString "ADAMS",SqlByteString "RESEARCH"],[SqlRational (7782 % 1),SqlByteString "CLARK",SqlByteString "ACCOUNTING"],[SqlRational (7900 % 1),SqlByteString "JAMES",SqlByteString "SALES"],[SqlRational (7698 % 1),SqlByteString "BLAKE",SqlByteString "SALES"],[SqlRational (7566 % 1),SqlByteString "JONES",SqlByteString "RESEARCH"],[SqlRational (7499 % 1),SqlByteString "ALLEN",SqlByteString "SALES"],[SqlRational (7788 % 1),SqlByteString "SCOTT",SqlByteString
MAX_ITER=1000
MAX_THREADS=10
MAX_REPETITIONS=10
def benchmark fun, file
File.unlink file if File.exists? file
(1..MAX_THREADS).each do |thread_count|
total_time = 0.0
mean_time = 0.0
(1..MAX_REPETITIONS).each do |repetitions|
cd $HOME/pgsql90
mkdir mestre
./bin/initdb -D mestre
echo "
listen_addresses = '*'
port = 5433
wal_level = hot_standby
archive_mode = on
archive_command = 'cp %p /tmp/%f'
max_wal_senders = 1
cd $HOME/pgsql90
./bin/psql -p 5433 postgres -c "SELECT pg_start_backup('teste');"
cp -r mestre escravo
rm -f escravo/pg_xlog/*
rm escravo/mestre.conf
rm escravo/postmaster.pid
sed -e "s/mestre\.conf/escravo.conf/" escravo/postgresql.conf > escravo/postgresql.conf.new
mv escravo/postgresql.conf.new escravo/postgresql.conf
echo "
listen_addresses = '*'
wget http://ftp9.us.postgresql.org/pub/mirrors/postgresql/source/v9.0beta2/postgresql-9.0beta2.tar.gz
tar -zxvf postgresql-9.0beta2.tar.gz
cd postgresql-9.0beta2
./configure --prefix=$HOME/pgsql90
make install
CREATE OR REPLACE FUNCTION public.word2number(word text)
RETURNS integer
LANGUAGE sql
AS $function$
SELECT (CASE WHEN sum(u::int) % 9 = 0 THEN 1 ELSE sum(u::int) % 9 END)::int
FROM unnest(regexp_split_to_array(
(
WITH RECURSIVE a as
(
SELECT 1 AS iteration, ascii(lower(nullif(substr($1, 1, 1), ' '))) % 97 % 9 + 1 AS ch
@diogob
diogob / ubuntu-setup.sh
Created January 12, 2011 19:49
Setup a minimal Ruby+PostgreSQL environment in Ubuntu 11.04 (should be called as root)
apt-get update
apt-get install aptitude
aptitude install python-software-properties
apt-add-repository ppa:pitti/postgresql
add-apt-repository ppa:nginx/stable
aptitude update
aptitude install ruby1.9.1-full build-essential postgresql-server-dev-9.1 postgresql-contrib-9.1 nginx vim-nox git-core htop atop most
pg_dropcluster 9.1 main --stop
echo "pt_BR.UTF-8 UTF-8" > /var/lib/locales/supported.d/pt_BR
locale-gen
@diogob
diogob / rails_template.rb
Created January 20, 2011 20:09
My neat rails template created by RailsWizard
# >---------------------------[ Install Command ]-----------------------------<
# rails new APP_NAME -m http://railswizard.org/168b0f6c5ccb55ec3117.rb -T -J
# >---------------------------------------------------------------------------<
#
# _____ _ _ __ ___ _
# | __ \ (_) | \ \ / (_) | |
# | |__) |__ _ _| |___\ \ /\ / / _ ______ _ _ __ __| |
# | _ // _` | | / __|\ \/ \/ / | |_ / _` | '__/ _` |
# | | \ \ (_| | | \__ \ \ /\ / | |/ / (_| | | | (_| |