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 / paperclip_initializer.rb
Created January 11, 2011 00:12 — forked from felipeelias/paperclip_initializer.rb
Paperclip initializer to provide dimensions data for the original attachment
# width & height attributes for the original image only
# since style dimensions are already known
#
# Migration to add width & height attribtues for the original attachment
#
# add_column :<model>, :<attachment>_file_width, :integer
# add_column :<model>, :<attachment>_file_height, :integer
#
#
# class Document < ActiveRecord::Base
@nowk
nowk / .autotest
Created June 15, 2011 18:29
Autotest
# this lives in your home directory ~/.autotest
#
Autotest.add_hook :initialize do |autotest|
# autotest.add_exception(%r{^\./db})
# autotest.add_exception(%r{^\./log})
# autotest.add_exception(%r{^\./tmp})
# autotest.add_exception(%r{^\./Gemfile.lock})
# autotest.add_exception(%r{^\./\.git})
# autotest.add_exception(%r{^\./\.bundle})
# autotest.add_exception(%r{^\./.+\.swp})
@nowk
nowk / LICENSE
Created July 31, 2011 23:05 — forked from dreamr/LICENSE
heroku autotag deploy scripts
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEA
@nowk
nowk / PurchaseOrder.rb
Created September 23, 2011 01:47
An eh solution for SO Question#7400657.rb
class PurchaseOrder < ActiveRecord::Base
has_many :sales_transactions, :foreign_key => "po_purchase_order_no",
:primary_key => "purchase_order_no"
before_validation :check_for_exisitng_po # maybe only on create?
accepts_nested_attributes_for :sales_transactions
private
def intercept_alert(confirm = false)
begin
# TODO dismiss vs accept
# page.evaluate_script('window.confirm = function(msg) { return true; }')
# page.driver.browser.switch_to.alert.accept
page.driver.browser.switch_to.alert.dismiss
rescue Selenium::WebDriver::Error::NoAlertOpenError
# /
end
end
def wait_for_ajax(timeout = 5) #Timeout in seconds
page.wait_until(timeout) { page.evaluate_script "jQuery.active == 0" }
end
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '/javascripts/your-js.js';
document.getElementsByTagName('head')[0].appendChild(script);
@nowk
nowk / gist:1304512
Created October 21, 2011 18:05
Firebug in IE
javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=
F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('sc
ript');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body
')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createEleme
nt','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js
','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#star
tOpened');
@nowk
nowk / index.html.haml
Created October 27, 2011 19:21
jQuery #exists() method
jQuery.fn.exists = function() { return jQuery(this).length>0; }
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]);
}