Discover gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()])}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% form_for @survey do |f| %> | |
<%= observe_form "edit_survey_#{@survey.id}", | |
:url => survey_path(@survey), | |
:method => :put, | |
:frequency => 5, | |
:update => 'savedat_time' | |
%> | |
<%#= the form... %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "test/unit" | |
class Module | |
alias_method :old_private, :private | |
def private(*args) | |
old_private(*args) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope 'merb-gen' do | |
# do merb-gen stuff here | |
end | |
scope 'monkey' do | |
# do monkey stuff here | |
end |