Skip to content

Instantly share code, notes, and snippets.

View rsl's full-sized avatar
🏳️‍🌈
still a bad fish and free bird

Russell Norris rsl

🏳️‍🌈
still a bad fish and free bird
View GitHub Profile
describe ApplicationHelper
describe "current_page?" do
it "should ignore anchors in request_uri" do
@controller.request.request_uri = "/page/url#anchor"
helper.current_page?("/page/url").should be_true
end
end
function insert_fields(link, method, content) {
var new_id = new Date().getTime();
var regexp = new RegExp("new_" + method, "g")
$(link).up().insert({
before: content.replace(regexp, new_id)
});
}
function remove_fields(link) {
var hidden_field = $(link).previous("input[type=hidden]");
@rsl
rsl / gist:175865
Created August 26, 2009 21:37 — forked from hardbap/gist:175863
#content ul {
margin: 0;
padding: 8px 21px 8px 21px;
width: 718px;
list-style: none;
display: block;
clear : both;
}
#content li {
@rsl
rsl / descriptive_sql_load_log.rb
Created July 19, 2011 20:39 — forked from JackDanger/descriptive_sql_load_log.rb
Let Rails display file names and line numbers for log activity.
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
protected
# Turn:
# User Load (6.3ms) SELECT * FROM "users"
# Into:
# User Load /app/views/_partial.erb:27 (6.3ms) in `_app_views_partial_erb` SELECT * FROM "users"
class Test::Unit::TestCase # Or ActiveSupport::TestCase if you are using Rails
# This is a debugging utility to find slow tests.
# Usage: rake FIND_SLOW_TESTS=true test:units
unless ENV["FIND_SLOW_TESTS"].blank?
alias_method :old_run, :run
def run(*args, &block)
start_time = Time.now
old_run *args, &block
test_time = Time.now - start_time
puts "\nSLOW TEST: #{self.name}, #{test_time}s" if test_time > 0.5
@rsl
rsl / example.rb
Last active August 29, 2015 13:57 — forked from anonymous/gist:9549170
def insert_flash
content_tag :div, class: 'flash' do
flash.each do |name, msg|
add_flash name, msg
end
end
end
private
@rsl
rsl / mcreate
Last active August 29, 2015 13:59 — forked from andrewfree/mcreate
def create
# current_user = User.first
if moment_params.empty?
render status: 406, nothing: true and return
else
@moment = current_user.moments.build(moment_params)
if @moment.save
render "moments/show", status: 201
else
render status: 422, nothing: true # We should know about things like this.
= form_for Comment.new do |f|
= f.text_area :body
= f.button t("button.submit")
- @video.comments.reverse.each do |comment|
- next unless comment.persisted?
%div{class: 'comment', id: "comment_#{comment.id}"}
= simple_format comment.body
@rsl
rsl / bank_proj.rb
Last active August 29, 2015 14:00 — forked from btn0s/bank_proj
# Tip: If you name your gist foo.rb it will highlight the code as Ruby.
class Account
# Two things here. First you never use the reader methods you define here.
# You can either refactor the code to use them [see other gist]
# or just remove them and keep using the instance variables.
# Second, usually Rubyists [we have a name!] group class-level code
# like attr_reader or defining constants apart from the method definitions
# with newlines. Multiple calls of similar types [like another attr_reader here]
# would be back-to-back [no newlines] though. Just a readability thing.
attr_reader :name, :balance
@rsl
rsl / gist:11389367
Last active August 29, 2015 14:00 — forked from btn0s/gist:11389343
class Sleigh
USERS = {
"Santa Claus": "Ho Ho Ho!"
}
def authenticate(name, password)
USERS[name] == password
end
end