Skip to content

Instantly share code, notes, and snippets.

@kuon
kuon / Rakefile
Created May 10, 2014 22:56
How to use nanoc with rerun
task :server do
fork do
exec 'bundle exec rackup -p 4567'
end
exec %{rerun -p "{Rules,Gemfile,content/**/*,lib/**/*,static/**/*,layouts/**/*}" -x nanoc compile}
end
# a method presently in the model
# I rapidely used slice to mimic attr_accessible and to have tests pass
# but I am wondering if such code shouldn't go in the controller instead
class Taxonomy < ActiveRecord::Base
has_many :terms,
-> {order(:id)}
choices: ['yes', 'no']
label: 'auth.labels.automaticLogin'
tabindex: idx++
produces:
{
choices: ['yes', 'no']
}, {
label: 'auth.labels.automaticLogin',
hash = {}
a.resource_sets.each do |set|
r = set.resource
hash[set.key] = {
:id => r.id,
:url => r.url
}
end
hash
client
proto udp
dev tun
ca ca.crt
dh dh2048.pem
cert kuon.crt
key kuon.key
remote <hidden remote ip> 1191
cipher DES-CBC
verb 2
@kuon
kuon / gist:4013591
Created November 4, 2012 20:27
slow query
explain analyse SELECT "field_values".* FROM "field_values" LEFT OUTER JOIN "field_entry_values" ON "field_entry_values"."field_value_id" = "field_values"."id" LEFT OUTER JOIN "field_entries" ON "field_entries"."id" = "field_entry_values"."field_entry_id" WHERE "field_entries"."id" IS NULL;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
Hash Anti Join (cost=366.83..613.78 rows=1 width=146) (actual time=69.079..69.079 rows=0 loops=1)
Hash Cond: (field_entry_values.field_entry_id = field_entries.id)
-> Hash Right Join (cost=129.64..350.77 rows=9391 width=162) (actual time=12.138..41.534 rows=9406 loops=1)
Hash Cond: (field_entry_values.field_value_id = field_values.id)
-> Seq Scan on field_entry_values (cost=0.00..174.17 rows=9391 width=32) (actual time=0.007..8.561 rows
@kuon
kuon / gist:4004319
Created November 2, 2012 21:08
Slow query
memoways=# \d field_entries
Table "public.field_entries"
Column | Type | Modifiers
---------------------+-----------------------------+-------------------------------------
id | uuid | not null default uuid_generate_v4()
created_at | timestamp without time zone | not null
updated_at | timestamp without time zone | not null
field_definition_id | uuid | not null
asset_id | uuid |
Indexes:
@kuon
kuon / gist:3806377
Created September 30, 2012 10:01
Adding nested routes on the same controller
resources :users do
put 'parents/:parent_id', :action => 'add_parent', :as => 'parents'
delete 'parents/:parent_id', :action => 'remove_parent'
end
┌─(~/Projects/GithubForks/cappuccino/Foundation)────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────(2012-07-11 17:13:19)─(kuon@aiur)─
└─(node *)─> touch CPArray/*
┌─(~/Projects/GithubForks/cappuccino/Foundation)────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────(2012-07-11 17:13:30)─(kuon@aiur)─
└─(node )─> time jake
[CPP] _CPJavaScriptArray.j
[OBJJC] _CPJavaScriptArray.j
[CPP] CPArray.j
[OBJJC] CPArray.j
[CPP] CPMutableArray.j
[OBJJC] CPMutableArray.j
create table nodes (int id, int parent_id);
insert into nodes (1, null);
insert into nodes (2, null);
insert into nodes (3, 1);
insert into nodes (4, 2);
insert into nodes (5, 4);
How can I do a query like this (on PostgreSQL 9.1):