Skip to content

Instantly share code, notes, and snippets.

View leucos's full-sized avatar
👽
Waiting for aliens

Michel Blanc leucos

👽
Waiting for aliens
View GitHub Profile
@leucos
leucos / sample_blog.diff
Created November 25, 2011 18:12
Changes to sample_blog in padrino to make it work
diff --git a/Gemfile b/Gemfile
index 8d95848..90fb80f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,12 +2,13 @@ source :rubygems
# Project requirements
gem 'bundler', '>= 0.9.26'
-gem 'rack-flash'
+gem 'sinatra-flash', :require => 'sinatra/flash'
@leucos
leucos / sound
Created December 6, 2011 22:49
#!/bin/sh
play() {
/usr/bin/play -q /usr/share/sounds/gnome/default/alerts/glass.ogg > /dev/null 2>&1 &
}
mixer() {
/usr/bin/amixer sset 'Master',0 $1 > /dev/null 2>&1
}
@leucos
leucos / config.ru
Created December 11, 2011 14:43
ORA-12154 with Sequel and daemonized Thin
# Invoked with :
# thin -DR config.ru start
# (single, undetached process, oracle Ok)
# thin -DR config.ru -s2 start
# (two forked processed, oracle error ORA-12154)
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
require 'rack'
require 'init.rb'
@leucos
leucos / ora_NOK.rb
Created December 11, 2011 17:09
Post-fork "require 'oci8'" yields ORA-12154
require 'daemons'
Daemonize.daemonize(File.expand_path('./log.txt'), 'test')
require 'oci8'
db = OCI8.new('theuser', 'thepassword', 'SID');
db.exec('select * from utilisateurs where id = 74944') do |r|
puts r.join(',')
Warning: NLS_LANG is not set. fallback to US7ASCII.
I, [2012-01-11T23:16:55.422561 #19184] INFO -- : (0.110660s) SELECT "COLS"."COLUMN_NAME" FROM "ALL_CONSTRAINTS" "CONS", "ALL_CONS_COLUMNS" "COLS" WHERE (("COLS"."TABLE_NAME" = 'UTILISATEURS') AND ("CONS"."CONSTRAINT_TYPE" = 'P') AND ("CONS"."CONSTRAINT_NAME" = "COLS"."CONSTRAINT_NAME") AND ("CONS"."OWNER" = "COLS"."OWNER"))
OMG this is gonna fail !!
E, [2012-01-11T23:16:55.572218 #19184] ERROR -- : OCIError: ORA-00942: table or view does not exist: SELECT * FROM "DBA_TAB_COLS" WHERE ("TABLE_NAME" = 'UTILISATEURS')
In rescue
E, [2012-01-11T23:16:55.688581 #19184] ERROR -- : OCIError: ORA-04043: object SOMEWHERE.UTILISATEURS does not exist: Connection.describe_table
metadata.c:151:in oci8lib_191.so: OCIError: ORA-04043: object SOMEWHERE.UTILISATEURS does not exist (Sequel::DatabaseError)
from /home/leucos/.rvm/gems/ruby-1.9.3-p0@testsequel/gems/ruby-oci8-2.1.0/lib/oci8/metadata.rb:2085:in `describe_table'
from /home/leucos/.rvm/gems/ruby-1.9.3-p0@testsequel
@leucos
leucos / nagbar-quote.diff
Created February 6, 2012 10:18
Quoting problems with i3-sensible-terminal
My $TERMINAL is set to "gnome-terminal"
When introducing a typo in my i3 config, the nagbar is started this way (as seen in processes) :
i3-nagbar -t error -m You have an error in your i3 config file! -b edit config i3-sensible-terminal -e sh -c "i3-sensible-editor \"/home/user/.i3/config\" && i3-msg reload" -b show errors i3-sensible-terminal -e i3-sensible-pager "/tmp/i3-user.6swBVu/errorlog.11524"
Clicking 'edit config' or 'show errors' spaws a new window that disappear immediately.
The problem is that gnome-terminal expects a single argument after '-e', while other terminals are ok with that since -e is the last argument that can appear on their command line. Thus, the whole `sh -c "i3-sensible-editor \"/home/user/.i3/config\"` should be quoted.
@leucos
leucos / todolist.diff
Created March 19, 2012 23:41
Diff that adds pagination to the todolist app example in Ramaze
diff --git a/examples/app/todolist/controller/init.rb b/examples/app/todolist/controller/init.rb
index d5aaa92..3c74fec 100644
--- a/examples/app/todolist/controller/init.rb
+++ b/examples/app/todolist/controller/init.rb
@@ -2,6 +2,12 @@ module TodoList
class Controller < Ramaze::Controller
layout :default
engine :Etanni
+ helper :paginate
+
@leucos
leucos / controller_domains.rb
Created March 20, 2012 10:43
Sample for sidebar rendering
class Domains < MainController
def index
@title = 'Domains'
@domains = Domain
@sidebar = render_sidebar
end
def edit(id)
@domain = Domain[id]
@leucos
leucos / helper_sidebar.rb
Created March 20, 2012 15:57
An attempt on Ramaze helpers and Gestalt
module Ramaze
module Helper
module SideBar
def self.generate(current=nil)
# Get the domain name currently being returned but the Domain controller
# If we're not called from a Domain action, set it to an empty String so
# Ruby doesn't complain
currentname = ( current.nil? ? "" : current.name)
# Get a list of forward/reverse domains
@leucos
leucos / gist:2146971
Created March 21, 2012 13:42
Sequel hook to remove associated entries
class Domain < Sequel::Model
one_to_many :records
def before_destroy
Record.filter(:domain_id => id).destroy
end
end