Skip to content

Instantly share code, notes, and snippets.

View douglogue's full-sized avatar

Doug Logue douglogue

View GitHub Profile
@douglogue
douglogue / goToByScroll.js
Created October 22, 2013 14:40
Smooth scroll to in-page elements
<script>
$(document).ready(function(){ $('a').click(function(){ goToByScroll($(this).attr('href')); return false; }); });
function goToByScroll(id){ $('html,body').animate({scrollTop: $(id).offset().top},'slow'); }
</script>
class Party
{
var time: NSDate
var location: CGPoint
var guests: Array
// ...
}
class Guest
// Here we explicitly specify the type
var beverage: String = "Leffe"
// But the type can also be inferred from the fact that we're assigning it a String value
var name = "Leffe"
// vars
var mutableBeverage = "Leffe"
println(mutableBeverage) // "Leffe"
mutableBeverage = "Bud"
println(mutableBeverage) // "Bud"
mutableBeverage = mutableBeverage + "weiser"
println(mutableBeverage) // "Budweiser"
// Non-optional vars
var mutableBeverage = "Leffe"
println(mutableBeverage) // "Leffe"
mutableBeverage = "Bud"
println(mutableBeverage) // "Bud"
mutableBeverage = mutableBeverage + "weiser"
println(mutableBeverage) // "Budweiser"
NSString *costume = @"Dracula";
// ...
if (costume == nil) {
// Do something for this plain clothes guest
} else {
// Do something else for this costumed guest
}
var costume: String? = "Werewolf"
println(costume) // Optional("Werewolf")
costume = costume + " dressed as Michael J Fox" // Compiler Error
if let something = costume {
// The value is not nil, use it with confidence
something = something + " dressed as Michael J Fox"
println(something) // "Werewolf dressed as Michael J Fox"
} else {
var costume: String? = "Werewolf"
println(costume) // Optional("Werewolf")
costume = costume! + " dressed as Michael J Fox"
println(costume) // Optional("Werewolf dressed as Michael J Fox")
toppings = %w(pepperoni mushroom bacon pineapple)
def pizza(toppings)
toppings.each do |topping|
puts "I love #{topping} pizza!"
end
end