Skip to content

Instantly share code, notes, and snippets.

View DonSchado's full-sized avatar
🐢
null

Marco DonSchado

🐢
null
View GitHub Profile
@DonSchado
DonSchado / example_spec.rb
Last active December 22, 2015 20:18
Thoughtbot retracted their initial implementation of strong parameters matchers in v2.0.0 of shoulda-matchers, so we decided to build our own until new official ones are released. The following is a small matcher for testing what params should be permitted in controllers. The matcher's syntax is based on validation matchers. If you're not follow…
# assuming your subject is the UsersController with a method user_params
describe UsersController do
describe "params" do
# per default the matcher extracts the subject and params method
it { should permit_params(:email, :name, :role) }
# to overwrite the params method use explicit .params_method()
it { should permit_params(:first_name, :last_name).params_method(:other_user_params) }
@DonSchado
DonSchado / gist:3499614
Created August 28, 2012 16:10 — forked from brumm/gist:3437594
sublime shortcuts
# expand selection to word, create new selection
cmd + d
# skip over a match
cmd + k, d
# expand selection to all matches
cmd + ctrl + g
@DonSchado
DonSchado / card_deck.rb
Created June 29, 2012 17:22
A deck of cards in ruby
suits = %w{s h d c}
ranks = %w{2 3 4 5 6 7 8 9 T J Q K A}
deck = suits.product(ranks)
def pull_card
deck.sample
end
@DonSchado
DonSchado / protocol_adapter.rb
Created January 8, 2012 14:04
Adapter method that pulls the destination protocol off of the message (...) and add a new adapter
def adapter_for(message)
protocol = message.to.scheme.downcase
adapter_name = "#{protocol.capitalize}Adapter"
adapter_class = self.class.const_get(adapter_name)
adapter_class.new
end
@DonSchado
DonSchado / clickable-button-group.js
Created November 19, 2011 17:39
When a button is clicked, the selected class is removed from all other buttons and will be added it to the one clicked.
$('div.button a.available').click(function(e){
e.preventDefault();
$('a').removeClass('selected');
$(this).addClass('selected');
});
@DonSchado
DonSchado / Three_State_Button.js
Created November 19, 2011 11:08
Add a click event listener on each of the button links. When clicked each toggle the class 'selected'. event.preventDefault stops the browser from following the link
$(document).ready(function(){
$('a.button').click(
function(event){
event.preventDefault();
$(this).toggleClass('selected');
});
});
@DonSchado
DonSchado / sort_stings.rb
Created October 26, 2011 18:05
Given a string "Sort words in a sentence", it should return "a in Sort words sentence".
def sort_string(string)
string.split(' ').sort{|x, y| x.length <=> y.length}.join(' ')
end
@DonSchado
DonSchado / find_and_count_words.rb
Created October 26, 2011 17:48
Given a sentence containing multiple words, find the frequency of a given word in that sentence.
def find_frequency(sentence, word)
sentence.downcase.split.count(word.downcase)
end
@DonSchado
DonSchado / gist:1173079
Created August 26, 2011 09:43
Step through your Cucumber features one step at a time, tag any feature with "@Pause"
#via rubyquicktips
AfterStep('@pause') do
print "Press Return to continue..."
STDIN.getc
end
@DonSchado
DonSchado / apple.html
Created August 24, 2011 08:34 — forked from marklit/apple.html
Apple Icon HTML header example
<link rel="apple-touch-icon" href="img/apple-touch-icon.png"> <!-- 57x57 -->
<link rel="apple-touch-icon" sizes="72x72" href="img/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="img/apple-touch-icon-114x114.png">