Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

John Tsevdos tsevdos

🏠
Working from home
View GitHub Profile
@tsevdos
tsevdos / example_1.rb
Created Sep 13, 2015
Ruby tips : Parallel Assignment of Variables
View example_1.rb
a, b, c = 50, 'cent', :test
# a => 50
# b => 'cent'
# c => :test
@tsevdos
tsevdos / example.rb
Created Sep 13, 2015
Ruby tips : Here Documents
View example.rb
name = 'John'
# default acts as double-quoted string
puts <<heredoc
Hello #{name}
other line 1,
other line 2.
heredoc
# double-quoted string
View comparison_and_ranges.rb
(1..10) === 4 # => true
(1...10) === 10 # => false
@tsevdos
tsevdos / example.rb
Created Sep 13, 2015
Ruby tips : Default arguments
View example.rb
def hello(name = "world")
puts "hello #{name}!"
end
hello # => hello world!
hello('John') # => hello John!
@tsevdos
tsevdos / example.rb
Created Sep 13, 2015
Ruby tips : block_given? on yields
View example.rb
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 Sep 13, 2015
Ruby tips : Case statement
View assign_value.rb
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 Jan 2, 2012
jQuery tips: Chaining
View chaining1.js
$('<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 Jan 2, 2012
jQuery tips: Select elements based on their content
View content-based-selection.js
<p>Hello World!</p> // Markup $('p:contains("Hello")');
@tsevdos
tsevdos / replace-dom-elements.js
Created Jan 2, 2012
jQuery tips: Replace DOM elements
View replace-dom-elements.js
$('li.old').replaceWith('<li>new li</li>');
@tsevdos
tsevdos / context1.js
Created Jan 2, 2012
jQuery tips: Specify a context
View context1.js
$('h1', 'div#posts'); //using jQuery wrapper as context