Skip to content

Instantly share code, notes, and snippets.

module RailsAdmin
module AuthorizationAdapters
class CanCanAdapter
def filter_objects(objects)
objects.accessible_by(current_ability)
end
def authorize_action(action, class, object)
current_ability.authorize! action.to_sym, (object || class)
end
@ryanb
ryanb / github_tree_slider.js
Created December 6, 2010 17:23
This is how GitHub's new AJAX file browser works.
GitHub.TreeSlider = function () {
if (window.history && window.history.pushState) {
function a() {
if (e.sliding) {
e.sliding = false;
$(".frame-right").hide();
$(".frame-loading:visible").removeClass("frame-loading")
}
}
if (!($("#slider").length == 0 || !GitHub.shouldSlide)) if (!navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
require "time"
require "date"
class Date
def to_time
Time.local(year, month, day)
end
end
class Time
require "test/unit"
require File.dirname(__FILE__) + '/business_hours'
class BusinessHoursTest < Test::Unit::TestCase
def setup
@hours = BusinessHours.new("8:00 AM", "5:00 PM")
end
def test_within_working_hours
assert_equal Time.parse("Dec 21, 2009 3:05 PM"), @hours.calculate_deadline(5*60, "Dec 21, 2009 3:00 PM")
@ryanb
ryanb / morse.rb
Created June 10, 2010 17:56 — forked from swhitt/morse.rb
def morse s;26.times{|i|s.gsub! /#{(97+i).chr}/i,("$be5 J8G#T6P'&9Sl/,!-H0cfk"[i]-31).to_s(3).tr("12",".-")};s;end
def luhn? n;s=0;n.size.times{|i|x=n[-(i+1),1].to_i*(i%2+1);s+=x>9?x+1:x};s%10==0;end
def morse s;26.times{|i|s.gsub!(/#{(97+i).chr}/i,%w[.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..][i])};s;end
require "test/unit"
class MaskTest < Test::Unit::TestCase
def test_morse
assert_equal ".-", morse("a")
assert_equal "-...", morse("b")
assert_equal "......-...-..--- .-----.-..-..-..", morse("Hello World")
end
end
def morse s;26.times{|i|s.gsub!(/#{(97+i).chr}/i,%w[.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..][i])};s;end
Action Pack
* #concat is now deprecated in favor of using <%= %> helpers [YK]
* Block helpers now return Strings, so you can use <%= form_for @foo do |f| %>.
<% form_for do |f| %> still works with deprecation notices [YK]
* Add a new #mount method on the router that does not anchor the PATH_INFO
at the end [YK & CL]