Skip to content

Instantly share code, notes, and snippets.

loop(Request) ->
try
process(Request)
catch
Class:Exception ->
Req:respond({500, [{"Content-Type", "text/plain"}],
io_lib:format("Couldn't process request ~p~n"
"Exception: ~p:~p~n"
"StackTrace:~p~n", [Request:dump(), Class, Exception,
erlang:get_stacktrace()])})
father = Father.new
child = Child.new(:father => father)
father.save
child.father_id.should == father.id # how? the child references the father, but there's no backlink atm
# ... unless
<% form_for @survey do |f| %>
<%= observe_form "edit_survey_#{@survey.id}",
:url => survey_path(@survey),
:method => :put,
:frequency => 5,
:update => 'savedat_time'
%>
<%#= the form... %>
@caffo
caffo / rails_check_syntax.rake
Created July 28, 2008 21:47
sake task for syntax checking a ruby on rails project
# sake rails:check_syntax
# based on this rake task: http://moourl.com/s2dnw
# non-copyright (c) 2008 rodrigo franco <caffo@imap.cc>
namespace :rails do
task :load_requirements_and do
require 'erb'
require 'open3'
require 'yaml'
end
# initial idea for state(or step #)-based validation
# for the model below, it would only run those validations when instance_model#step == "initial" or nil
class ActiveRecord::Base
def self.validate_on_step(attribute, &block)
attribute, step_attribute = attribute.to_s, "step"
self.send :attr_accessor, step_attribute unless self.respond_to?(step_attribute)
with_options(:if => lambda {|w| (w.send(step_attribute) == attribute) || (w.send(step_attribute).nil?) }) do |validating_model|
yield(validating_model)
def number_to_human_size(number, *args)
return number.nil? ? nil : pluralize(number.to_i, "Byte") if number.to_i < 1024
options = args.extract_options!
options.symbolize_keys!
defaults, human = I18n.translate([:'number.format', :'number.human.format'], :locale => options[:locale]) || [{},{}]
defaults = defaults.merge(human)
unless args.empty?
// ==UserScript==
// @name Fix tabs in gist paste.
// @namespace Gist
// @description nukes tabs
// @include http://gist.github.com/
// ==/UserScript==
var jQuery = unsafeWindow.jQuery;
$ = jQuery
$('.paste').prepend('<a href="#" id="fix_the_fucking_tabs">fix the fucking tabs</a>');
@cmorss
cmorss / private.rb
Created July 28, 2008 22:06 — forked from jbarnette/private.rb
undefined
require "test/unit"
class Module
alias_method :old_private, :private
def private(*args)
old_private(*args)
end
end
@trey
trey / gist:2967
Created July 28, 2008 22:14
How to use Google's AJAX Libraries API to include jQuery.
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">google.load("jquery", "1.2.6");</script>
<script src="/js/load.js" type="text/javascript"></script>
scope 'merb-gen' do
# do merb-gen stuff here
end
scope 'monkey' do
# do monkey stuff here
end