This file contains hidden or 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
def detect_collision(number) | |
guessed_numbers = {} | |
count = 0 | |
collision = false | |
while !collision | |
guess = rand(number) | |
count += 1 | |
if guessed_numbers[guess] |
This file contains hidden or 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 | |
puts "Starting..." | |
branches = `git branch --merged`.split("\n").map { |branch| branch.strip } | |
pattern = (ARGV.shift || `whoami`).strip | |
branches.select! { |branch| branch.match(pattern) } | |
count = branches.size |
This file contains hidden or 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
# Q: How do I make something happen 25% of the time | |
# A: rand(4) == 0 | |
# How? | |
results = Hash.new(0) | |
10_000.times do | |
results[rand(4)] += 1 | |
end |
This file contains hidden or 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 sh | |
if [[ "$1" && "$2" ]]; then | |
tmp='tmp.gif' | |
ffmpeg -i $1 -pix_fmt rgb24 $tmp | |
convert -layers Optimize $tmp $2 | |
rm $tmp | |
else | |
echo "usage: gifify <input.mov> <output.gif>" | |
fi |
This file contains hidden or 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
~/tmp% echo "Hello World" > file1.txt | |
~/tmp% echo "Hello World" > file2.txt | |
~/tmp% shasum file1.txt | |
648a6a6ffffdaa0badb23b8baf90b6168dd16b3a file1.txt | |
~/tmp% shasum file2.txt | |
648a6a6ffffdaa0badb23b8baf90b6168dd16b3a file2.txt | |
~/tmp% md5 file1.txt | |
MD5 (file1.txt) = e59ff97941044f85df5297e1c302d260 | |
~/tmp% md5 file2.txt | |
MD5 (file2.txt) = e59ff97941044f85df5297e1c302d260 |
This file contains hidden or 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
brew install ruby-build | |
==> Installing ruby-build dependency: rbenv | |
==> Downloading https://github.com/sstephenson/rbenv/tarball/v0.3.0 | |
######################################################################## 100.0% | |
Warning: The cleaning step did not complete successfully | |
Still, the installation was successful, so we will link it into your prefix | |
==> Caveats | |
To enable shims and autocompletion add to your profile: | |
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi |
This file contains hidden or 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
def tax_brackets(salary) | |
current = salary | |
total = 0 | |
if salary > 8_700 | |
total += 8_700 * 0.10 | |
else | |
return salary * 0.10 | |
end |
This file contains hidden or 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
require 'bundler' | |
Bundler.setup(:assets) | |
require 'rake-pipeline-web-filters' | |
RequireFilter = Rake::Pipeline::Web::Filters::NeuterFilter | |
REQUIRE_REGEX = %r{//= require (.*)} | |
output 'public' | |
load_paths = ['app/assets/javascripts', 'vendor/assets/javascripts'] |
This file contains hidden or 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
class Foo | |
protected | |
def protected_method | |
puts "protected method" | |
end | |
private |
This file contains hidden or 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
alias foo Foo Bar <[email protected]> |