Skip to content

Instantly share code, notes, and snippets.

@xaviershay
xaviershay / page.rb
Created February 16, 2009 00:17 — forked from chrislloyd/page.rb
Refactor this code: URL Matching Edition
--
So I have Pages, in a nested set so that each page has parent. That allows me to have urls like:
/foo/bar
where the Page with permalink 'foo' has a child with the permalink 'bar'. In my routes.rb I have a general catch-all route as my last route.
map.page '/*tree', :controller => 'pages', :action => 'show'
# Change login from script/console
# Grab the session_id from your server log
module ConsoleHelpers
def set_session(session_id)
Thread.current[:session_id] = session_id
end
def login(user)
session_id = Thread.current[:session_id]
~/Code/thehunge (master)$ git log
commit 27a59363ace6727da6cbd8deaf96cda264592bee
Author: Xavier Shay <xavier@rhnh.net>
Date: Thu Apr 2 17:56:32 2009 +1100
Train spike
commit 837491549d18bcc35c84bb0a8b682917ce3130fe
Author: Xavier Shay <xavier@rhnh.net>
Date: Thu Apr 2 16:48:54 2009 +1100
Need to build a "waiting list" for registrations.
Thinking about duplicating the table structure, rather than having an 'accepted' flag on the Registration.
This way it's easier to efficiently query stats, without having to worry about joining in registration or including 'accepted' in conditions/indexes.
Should be able to meta-program most of it, so not much extra code. Keeps data clean.
Registration
has N Options
has 1 Thing
... other things
require 'spec/runner/formatter/progress_bar_formatter'
class RealtimeFailuresFormatter < Spec::Runner::Formatter::ProgressBarFormatter
def example_failed(example, counter, failure)
super
@output.puts
@output.puts failure.exception.to_s, failure.exception.backtrace
end
end
>> $(0).sum()
0[object HTMLDocument]
>> $(1).sum()
1
Why the HTMLDocument in there?
module Support
class ApplicationServer
attr_accessor :options
attr_accessor :started
def initialize(options = {})
self.options = options
end
def option(key, default = nil)
; AMQP 0.9.1, correct ABNF format, with circular dependencies excluded for the moment (so it's
; technically incomplete, but functionally I think will deal with most messages I'm interested in)
amqp = protocol-header *amqp-unit
amqp-unit = method / content / heartbeat ; amqp-unit was not defined in the spec
protocol-header = literal-AMQP protocol-id protocol-version
literal-AMQP = %d65.77.81.80 ; "AMQP"
protocol-id = %d0 ; Must be 0
protocol-version = %d0.9.1 ; 0-9-1
From a0db2d73d6d6099c5bc810d60bcce192c6d81dbe Mon Sep 17 00:00:00 2001
From: Xavier Shay <xavier@rhnh.net>
Date: Tue, 1 Dec 2009 21:20:14 +1100
Subject: [PATCH] sys.inspect is totally more awesome now:
- No longer relies on JSON.stringify, so it can output nulls and functions
- Handles circular references better
- Has tests
---
lib/sys.js | 84 +++++++++++++++++++++++++++++++++++-----------
From d5d522adb48cb3c42a7bd86cc019f9f2fca32166 Mon Sep 17 00:00:00 2001
From: Xavier Shay <xavier@rhnh.net>
Date: Mon, 7 Dec 2009 15:44:41 +1100
Subject: [PATCH] sys.inspect prints out special chars correctly (\n, \u0001, etc...)
---
lib/sys.js | 2 +-
test/mjsunit/test-sys.js | 2 ++
2 files changed, 3 insertions(+), 1 deletions(-)