Skip to content

Instantly share code, notes, and snippets.

@grantmichaels
Forked from seancribbs/links.rb
Created April 14, 2010 13:58
Show Gist options
  • Save grantmichaels/365841 to your computer and use it in GitHub Desktop.
Save grantmichaels/365841 to your computer and use it in GitHub Desktop.
require 'csv'
require 'riak'
client = Riak::Client.new
bucket = client.bucket('goog', :keys => false)
CSV.foreach('goog.csv',
:headers => true) do |row|
puts row.first[1].to_s
obj = bucket.new(row.first[1].to_s)
obj.data = Hash[row.to_a]
obj.store
end
require 'riak'
client = Riak::Client.new
puts "Map-Reduce all data"
gets
data = Riak::MapReduce.new(client).
add('goog').
map("Riak.mapValuesJson", :keep => true).run
puts data
puts "M/R all the days where high was above $600."
gets
map_filter = <<-JAVASCRIPT
function(value, keyData, arg) {
var data = Riak.mapValuesJson(value)[0];
if(data.High && parseFloat(data.High) > 600.00)
return [value.key];
else
return [];
}
JAVASCRIPT
data = Riak::MapReduce.new(client).
add('goog').
map(map_filter).
reduce("Riak.reduceSort", :keep => true).
run
puts data
require 'ripple'
class Person
include Ripple::Document
property :name, String
validates_presence_of :name
end
puts "Loading all people."
people = Person.all
puts people.inspect
puts "Creating John."
johnm = Person.new(:name => "John Muellerleile")
johnm.key = "johnm"
johnm.save
puts "Reloading all people."
people = Person.all
puts people.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment