Skip to content

Instantly share code, notes, and snippets.

@ruckus
ruckus / gist:3989311
Created October 31, 2012 19:36
tumblr theme with fixed footer
<!DOCTYPE html>
<!--
High Res Theme 1.1.9 -- 26 September 2012
(c) 2011-2012 Justin Ouellette, all rights reserved
http://highrestheme.tumblr.com/
-->
<html>
<head>
<title>{Title}{block:PostSummary} - {PostSummary}{/block:PostSummary}</title>
<meta name="tumblr-theme" content="30257" />
@ruckus
ruckus / AppController.php
Created October 25, 2012 04:51
CakePHP Request logging ala Rails
class AppController extends Controller {
function beforeFilter() {
$this->capture_request_head_for_log();
}
/*
Log some basic basic details of the HTTP Request:
Started GET "/users/lost" for 127.0.0.1 at 2012-10-24 19:18:25 -0700
@ruckus
ruckus / 20120925150949_create_foo_table
Created September 25, 2012 22:38
Sample SQL migration file
// Generate the timestamp for the filename from the command line like:
// php -r "echo date('YmdHis', time());"
UP
--
CREATE TABLE foo (
id int(11) PRIMARY KEY AUTO_INCREMENT,
first_name varchar(64)
);
@ruckus
ruckus / gist:3124445
Created July 16, 2012 19:11
Rails Single Table Inheritance example
create_table :media_items do |t|
t.string :type, :null => false, :limit => 32
t.string :name
t.timestamps
end
class MediaItem < ActiveRecord::Base
validates_presence_of :kind
end
#import "Account.h"
#import "JSONKit.h"
@implementation Account
@synthesize name = _name;
@synthesize accountId = _accountId;
@synthesize initial = _initial;
@synthesize code = _code;
SELECT varietals.*, ts_rank_cd(varietals.search_content, plainto_tsquery('vinosmith', 'gruner')) as rank
FROM varietals WHERE varietals.search_content @@ plainto_tsquery('vinosmith', 'gruner')
ORDER BY rank DESC limit 25
=> [#<Varietal id: 657, name: "Grüner Veltliner" .. ]
CREATE EXTENSION unaccent;
CREATE TEXT SEARCH CONFIGURATION vinosmith ( COPY = english );
ALTER TEXT SEARCH CONFIGURATION vinosmith ALTER MAPPING FOR hword, hword_part, word WITH unaccent, english_stem;
CREATE TRIGGER contacts_search_content_trigger BEFORE INSERT OR UPDATE
ON contacts FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(search_content, 'public.vinosmith', title, name, phone, fax, email, mobile_phone);
2012-04-27T21:10:44Z 530 TID-owb1ckq7w INFO: Booting sidekiq 1.1.4 with Redis at redis://localhost:6379/6
2012-04-27T21:10:44Z 530 TID-owb1ckq7w INFO: Running in ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
2012-04-27T21:10:44Z 530 TID-owb1ckq7w DEBUG: {:queues=>["default"], :concurrency=>25, :require=>".", :environment=>"development", :timeout=>8, :enable_rails_extensions=>true}
2012-04-27T21:10:44Z 530 TID-owb099rks INFO: Starting processing, hit Ctrl-C to stop
2012-04-27T21:10:59Z 530 TID-owb14h9wk INFO: IntuitSyncRequest MSG-owb14ha9w start
/Users/codyc/.rvm/gems/ruby-1.9.3-p194@vino/gems/activerecord-3.2.2/lib/active_record/result.rb:30: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
-- Control frame information -----------------------------------------------
SELECT contacts.*, ts_rank_cd(contacts.search_content, to_tsquery('purple & drank')) as rank
FROM contacts
WHERE contacts.search_content @@ to_tsquery('purple & drank')
ORDER BY rank DESC
CREATE FUNCTION wine_books_search_content_trigger() RETURNS trigger AS $$
begin
new.search_content := (
-- MUST use COALLESCE here if any of these columns can be NULL
SELECT to_tsvector(COALESCE(wine_books.code, '') || ' ' || COALESCE(wine_books.name, '') || ' ' || COALESCE(producers.name, '') || ' ' || COALESCE(varietals.name, '') || COALESCE(wine_books.year::varchar, ''))
FROM wine_books
LEFT OUTER JOIN producers ON producers.id = wine_books.producer_id
LEFT OUTER JOIN varietals ON varietals.id = wine_books.varietal_id
WHERE wine_books.id = new.id);
return new;