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 / staging.rb
Last active December 12, 2015 03:18
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
config.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Staging") do |u, p|
[u, p] == [ENV['BASIC_AUTH_USER'], ENV['BASIC_AUTH_PASSWORD']]
end
@nowk
nowk / .vimrc
Last active December 12, 2015 04:18
set t_Co=256
set shell=bash
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
if filereadable(expand('~/.vim/Vunfile'))
source ~/.vim/Vunfile
@nowk
nowk / .bashrc.local
Last active December 12, 2015 07:38
Use MacVim's VI
# alias to macvim for ruby support
alias vim='/Applications/MacVim.app/Contents/MacOS/Vim'
@nowk
nowk / capybara_helpers.rb
Last active December 12, 2015 08:29
Capybara fills in TinyMCE
def fill_in_tinymce(frame_id, options)
page.execute_script(%{tinyMCE.editors['tinymce-#{frame_id}'].setContent('#{options[:with]}')})
end
@nowk
nowk / capybara_helpers.rb
Last active June 10, 2016 01:07
Capybara waits for AJAX (angular & jquery)
def wait_for_ajax(timeout = 5) #Timeout in seconds
page.wait_until(timeout) do
page.evaluate_script "angular.element.active == 0 && jQuery.active == 0"
end
end
@nowk
nowk / user.rb
Last active May 2, 2021 09:32
Devise #update_with_password
class User < ActiveRecord::Base
def update_with_password(params, *options)
_current_password = params[:current_password]
_password = params[:password]
_password_confirmation = params[:password_confirmation]
unless _current_password.blank?
if _password.blank?
errors.add(:password, "can't be blank")
false
else
private
def force_ssl
if Rails.env.production?
if !request.ssl?
redirect_to :protocol => 'https'
end
end
end
@nowk
nowk / Gemfile
Last active December 15, 2015 01:49 — forked from rmoriz/Gemfile
UUID as Primary Key
# Gemfile
gem 'uuidtools'
@nowk
nowk / gist:5215905
Created March 21, 2013 19:26
angularjs module
angular.module("app.Standards", [])
.config(function($httpProvider, $locationProvider) {
$locationProvider.html5Mode(false);
$locationProvider.hashPrefix('!');
$httpProvider.defaults.headers.
common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
})
class TablelessModel
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
def initialize(attributes = {})
attributes.try(:each) do |name, value|
send("#{name}=", value)
end
end