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 / cmd
Created November 13, 2012 19:26
Git log graph
git log --graph --decorate --pretty=oneline --abbrev-commit --all
@nowk
nowk / juggernaut.rb
Created October 29, 2012 14:50 — forked from maccman/juggernaut.rb
Sinatra Server Side Event streaming.
# Usage: redis-cli publish message hello
require 'sinatra'
require 'redis'
conns = []
get '/' do
erb :index
end
@nowk
nowk / drag_and_drop_simulator.rb
Created September 27, 2012 20:45
A basic wrapper for drag and drop simulation
class DragAndDropSimulator
def initialize(page, drag)
@page = page
@drag = drag
end
def up(num)
drag_and_drop(num)
end
@nowk
nowk / application_controller.rb
Created September 19, 2012 14:51
save and redirect
def after_sign_in_path_for(resource)
if resource.is_a?(User)
redirect_after_login = session[:redirect_after_login]
if redirect_after_login
clear_redirect_after_login
return redirect_after_login
end
else
super
end
@nowk
nowk / .bashrc
Created August 27, 2012 22:58
Setup local ENV variables for 3rd party credentials
# ~/.bashrc
# add this line so keep .bashrc cleaner, if you don't already have it in there somewhere
[ ! -f "$HOME/.bashrc.local" ] || . "$HOME/.bashrc.local"
" My Bundles here:
"
" themes
Bundle 'railscasts'
Bundle 'molokai'
Bundle 'tpope/vim-vividchalk'
Bundle 'nowk/vim-flog'
" 'fousa/vim-flog' fork
" Bundle 'mbadran/headlights'
@nowk
nowk / capybara_wysiwyg.rb
Created July 15, 2012 15:38
Capybara + Selenium wysiwyg interaction
def is_js?
Capybara::Selenium::Driver == page.driver.class
end
page.execute_script('$("#selector").tinymce().setContent("Test goes here")')
# this does not work (or does not work anymore)
# it asks to switch the to the frame
within_frame("#{name}_ifr") do
@nowk
nowk / _pagination_partial.html.haml
Created July 4, 2012 16:24
Knockout pagination
/ ko with: paginate
.will_paginate
%span.per_page_options
Show rows
%select.per_page{:name => "per_page", 'data-bind' => 'options: per_page_limits, value: per_page'}
 
%span.go_to_page_options
Go to
%input{:name => 'page', :type => 'text', :size => "2", 'data-bind' => 'value: page, valueUpdate: "afterKeyDown"'}
 
@nowk
nowk / helper.rb
Created July 4, 2012 15:38
Paginated mapping to json
def mapping_for_js(resource, options={})
resource_name = resource.is_a?(ActiveRecord::Relation) ?
resource.name.tableize : resource.class.to_s.underscore
payload = {
resource_name => JSON.parse(resource.to_json(options[:to_json]))
}
# only merge if paginated
// prepare the form when the DOM is ready
$(document).ready(function() {
// Setup the ajax indicator
$('body').append('<div id="ajaxBusy"><p><img src="images/loading.gif"></p></div>');
$('#ajaxBusy').css({
display:"none",
margin:"0px",
paddingLeft:"0px",