Skip to content

Instantly share code, notes, and snippets.

class String
@@all = []
def /(other)
@@all << "#{self} #{other}"
@@all.join(' and ')
end
def self.reset
@@all = []
end
@fronx
fronx / url_dsl.rb
Created December 14, 2009 22:31 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
@fronx
fronx / gist:281436
Created January 19, 2010 23:40 — forked from dhh/gist:281420
class Notifier < ActionMailer::Base
delivers_from '[email protected]'
def welcome(user)
@user = user # available to the view
mail(:subject => 'Welcome!', :to => user.email_address)
# auto renders both welcome.text.erb and welcome.html.erb
end
def goodbye(user)
@fronx
fronx / README.txt
Created March 15, 2010 21:33 — forked from rmm5t/README.md
You can represent time statements in most western languages where
a prefix and/or suffix is used.
The default case is to use suffix only (as in English), which you
do by providing the `suffixAgo` and `suffixFromNow` settings in
the strings hash (earlier versions of timeago used the deprecated
`ago` and `fromNow` options). If present, they are used.
2 minutes [suffixAgo]
2 minutes [suffixFromNow]
@fronx
fronx / omg.rb
Created March 16, 2010 06:32 — forked from wycats/omg.rb
require ".bundle/environment"
Bundler.setup
require "action_controller/railtie"
class FooController < ActionController::Base
def bar
self.response_body = "HELLO"
end
end
# Include an anonymous module
#
# Useful for defining a class with a base module. So, instead of:
#
# class Foo
# module Base
# def bar
# # ...
# end
# end
@fronx
fronx / scooby-doo.rb
Created September 24, 2010 14:40 — forked from awendt/scooby-doo.rb
def scooby
`say #{yield}`
end
scooby do
"be-doo-be-doo"
end
document.body.addEventListener('keydown', function(e) {
([37, 39].indexOf(e.keyCode) > -1) && pres[{37:'prev',39:'next'}[e.keyCode]]();
});
// VERSUS
document.body.addEventListener('keydown', function(e) {
switch(e.keyCode) {
case 37: pres.prev(); break;
case 39: pres.next(); break;
require 'spec_helper'
describe SharesController do
render_views
describe '#create' do
let(:share_params) { :facebook_id => 'abc', :address_id => 7 }
it "redirects to login" do
post :create, :share => share_params
@fronx
fronx / fronx-4clojure-solution73.clj
Created September 16, 2011 17:49 — forked from anonymous/fronx-4clojure-solution73.clj
fronx's solution to Analyze a Tic-Tac-Toe Board ;; https://4clojure.com/problem/73
;; fronx's solution to Analyze a Tic-Tac-Toe Board
;; https://4clojure.com/problem/73
(fn [m]
(first
(filter
(fn win? [player]
(->> (let [idx [0 1 2]]
(concat m ; rows
(map (fn [i] (map #(% i) m)) idx) ; columns