Skip to content

Instantly share code, notes, and snippets.

View hron's full-sized avatar
:atom:

Aleksei Gusev hron

:atom:
  • Software Developer at @forenom
  • Helsinki, Finland
View GitHub Profile
login: &login
adapter: mysql
username: root
password:
host: localhost
development:
<<: *login
database: app_dev
common: &common
adapter: mysql
dev: &dev
<<: *common
username: root
<% if File.exist? "/opt/local/var/run/mysql5/mysqld.sock" %>
socket: /opt/local/var/run/mysql5/mysqld.sock
<% elsif File.exist? "/tmp/mysql.sock" %>
socket: /tmp/mysql.sock
#################################################################################
# CAPISTRANO TAG SUPPORT
# Provides the ability for capistrano to check out into a named tags directory
# Also makes sure that the releases array is properly ordered (not by name but by
# modification date). This enables proper rollbacks.
#
# Author: yan@planyp.us
#
# Requirements:
# set :tag_root, "tags" # where your tags are in relation to trunk/..

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@javascript
Scenario: confiming when saving inactive
Given I expect to click "OK" on a confirmation box saying "Are you sure?"
When I press "Save"
Then the confirmation box should have been displayed
And I should see "TV" in the "Campaign Keywords" section
# Add this to more_web_steps.rb
# Selenium docs: http://code.google.com/p/selenium/wiki/RubyBindings#Javascript_Alert/Confirm today!
When /^I (accept|dismiss) the "([^"]*)" alert$/ do |action, text|
alert = page.driver.browser.switch_to.alert
alert.text.should eq(text)
alert.send(action)
end
@hron
hron / gist:987084
Created May 23, 2011 17:17
Paradox Monty-Hall
#! /usr/bin/env ruby
require 'logger'
require 'pp'
class ThreeBoxGame
def initialize(options = {})
@double_choice = options[:double_choice] || false
@boxes = %w(1 2 3)
@hron
hron / config.rb
Created June 24, 2011 13:37
application config in yaml
config = YAML.load_file("#{Rails.root}/config/config.yml")
APP_CONFIG = HashWithIndifferentAccess.new(config[Rails.env])
Function Set-ScreenResolution {
param (
[Parameter(Mandatory=$true,
Position = 0)]
[int]
$Width,
[Parameter(Mandatory=$true,
Position = 1)]
[int]
$Height