Skip to content

Instantly share code, notes, and snippets.

@mkoby
mkoby / 001_ruby_methods.rb
Created March 30, 2012 19:50
Intro to Ruby - 05 - Methods
## Basic Method
def say_hello
puts “Hello”
end
hello # => Hello
## Method with an argument
def say_hello_to(name)
puts “Hello, #{name}”
@mkoby
mkoby / Each_loop.rb
Created March 16, 2012 21:00
Intro to Ruby - 04 - Flow Control
names = ["Michael", "John", "Paul", "George"]
names.each do |name|
puts "Hi, my name is #{name}"
end
# Result:
# Hi, my name is Michael
# Hi, my name is John
# Hi, my name is Paul
@mkoby
mkoby / Arrays.rb
Created March 16, 2012 20:46
Intro to Ruby - 03 - Arrays & Hashes
# Basic Array
my_array = [1, 2, 3, 4, 5]
# Ruby arrays are zero-based arrays,
# meaning the first element is at index 0
my_array[1] # => 2
my_array[0] # => 1
# Except when you do negative indexes
my_array[-2] # => 4
@mkoby
mkoby / Strings_Quotes.rb
Created March 16, 2012 20:35
Intro to Ruby - 02 - The String Addendum
# Double Quotes
double_quotes = "Here be double quotes"
# Single Quotes
single_quotes = 'Here be single quotes'
# Intermixing Quotes
'Sam said, "Never give up, never surrender"'
"Sam told me to read the book, 'Brave New World'"
@mkoby
mkoby / Numbers.rb
Created March 16, 2012 19:55
Intro to Ruby - 01 - Numbers and Strings
1 + 1 # => 2
x = 2
x * 2 # => 4
x *= 2# => 4
x = x * 2 # => 8
pi = 3.14
pi * (5 * 5) # => 78.5
@mkoby
mkoby / ruby_test.rb
Created March 2, 2012 22:04
Test Gist
2 + 2 # => 4
puts "Hello, World!" # => "Hello, World"
my_array = [1, 2, 3, 4, 5] # => [1,2,3,4,5]
@mkoby
mkoby / encode_videos.sh
Created February 18, 2012 20:26
Encode video to HTML5 compatible videos
#!/bin/bash
# This shell script will process & encode a single video file, and output 3
# seperate files in the following formats: WebM, Ogg Theora, & h.264 for
# streaming via an HTML5 player.
#
# You'll need ffmpeg, ffmpeg2theora, & HandbrakeCLI installed to run this
# script. ffmpeg and ffmpeg2theora can be installed via Homebrew on a Mac.
# If you're using Ubuntu, use the PPA at
# https://launchpad.net/~jon-severinsson/+archive/ffmpeg
// If value is falsy and not a string, return
// undefined. Otherwise, return 'good input!'
// Note that this means that the empty string ('')
// should return 'good input!'.
function detectGoodInput(value) {
if( typeof(value) === 'string' )
return 'good input!';
}
@mkoby
mkoby / band_controller_test.rb
Created September 27, 2011 18:58
Rails Controller Tests
#Goes in APP_FOLDER/test/functional
require 'test_helper'
class BandsControllerTest < ActionController::TestCase
setup :activate_authlogic
def setup
@host = bands(:one).subdomain + ".localhost"
UserSession.create(users(:one))
ActionMailer::Base.deliveries.clear
total 167080
-rwxr-xr-x 1 root wheel 18800 Jul 15 12:52 BuildStrings
-rwxr-xr-x 1 root wheel 25408 Jul 15 12:52 CpMac
-rwxr-xr-x 1 root wheel 100880 Jul 15 12:52 DeRez
-rwxrwxr-x 1 root admin 44480 Jul 25 10:31 DevToolsSecurity
-rwxr-xr-x 1 root wheel 18624 Jul 15 12:52 GetFileInfo
-rwxrwxr-x 1 root admin 70256 Apr 6 21:38 ImageUnitAnalyzer
-rwxr-xr-x 1 root wheel 62592 Jul 15 12:52 MergePef
-rwxr-xr-x 1 root wheel 19104 Jul 15 12:52 MvMac
-rwxr-xr-x 1 root wheel 59824 Jul 15 12:52 PPCExplain