Skip to content

Instantly share code, notes, and snippets.

View kevinthompson's full-sized avatar
🕹️

Kevin Thompson kevinthompson

🕹️
View GitHub Profile
@kevinthompson
kevinthompson / SassMeister-input-HTML.html
Created December 9, 2013 18:34
Generated by SassMeister.com.
<div id="people-show">
<div class="person">
<h1>This is a Person</h1>
</div>
</div>
<div id="plans-show">
<div class="plan">
<h1>This is a Plan</h1>
</div>
@kevinthompson
kevinthompson / commented_regex.rb
Last active December 19, 2015 15:38
An example of a commented regex block encapsulated in a method.
def email_pattern
%r{
^[A-Z0-9._%+-]+ # Beginning with one or more valid characters (letters, numbers, period, etc.)
@ # A literal "at" sign
[A-Z0-9.-]+ # One or more letters, numbers, period, or dash
\. # A literal period
[A-Z]{2,4}$ # Ending with a two to four character text domain extension
}ix # Flags: Ignore whitespace and ignore letter case
end
@kevinthompson
kevinthompson / proc_to_block.rb
Created July 6, 2013 17:46
Unary Ampersand Example: Proc to Block
items = {
'a' => 'aardvark',
'b' => 'banana',
'c' => 'cookies',
'd' => 'dog'
}
criteria = Proc.new { |key, value| value == 'banana' }
items.select(&criteria) # => {"b"=>"banana"}
items.reject(&criteria) # => {"a"=>"aardvark", "c"=>"cookies", "d"=>"dog"}
@kevinthompson
kevinthompson / example.rb
Last active December 18, 2015 13:19
Submit an ASP.net form by clicking a WebForm link using Mechanize.
require 'mechanize'
# Fetch the home page
browser = Mechanize.new
home_page = browser.get('https://www.example-aspnet-site.com/')
# Fill out the login form
login_form = home_page.forms.first
login_form.field_with(:name => /UserName/i).value = ARGV[0]
login_form.field_with(:name => /Password/i).value = ARGV[1]
@kevinthompson
kevinthompson / 2013-06-06-sdruby-heroku-fu.md
Last active December 18, 2015 04:39
Notes from @gkparishphilp's Heroku-Fu talk at SD Ruby; June 6, 2013

Heroku-Fu

By: Gk Parish-Philp
Date: June 6th, 2013

Tips and tricksto get the most out of Heroku

  1. Beginnings
  2. Why Heroku
@kevinthompson
kevinthompson / embed.js
Created March 19, 2013 20:45
Resize iFrame Example
document.write('<iframe src="iframe.html" id="unique-id" onload="resizeIframe();" />')
function resizeIframe() {
document.getElementById('unique-id').style.height = document.getElementById('unique-id').contentWindow.document.body.offsetHeight + 'px';
}
@kevinthompson
kevinthompson / person.rb
Created January 19, 2013 18:49
A quick example of how you might work with the Nike+ API. You'll need to get your own access key at https://developer.nike.com/console to test this code.
require 'httparty'
APP_ID = 'nike'
BASE_URL = 'https://api.nike.com'
class Person
def initialize(access_token)
self.access_token = access_token
end
@kevinthompson
kevinthompson / extract_factories.rb
Last active December 10, 2015 21:38
Convert a single FactoryGirl factory file into a directory of factories.
#!/usr/bin/env ruby
require 'fileutils'
# Set Source and Destination
source = ARGV[0] || "#{Dir.pwd}/spec/factories.rb"
destination = ARGV[1] || "#{Dir.pwd}/spec/factories/"
# Verify Source and Destination Exist
puts '! Source file does not exist.' unless File.exists?(source)
FileUtils.mkpath destination unless File.directory?(destination)
@kevinthompson
kevinthompson / border.sass
Created December 16, 2012 19:25
SASS Border Shorthand Mixin
// Border Shorthand
// -------------------------
=border($border: false, $border_horizontal: false, $border_bottom: false, $border_left: false)
$args: length($border)
// Reset Variables Based on Argument Count
@if $args > 1 and length(nth($border,1)) > 1 or nth($border,1) == none
@if $args == 4
$border_left: nth($border, 4)
@kevinthompson
kevinthompson / model.js.coffee
Last active October 13, 2015 15:48
Supporting Rails Nested Resources in Batman.js
class App.Model extends Batman.Model
@persist App.Storage
@encodeAttributesFor: ->
@encodeAttributesForKeys ?= []
for key in arguments
if typeof key == 'string'
@encodeAttributesForKeys.splice(index,1) if (index = @encodeAttributesForKeys.indexOf(key)) > 0
@encodeAttributesForKeys.push key