Skip to content

Instantly share code, notes, and snippets.

View DonSchado's full-sized avatar
🐢
null

Marco DonSchado

🐢
null
View GitHub Profile
@DonSchado
DonSchado / render_or_redirect.rb
Created June 8, 2014 19:11
an experiment for open discussion, to eliminate duplicate controller logic
# eliminate all the duplication
def render_or_redirect(_action, _path, &block)
if block.call
redirect_to _path, success: I18n.t('common.success')
else
flash.now[:alert] = I18n.t('common.error')
render _action
end
end
@DonSchado
DonSchado / layer-css
Created November 23, 2014 07:00
Different depth of nodes will use different colour allowing you to see the size of each element on the page, their margin and their padding. Now you can easily identify inconsistencies.
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
@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">
@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 / 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 / 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 / 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 / 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 / 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 / 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