This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate the sum of all elements in an array | |
def sum(array) | |
array.inject{|sum, e| sum + e} | |
end | |
# or i can use shortcut | |
def sum(array) | |
array.inject(:+) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Calculate the sum of largest 2 elements of an array. | |
def max_2_sum(arr) | |
arr.inject([0, 0]) do |largest, el| | |
if largest[0] < el | |
largest[1] = largest[0] | |
largest[0] = el | |
elsif largest[1] < el | |
largest[1] = el | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ pairing git:(master) vagrant up | |
Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed. | |
Vagrant uses the `VBoxManage` binary that ships with VirtualBox, and requires | |
this to be available on the PATH. If VirtualBox is installed, please find the | |
`VBoxManage` binary and add it to the PATH environmental variable. | |
➜ pairing git:(master) vagrant up | |
Bringing machine 'default' up with 'virtualbox' provider... | |
[default] Box 'raring-minimal' was not found. Fetching box from specified URL for | |
the provider 'virtualbox'. Note that if the URL does not have | |
a box for this provider, you should interrupt Vagrant now and add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'yaml' | |
# DATA is a little-used feature of the Ruby language; it's a file handle | |
# whose contents are everything in the current file after the __END__. | |
# YAML is "Yet Another Markup Language". | |
data = YAML.load(DATA) | |
def url_for(entry_num) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
var o = $( {} ); | |
$.each({ | |
on: 'subscribe', | |
trigger: 'publish', | |
off: 'unsubscribe' | |
}, function(key, api) { | |
$[api] = fiunction(){ | |
o[key].apply(o, arguments); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A new way to use an image replacment without using text indent to form a box way off the screen | |
ir{ | |
border: 0; | |
font: 0/0; | |
text-shadow: none; | |
color: transparent; | |
background-color: transparent; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ = window.jQuery; | |
var html = '' + | |
' <form action="//www.instapaper.com/bookmarklet/post_v5" method="post" id="instapaper"> \ | |
<input type="hidden" name="p" value=""/> \ | |
<input type="hidden" name="b" id="b" value=""/> \ | |
</form>'; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------- | |
// A short snippet for detecting versions of IE in JavaScript | |
// without resorting to user-agent sniffing | |
// ---------------------------------------------------------- | |
// If you're not in IE (or IE version is less than 5) then: | |
// ie === undefined | |
// If you're in IE (>=5) then you can determine which version: | |
// ie === 7; // IE7 | |
// Thus, to detect IE: | |
// if (ie) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# A complete URL-shortening web application, written in Ruby/Sinatra. Run it | |
# from the command line, and then visit http://localhost:4567/ | |
# | |
# Or to run it under apache/passenger, you'll need a config.ru file with the | |
# following contents: | |
# | |
# require 'tinyurl' | |
# run Sinatra::Application |
NewerOlder