Skip to content

Instantly share code, notes, and snippets.

View scottbartell's full-sized avatar
👋

Scott Bartell scottbartell

👋
View GitHub Profile
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@bowsersenior
bowsersenior / stooge_loader.rb
Created May 18, 2011 23:18
A demo of YAML anchors, references and nested values
require 'rubygems'
require 'yaml'
# A demonstration of YAML anchors, references and handling of nested values
# For more info, see:
# http://atechie.net/2009/07/merging-hashes-in-yaml-conf-files/
stooges = YAML::load( File.read('stooges.yml') )
# => {
# "default" => {
@zaius
zaius / open_uri.rb
Created October 7, 2011 21:46
Allow open-uri to follow unsafe redirects (i.e. https to http)
# Allow open-uri to follow unsafe redirects (i.e. https to http).
# Relevant issue:
# http://redmine.ruby-lang.org/issues/3719
# Source here:
# https://github.com/ruby/ruby/blob/trunk/lib/open-uri.rb
module OpenURI
class <<self
alias_method :open_uri_original, :open_uri
alias_method :redirectable_cautious?, :redirectable?
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
// good javascript
(function ($) {
'use strict';
$(function () {
$('[placeholder]')
.focus(function () {
var input = $(this);
if (input.val() === input.attr('placeholder')) {
@reneras
reneras / spin.js
Created July 13, 2012 11:02
Lightweight HTML5 canvas spinner / loader
/*
* <html>
* <head>
* </head>
* <body>
* <canvas id="demo" height="400" width="400" style="background:#000;"></div>
* </body>
* </html>​
*
*/
@traviskroberts
traviskroberts / rake.rb
Created January 17, 2013 15:57
Rspec shared context for testing rake tasks.
require "rake"
shared_context "rake" do
let(:rake) { Rake::Application.new }
let(:task_name) { self.class.top_level_description }
let(:task_path) { "lib/tasks/#{task_name.split(":").first}" }
subject { rake[task_name] }
def loaded_files_excluding_current_rake_file
$".reject {|file| file == Rails.root.join("#{task_path}.rake").to_s }
# app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
# ...
def create
user = User.authenticate(params[:username], params[:password])
if user
session[:user_id] = user.id
@harlow
harlow / user.rb
Last active November 16, 2023 15:13
Extract a validator in Rails. Zip code validation.
# app/models/user.rb
class User < ActiveRecord::Base
validates :zip_code, presence: true, zip_code: true
end
@bradland
bradland / 000-sftp.rb
Last active August 8, 2018 02:33
Net::SFTP test script. Fails when downloading files larger than 4 GB
#!/usr/bin/env ruby
require 'net/sftp'
@host = 'localhost'
@user = 'username'
@password = 'password'
@remote_dir = '/source/path/goes/here'
@remote_file_name = 'test-data.txt'
@tmp_dir = '/destination/path/goes/here'
@zekefast
zekefast / postgresql.conf
Last active December 31, 2022 19:04
PostgreSQL configuration tuning to improve tests performance of database interactions.
# PostgreSQL configuration tuning to improve tests performance of database interactions.
# Look for more detailed description in follow articles:
# - http://rhaas.blogspot.com/2010/06/postgresql-as-in-memory-only-database_24.html
#
# ATTENTION:
# Before appling those settings ensure that you have no important data in your cluster, because those settings
# could cause problems on your production database in case of appliance.
#
# Ensure follow settings have given values.