Skip to content

Instantly share code, notes, and snippets.

View bastjan's full-sized avatar

Sebastian Widmer bastjan

View GitHub Profile
@bastjan
bastjan / precision.sh
Created February 13, 2014 09:59
floating point number precision test
perl -e 'printf("%40.40f\n", 0.7)."\n"'
@bastjan
bastjan / gist:9364262
Created March 5, 2014 09:47
sed example
grep -lR "url = /home/git/repositories" . | xargs sed -i s/\\\/home\\\/git\\\/repositories/\\\/db\\\/gitroot\\\/repositories/g
@bastjan
bastjan / pgv8_trigger.sql
Created June 27, 2014 10:37
calculate delta of updated row in postgres and notify listener with json
-- Function: tacmon.test_v8()
-- DROP FUNCTION tacmon.test_v8();
CREATE OR REPLACE FUNCTION tacmon.test_v8()
RETURNS trigger AS
$BODY$// calculate delta
var key, delta = [];
for (key in NEW) {
var valueOld = OLD[key];
@bastjan
bastjan / quickadd.rb
Last active February 21, 2017 13:50
quickadd ta holidays
#!/usr/bin/env ruby
require 'date'
require 'rest-client'
ENDPOINT = "https://ssop.terreactive.ch/erp/ext/db1/terreActive-Info/worktime/moddo.htm.new"
def post date, rest_client
rest_client.post \
index: '682011.169',
@bastjan
bastjan / gist:35dc68b43942365d67cb
Last active August 29, 2015 14:06
needed taclom ubuntu packages
build-essential
postgresql-9.3
libpq-dev
libssl-dev
libxml2-dev
libzmq3
libzmq3-dev
librrd-dev
libreadline-dev
redis-server
server {
listen 80;
server_name localhost;
# application
location / {
proxy_pass http://localhost:3000/;
}
@bastjan
bastjan / ar_logger.rb
Created September 18, 2014 07:24
show sql statements in rails 4 console
ActiveRecord::Base.logger = Logger.new(STDOUT)
@bastjan
bastjan / benchmark.rb
Last active August 29, 2015 14:11 — forked from pauldix/gist:7549
Benchmark different ruby serializing options
require 'benchmark'
require 'rubygems'
require 'json'
require 'yaml'
include Benchmark
benchmark_iterations = 1
large_single_dimension_array = [42, 123.123] * 5000
large_single_dimension_hash = {}
10000.times do |i|
@bastjan
bastjan / order_by_subquery.sql
Last active August 29, 2015 14:24
order by subquery postgres
CREATE OR REPLACE FUNCTION idx(anyarray, anyelement)
RETURNS int AS
$$
SELECT i FROM (
SELECT generate_series(array_lower($1,1),array_upper($1,1))
) g(i)
WHERE $1[i] = $2
LIMIT 1;
$$ LANGUAGE sql IMMUTABLE;
@bastjan
bastjan / activerecord_union_scopes.rb
Created October 31, 2016 14:02
activerecord union scopes
scope1 = Model.scope1
scope2 = Model.scope2
union = Arel::Nodes::Union.new(scope1.arel, scope2.arel)
aliased_union = Arel::Nodes::As.new(union, Model.arel_table)
Model.from(aliased_union)