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
# Reversing a String | |
(0...(a.length/2)).each{|i| a[i], a[-i-1]=a[-i-1], a[i]} | |
return a | |
# Fibonacci Sequence | |
(0...n).inject([0, 1]) { |p, _| [p[1], p[0] + p[1]] }[0] |
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 | |
og = ARGV[0].to_f #first argument | |
fg = ARGV[1].to_f #second argument | |
if og or fg == nil | |
puts "usage: ./peralc.rb \'original gravity' \'final gravity'" | |
Process.exit | |
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
board_size, snake_length, snake_positions, snake_vector, fruit_position = 15, 3, [[5,6],[5,5],[5,4]], [1,0], [rand(15), rand(15)] # set game board size, snake starting position, snake starting direction and fruit position | |
system "stty -icanon -echoke" # set console to non-canonical mode so it doesn't require end of line to get input | |
loop do # loop infinitely | |
if ( input = select([$stdin], nil, nil, 0.2) ) then if ( STDIN.getc.chr == "\e" ) then if ( STDIN.getc == ?[) then input = STDIN.getc end end end # get input | |
if ( input == ?A ) then snake_vector = [0,-1] elsif ( input == ?B ) then snake_vector = [0,1] elsif ( input == ?C ) then snake_vector = [1,0] elsif ( input == ?D ) then snake_vector = [-1,0] end # set snake movement direction based on input | |
snake_positions = (snake_positions.count < snake_length ? snake_positions.concat([[snake_positions.last[0] + snake_vector[0], snake_positions.last[1] + snake_vector[1]]]) : snake_positions.drop(1).concat([[snake_positions.last[0] + snake_vector[0], snake_pos |
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 'couchrest' | |
require 'ostruct' | |
configure do | |
SiteConfig = OpenStruct.new( | |
:url_base_db => 'https://USERNAME:[email protected]/', | |
:db_name => "heyo_mountain" | |
) | |
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 'open-uri' | |
require 'benchmark' | |
urls = [] | |
urls << "http://ruby-lang.org" | |
urls << "http://theplatform.com" | |
urls << "http://reddit.com" | |
urls << "http://pragprog.com" | |
urls << "http://railscasts.com" |
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 'open-uri' | |
require 'benchmark' | |
require 'celluloid' | |
class Winning | |
include Celluloid | |
urls = [] | |
urls << "http://ruby-lang.org" | |
urls << "http://theplatform.com" |
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 'json' | |
json = JSON.parse(YOURFILE) | |
a = [] | |
json['entries'].each { |v| a <<v } |
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
module Autotest::Growl | |
def self.growl title, msg, img, pri=0, stick="" | |
system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{stick}" | |
end | |
Autotest.add_hook :ran_command do |at| | |
results = [at.results].flatten.join("\n") | |
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/) | |
if output =~ /[1-9]\sfailures?/ | |
growl "Test Results", "#{output}", '~/Dropbox/Photos/autotest/rails_fail.png', 2 #, "-s" |
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 'autotest' | |
module Autotest::Notify | |
def self.notify title, msg, img, pri='low', time=3000 | |
`notify-send #{title} -i #{img} -u #{pri} -t #{time} '#{msg}'` | |
end | |
Autotest.add_hook :ran_command do |autotest| | |
results = [autotest.results].flatten.join("\n") | |
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/) |
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
c_cyan=`tput setaf 6` | |
c_red=`tput setaf 1` | |
c_green=`tput setaf 2` | |
c_sgr0=`tput sgr0` | |
parse_git_branch () | |
{ | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then | |
git_status="$(git status 2> /dev/null)" | |
branch_pattern="^# On branch ([^${IFS}]*)" |
OlderNewer