Skip to content

Instantly share code, notes, and snippets.

View nowk's full-sized avatar

Yung Hwa Kwon nowk

  • damncarousel
  • New York, NY
View GitHub Profile
@nowk
nowk / application_helper.rb
Created February 6, 2012 17:56
states array collection for selects
def states_collection
[
['Alabama', 'AL'],
['Alaska', 'AK'],
['Arizona', 'AZ'],
['Arkansas', 'AR'],
['California', 'CA'],
['Colorado', 'CO'],
['Connecticut', 'CT'],
['Delaware', 'DE'],
jQuery.fn.capitalize_word = function() {
$(this).each(function() {
$(this).bind("keyup", function() {
$(this).val($(this).val().toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
}));
})
})
}
@nowk
nowk / screen.scss
Created February 3, 2012 20:07
A basic reset/style base for formtastic
.formtastic {
ol, ul {
list-style-type: none;
li {
font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
margin-bottom: 10px;
label {
display: block;
@nowk
nowk / helper.rb
Created January 13, 2012 15:59
visit helper for capybara + rspec
def visit_the page_to
visit page_to
end
def method_missing(method, *args, &block)
if method.to_s =~ /_page$/
route_path = method.to_s.gsub /_page$/, "_path"
__send__ route_path, *args
else
super
@nowk
nowk / admin_setup.rb
Created December 11, 2011 22:30
Devise + Declarative Authorization multi session/role use
module AdminSetup
def self.included(base)
base.send :include, InstanceMethods
end
module InstanceMethods
protected
def declarative_devise_scope
:admin
@nowk
nowk / rspec-syntax-cheat-sheet.rb
Created November 19, 2011 23:13 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@nowk
nowk / rr.rb
Created November 9, 2011 19:50
require "rr"
Cucumber::Rails::World.send(:include, RR::Adapters::RRMethods)
require 'benchmark'
RSpec::Matchers.define :take_less_than do |n|
chain :seconds do; end
match do |block|
@elapsed = Benchmark.realtime do
block.call
end
@elapsed <= n
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
@nowk
nowk / index.html.haml
Created October 27, 2011 19:21
jQuery #exists() method
jQuery.fn.exists = function() { return jQuery(this).length>0; }