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
metrics_with_inputs = Revision.find( | |
:all, | |
:conditions => { :id => self.revisions.map { |r| r.id } }, | |
:select => 'revisions.metric, revisions.snap_date, revisions.updated_at, | |
inputs.author, inputs.as_of_date, inputs.units', | |
:joins => 'join inputs on inputs.revision_id = revisions.id', | |
:order => 'revisions.metric, revisions.snap_date, revisions.updated_at' | |
) |
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 columnize(arr, columns) | |
size_in_group = arr.size / columns | |
if arr.size % columns != 0 | |
size_in_group += 1 | |
end | |
arr_grouped = [ ] | |
size_in_group.times do |m| | |
columns.times do |i| | |
arr_grouped[i] ||= [] |
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
animals = [ | |
{ :name => 'Frog', :class => 'Amphibian' }, | |
{ :name => 'Butterfly', :class => 'Arthropod' }, | |
{ :name => 'Eagle', :class => 'Bird' }, | |
{ :name => 'Seahorse', :class => 'Fish' }, | |
{ :name => 'Dog', :class => 'Mammal' }, | |
{ :name => 'Man', :class => 'Mammal' }, | |
{ :name => 'Crocodile', :class => 'Reptile' }, | |
] | |
# Note that Fish and Reptiles are missing from the following |
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
# http://mathforum.org/dr.math/faq/faq.peasant.html | |
# http://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication | |
module RussianPeasantMultiplication | |
def russian_peasant_multiply(b) | |
numbers_to_add = [] | |
a, b = [self, b].sort #So we have the smaller number as the first | |
negative_operands = [a, b].select { |n| n < 0 } | |
result_should_be_negative = negative_operands.size.odd? # or negative_operands.size == 1 |
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 -wKU | |
players = "Parag | |
Arnab | |
Vinoth | |
Sreeram | |
Ajay | |
Nazeer | |
Swapnil | |
Sridhar |
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 "pp" | |
class String | |
def all_substrings | |
substrs = [] | |
start_index, end_index = [0, self.length - 1] | |
start_index.upto end_index do |i| | |
i.upto end_index do |j| | |
# puts "#{self}[#{i}, #{j}] => #{ss}" | |
substrs << self[i..j] |
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 "fog" | |
CREDS_FILE = 'Somewhere' | |
DOMAIN = 'Dogs' | |
ATTRIBS_TO_CHANGE = { | |
'color' => 'white' | |
} | |
OPTIONS = { | |
:replace => ['color'], | |
:expect => { |
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
import java.io.Console; | |
public class NumberGuess { | |
private int small; | |
private int big; | |
private int guess; | |
private void guess(){ | |
this.guess = nextGuess(); | |
String verdict = System.console().readLine(guess + ": smaller/bigger/start-over? "); |
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
ArgumentError in 'Fog::Vcloud power_on with a vapp uri that doesn't exist should == {:type=>"application/vnd.vmware.vcloud.org+xml", :name=>"Boom Inc.", :href=>"https://fakey.com/api/v0.8/MockOrganization/2174953160"}' | |
Unrecognized arguments: username, module, password, versions_uri | |
/Users/arnab/code/github/fog/lib/fog/core/service.rb:141:in `validate_arguments' | |
/Users/arnab/code/github/fog/lib/fog/core/service.rb:43:in `new' | |
/Users/arnab/code/github/fog/spec/vcloud/terremark/ecloud/requests/../../../spec_helper.rb:276: |
OlderNewer