Skip to content

Instantly share code, notes, and snippets.

Ken Collins metaskills

Block or report user

Report or block metaskills

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@metaskills
metaskills / gist:2836849
Created May 30, 2012
Basic Save & Open Page For Poltergeist
View gist:2836849
def save_and_open_page
dir = "#{Rails.root}/tmp/cache/capybara"
file = "#{dir}/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.png"
FileUtils.mkdir_p dir
page.driver.render file
wait_until { File.exists?(file) }
system "open #{file}"
end
@metaskills
metaskills / bm.rb
Created Aug 1, 2017
Simple SQL Server & PG Rails Benchmarks.
View bm.rb
#!/usr/bin/env ruby
require 'benchmark'
require 'bundler/inline'
gemfile true do
source 'https://rubygems.org'
gem 'activerecord-sqlserver-adapter', ENV['VER_AR'] || '~> 5.1.0'
gem 'tiny_tds', ENV['VER_TTDS'] || '~> 2.0.0'
gem 'pg'
@metaskills
metaskills / gitio.sh
Last active Aug 29, 2017
Shell Function for Git.io
View gitio.sh
gitio () {
local url=$(curl -s -i https://git.io -F "url=$1" | grep "Location: " | cut -d" " -f2)
echo -n $url | tr -d '\n' | pbcopy
echo $url
}
@metaskills
metaskills / transaction_fixtures.rb
Created Oct 20, 2015
Rails 4.2 Capybara Transactional Fixtures Example.
View transaction_fixtures.rb
class ActiveRecord::Base
CONNECTION_LOCK = Mutex.new
def self.connection ; CONNECTION_LOCK.synchronize { @@shared_base_connection ||= retrieve_connection } ; end
end
View 0-readme.md
@metaskills
metaskills / output.txt
Created Feb 22, 2017
Test FreeTDS Connection
View output.txt
$ tsql -S localhost -U sa -P $SA_PASSWORD
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> SELECT @@VERSION
2> GO
Microsoft SQL Server vNext (CTP1.3) - 14.0.304.138 (X64)
Feb 13 2017 16:49:12
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
@metaskills
metaskills / vcr_helper.rb
Created Jun 19, 2017
Per-Service VCR Cassettes - Reuse Common API Requests Across Your App's Tests
View vcr_helper.rb
# This assumes you have a client with a URL config. Hard coded URLs work too.
# Will automiatically insert cassets whenever needed and organize them per servcie.
#
VCR.configure do |c|
c.around_http_request do |request|
if request.uri =~ Regexp.new(MyServiceClient.config.url)
VCR.use_cassette 'my_service', default_cassette_options, &request
else
request.proceed
end
@metaskills
metaskills / prepend.rb
Created May 11, 2017
Using Module Prepend To Extend Ruby Classes
View prepend.rb
class Foo
attr_reader :bar
def initialize
@bar = 'bar'
end
end
module Bar
def bar
super.upcase
View demo.scss
$my-color-names: ( 'inchworm', 'sunglow', 'scarlet');
$my-colors: ( #a5de37, #ffd426, #ff4351 );
@each $name in $my-color-names {
$index: index($my-color-names, $name);
$color: nth($my-colors, $index);
%my-#{$name}-background-color { background-color: $color; }
%my-#{$name}-border-color { border-color: $color; }
}
View crud.rb
require 'tiny_tds'
puts 'Connecting to SQL Server'
@client = TinyTds::Client.new(
host: 'localhost', port: 1433,
username: 'sa', password: ENV['SA_PASSWORD'],
database: 'SampleDB'
)
def execute(sql)
@client.execute(sql).do
You can’t perform that action at this time.