$ rails g model User
belongs_to
has_one
| # Create a file `spec/acceptance/support/warden.rb' with the following | |
| # contents: | |
| Spec::Runner.configure do |config| | |
| config.include Warden::Test::Helpers, :type => :acceptance | |
| config.after(:each, :type => :acceptance) { Warden.test_reset! } | |
| end | |
| # Or, if you're using RSpec 2 / Rails 3, the contents should be the following | |
| # instead: |
| require 'rubygems' | |
| require 'curb' | |
| require 'benchmark' | |
| loop do | |
| resp = nil | |
| t = Benchmark.measure { | |
| resp = Curl::Easy.perform(ARGV[0]) | |
| } | |
| puts "#{resp.response_code} : #{t}" |
| class BackgroundSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy | |
| class <<self | |
| def async? | |
| !!Thread.current[:background_session_proxy_async] | |
| end | |
| def with_async | |
| self.async = true | |
| begin | |
| yield |
| =begin | |
| Need to install gems heroku, newrelic_rpm | |
| $ gem install heroku newrelic_rpm | |
| Set your apps setting | |
| app_name : heroku's app_name of auto scaling | |
| license_key : NewRelic api key. You can get heroku's NewRelic admin console. "App setting" and "Agent configuration" | |
| execute with cron every minutes | |
| $ ruby ./adjust_dynos_with_newrelic.rb |
| var flattenObject = function(ob) { | |
| var toReturn = {}; | |
| for (var i in ob) { | |
| if (!ob.hasOwnProperty(i)) continue; | |
| if ((typeof ob[i]) == 'object') { | |
| var flatObject = flattenObject(ob[i]); | |
| for (var x in flatObject) { | |
| if (!flatObject.hasOwnProperty(x)) continue; |
| # WAIT! Do consider that `wait` may not be needed. This article describes | |
| # that reasoning. Please read it and make informed decisions. | |
| # https://www.varvet.com/blog/why-wait_until-was-removed-from-capybara/ | |
| # Have you ever had to sleep() in Capybara-WebKit to wait for AJAX and/or CSS animations? | |
| describe 'Modal' do | |
| should 'display login errors' do | |
| visit root_path |
| #!/usr/bin/env ruby | |
| # A simply utility to show character counts for each line of input and | |
| # highlight lines longer than 80 characters. | |
| # | |
| # Written as an example for http://jstorimer.com/2011/12/12/writing-ruby-scripts-that-respect-pipelines.html | |
| # | |
| # Examples: | |
| # | |
| # $ hilong Gemfile |
| #!/usr/bin/env python | |
| import os | |
| import random | |
| import time | |
| import platform | |
| snowflakes = {} | |
| try: | |
| # Windows Support |
| #!/usr/bin/env ruby | |
| =begin | |
| = Geographic Searches With Postgres's Earthdistance and Cube Extensions | |
| This program shows how to easily create a Postgres database that uses the Cube | |
| and Earthdistance extensions to perform fast queries on geographic data. | |
| Briefly, the problem this code solves is "show me all places within 50 | |
| kilometers of New York City." |