Skip to content

Instantly share code, notes, and snippets.

View tsevdos's full-sized avatar
🏠
Working from home

John Tsevdos tsevdos

🏠
Working from home
View GitHub Profile
@tsevdos
tsevdos / example_1.rb
Created September 13, 2015 10:58
Ruby tips : Parallel Assignment of Variables
a, b, c = 50, 'cent', :test
# a => 50
# b => 'cent'
# c => :test
@tsevdos
tsevdos / example.rb
Created September 13, 2015 11:03
Ruby tips : Here Documents
name = 'John'
# default acts as double-quoted string
puts <<heredoc
Hello #{name}
other line 1,
other line 2.
heredoc
# double-quoted string
@tsevdos
tsevdos / comparison_and_ranges.rb
Created September 13, 2015 11:12
Ruby tips : Ranges
(1..10) === 4 # => true
(1...10) === 10 # => false
@tsevdos
tsevdos / example.rb
Created September 13, 2015 11:15
Ruby tips : Default arguments
def hello(name = "world")
puts "hello #{name}!"
end
hello # => hello world!
hello('John') # => hello John!
@tsevdos
tsevdos / example.rb
Created September 13, 2015 11:19
Ruby tips : block_given? on yields
def yo
if block_given?
yield
else
puts "No block :-("
end
end
yo # => No block :-(
yo { puts "Yo man" } # => Yo man
@tsevdos
tsevdos / assign_value.rb
Created September 13, 2015 11:23
Ruby tips : Case statement
lang = 'en'
welcome_msg = case lang
when 'en' then 'welcome'
when 'de' then 'willkommen'
when 'fr' then 'bienvenue'
when 'de' then 'bienvenida'
else 'yo'
end
@tsevdos
tsevdos / chaining1.js
Created January 2, 2012 09:36
jQuery tips: Chaining
$('<div id="test"><p><a>John</a></p></div>').find('a').attr('href' , 'http://phrappe.com/').end().appendTo('body');
@tsevdos
tsevdos / content-based-selection.js
Created January 2, 2012 09:40
jQuery tips: Select elements based on their content
<p>Hello World!</p> // Markup $('p:contains("Hello")');
@tsevdos
tsevdos / replace-dom-elements.js
Created January 2, 2012 09:42
jQuery tips: Replace DOM elements
$('li.old').replaceWith('<li>new li</li>');
@tsevdos
tsevdos / context1.js
Created January 2, 2012 09:26
jQuery tips: Specify a context
$('h1', 'div#posts'); //using jQuery wrapper as context