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
require File.expand_path("../production.rb", __FILE__)
RailsAppName::Application.configure do
config.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Staging") do |u, p|
[u, p] == [ENV['STAGING_USERNAME'], ENV['STAGING_PASSWORD']]
end
config.action_mailer.default_url_options = { :host => 'some-app.herokuapp.com' }
config.action_mailer.asset_host = ""
end
@nowk
nowk / angularjs_steps.rb
Last active December 20, 2015 14:39
Capybara JS quirks using angular.js and/or turbolinks
step %{I save a task without the required fields} do
within_task_form do
# NOTE filling with '' won't work as it does not trigger keypress events
# and thus breaks angular bindings
fill_in 'task_name', with: ' '
end
step %{I save the task}
end
@nowk
nowk / app.js.coffee
Last active December 21, 2015 00:49
Column sort arrow directive
.controller 'CollectionsController', ($scope) ->
$scope.sort_column = 'created_at'
$scope.sort_order = 'DESC'
current_sort_order = $scope.sort_order
$scope.sort_by_column = (column) ->
$scope.sort_order = 'ASC'
$scope.sort_order = 'DESC' if $scope.sort_column == column && current_sort_order == 'ASC'
(function(XHR) {
"use strict";
var stats = [];
var timeoutId = null;
var open = XHR.prototype.open;
var send = XHR.prototype.send;
require "timeout"
module WaitSteps
extend RSpec::Matchers::DSL
matcher :become_true do
match do |block|
begin
Timeout.timeout(Capybara.default_wait_time) do
sleep(0.1) until value = block.call
# add this file capybara_wait_until.rb to your /test directory
module Capybara
class Session
##
#
# Retry executing the block until a truthy result is returned or the timeout time is exceeded
#
# @param [Integer] timeout The amount of seconds to retry executing the given block
#
@nowk
nowk / proxy.rb
Created August 24, 2013 03:01 — forked from torsten/proxy.rb
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009 Torsten Becker <[email protected]>
require 'socket'
require 'uri'
@nowk
nowk / gist:6375620
Created August 29, 2013 08:33 — forked from Arcath/gist:481321
def gravatar_url(email,options = {})
require 'digest/md5'
hash = Digest::MD5.hexdigest(email)
url = "http://www.gravatar.com/avatar/#{hash}"
options.each do |option|
option == options.first ? url+="?" : url+="&"
key = option[0].to_s
value = option[1].to_s
url+=key + "=" + value
end
# add this file capybara_wait_until.rb to your /test directory
module Capybara
class Session
##
#
# Retry executing the block until a truthy result is returned or the timeout time is exceeded
#
# @param [Integer] timeout The amount of seconds to retry executing the given block
#
@nowk
nowk / closure.js
Created April 14, 2014 15:47
Javascript Closure practice
/* jshint node: true */
var assert = require("assert");
/*
* fn
*
* @return {Function}
*/