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: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
@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'
# 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
#
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
(function(XHR) {
"use strict";
var stats = [];
var timeoutId = null;
var open = XHR.prototype.open;
var send = XHR.prototype.send;
@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'
@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
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 / aws_S3.rb
Last active December 20, 2015 06:39
Amazon S3 request generator class
class AwsS3
AWS_ACCESS_KEY = ENV['AWS_ACCESS_KEY_ID']
AWS_SECRET_KEY = ENV['AWS_SECRET_ACCESS_KEY']
S3_BUCKET = ENV['S3_BUCKET'] || "#{Rails.application.class.parent_name}_#{Rails.env}".downcase
attr_accessor :file_name, :mime_type, :path, :acl, :expires_in
attr_writer :as_attachment
def initialize(file_name, mime_type, acl: 'private', path: '/')
@file_name = esc file_name # escape for spaces and the like
@nowk
nowk / formtastic-inline-errors.js.coffee
Last active December 19, 2015 02:09
Angular.js directive for inline form errors when using Formtastic
angular.module("app", [])
.directive 'formtasticInlineErrors', ($compile) ->
return {
restrict: 'A'
link: (scope, element, attrs) ->
scope.$on 'event:form-FormErrors', (evt, model_name, errors) ->
element.find('.input .inline-error').remove()
if !errors? || errors.length == 0
else