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 / gist:1903463
Created February 24, 2012 20:16
Resource naming solutions
# Rails < 3
class CustomerLocation < ActiveRecord::Base
def self.model_name
ActiveSupport::ModelName.new("Location")
end
end
# ActiveSupport::ModelName is moved or deprecated after 3
@nowk
nowk / .vimrc
Created March 12, 2012 15:33
my (ugly) vimrc files
set shell=bash
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
@nowk
nowk / application.js
Created March 18, 2012 22:24
Formtastic errors w/ ajax + knockout.js and responds_to :json
$.ajax({
error: function(jqXHR, textStatus, errorThrown) {
// reset
$('.formtastic li').removeClass("error");
$('.formtastic li .inline-errors').remove();
// set the errors
// TODO turn into dynamic
// TODO include errors for :base and #semantic_errors
var errors = ko.mapping.toJS(ko.mapping.fromJSON(jqXHR.responseText));
@nowk
nowk / email_matchers.rb
Created March 21, 2012 23:56
Email matchers
RSpec::Matchers.define :be_from do |expected|
match do |actual|
actual.from_addrs.include?(expected)
end
failure_message_for_should do |actual|
%{expected to be from #{expected} but was from #{actual.from_addrs.join(', ')}}
end
failure_message_for_should_not do |actual|
(1..100).each do |n|
puts case
when (n % 3) == 0
"Fizz"
when (n % 5) == 0
"Buzz"
when (n % 3) == 0 && (n % 5) == 0
"FizzBuzz"
else
n
@nowk
nowk / capistrano_database_yml.rb
Created April 17, 2012 21:31 — forked from weppos/capistrano_database_yml.rb
Provides a couple of tasks for creating the database.yml configuration file dynamically when deploy:setup is run.
#
# = Capistrano database.yml task
#
# Provides a couple of tasks for creating the database.yml
# configuration file dynamically when deploy:setup is run.
#
# Category:: Capistrano
# Package:: Database
# Author:: Simone Carletti <[email protected]>
# Copyright:: 2007-2010 The Authors
@nowk
nowk / .rvmrc
Created April 18, 2012 18:12
Foreman Upstarting some Rubies
# server user ~/.rvmrc
export rvm_path="/path/to/users/.rvm"
export rvm_trust_rvmrcs_flag=1
locals: &locals
host: localhost
adapter: mysql
username: <username>
password: <password>
pool: 5
timeout: 5000
# socket: /Application/MAMP/tmp/mysql/mysql.sock
development:
// 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",
@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