This file contains hidden or 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
(function() { | |
$(function() { | |
return $('a[data-toggle="tab"]').on('shown', function(e) { | |
var persistentTabs; | |
persistentTabs = localStorage.getObject("persistentTabs") || {}; | |
persistentTabs[location.pathname] = e.target.hash; | |
return localStorage.setObject("persistentTabs", persistentTabs); | |
}); | |
}); |
This file contains hidden or 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 test_exclusions(str) | |
exclusions = ['a', /^I-/] | |
case str | |
when *exclusions then | |
"Excluded" | |
else | |
"Accepted" | |
end | |
end |
This file contains hidden or 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
# Given a big (~25MB) text file, I want to extract | |
# and process lines that are prefixed with a certain | |
# string. In the actual case, known_prefixes is | |
# approximately 50 elements long with potential for growth | |
known_prefixes = %w(aa ab ax fy fx) | |
regex = "^#{known_prefixes.join("|")} " | |
IO.foreach(big_ass_text_file).each |row| | |
if row =~ regex |
This file contains hidden or 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 update | |
if @baby.update_attributes(params[:baby]) | |
if params[:notify] == true | |
flash[:notice] = "Done" | |
else | |
redirect_to(root_url(:host => with_subdomain(@baby.subdomain)), :notice => 'Your baby was successfully updated and everyone has been told the good news.') | |
end | |
else | |
render :action => "edit" | |
end |
This file contains hidden or 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
class FoosController < AbstractController::Base | |
def update | |
@foo = Foo.find(params[:id]) | |
# If our changed object saves... | |
if @foo.update_attributes(params[:attributes]) | |
# Now, we check for changes. In some situations, we might | |
# use @foo.notify_changed? but given that update_attributes | |
# clobbers the dirty state of your instance, we need to |
This file contains hidden or 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
class User | |
include Mongoid::Document | |
field :email | |
validates_format_of :email, :with => /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i, :message => "is not a valid email adress." | |
end | |
This file contains hidden or 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
class FancyMiddleware | |
def initialize(app) | |
@app = app | |
@excluded_paths = [] | |
end | |
def call(env) | |
# env variable may be wrong here | |
if @excluded_paths.include(env["REQUEST_PATH"]) | |
# do magic |
This file contains hidden or 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
[server] administrator:~$ nc -zvw 1 207.97.227.239 22 | |
github.com [207.97.227.239] 22 (ssh) : No route to host | |
[server] administrator:~$ nc -zvw 1 207.97.227.239 80 | |
github.com [207.97.227.239] 80 (www) open |
This file contains hidden or 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
module ResourcefulRequestHelper | |
# Iterates through each route defined for the current controller, yielding | |
# each one to allow the same set of assertions / expectations to be tested. | |
# | |
# Usage: | |
# ====== | |
# describe UsersController do | |
# let(:user) { double('user') } | |
# |
This file contains hidden or 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
class Article < ActiveRecord::Base | |
# Has attributes: :title, :body, :active | |
attr_protected :active | |
end | |
class Image < ActiveRecord::Base | |
# Has attributes: :title, :filename, :active | |
attr_accessible :title |