Skip to content

Instantly share code, notes, and snippets.

View michael's full-sized avatar

Michael Aufreiter michael

View GitHub Profile
describe Machines, "#update" do
before(:each) do
Machine.auto_migrate!
Machinemodel.auto_migrate!
@machine = Machine.create(:serial_number => "FAKENUM", :machinemodel => Machinemodel.create(:name => "IR2880"))
@machine.save # machine#1
@machine = Machine.create(:serial_number => "FAKENUM2", :machinemodel => Machinemodel.create(:name => "IR2200"))
@machine.save # machine#2
/* AutoSaveResourceProxy */
/*
forms must look like that:
<form id="quote_option_2_form" action="/quotes/1/quote_options/2" method="post">
<input type="hidden" name="_method" value="put"/>
</form>
it even works with a normal div element - conventions are like so:
<div id="quote_option_2">
/* original element */
#users {border:0; width: 300px; height: 200px;}
/* needed for the plugin */
.clear {clear: both;}
.multiselect ul.selected { background: #f1f1f1; margin: 0; padding: 0; padding-top: 1px; overflow: auto; list-style: none; border: 0; float:left; position: relative; }
.multiselect ul.selected li { border-bottom: #ccc 1px solid; line-height: 20px; font-size: 11px; width: 90%; }
.multiselect ul.selected li:hover { background: #dfdfdf;}
# namestorming
# SteadyStateMachine
# Workflowable
# WorkflowEngine
module DataMapper
module Is
module PersistentStateMachine
state = State.get(1)
state.state_transitions << StateTransition.new(:target => QuoteState.get(3), :state_event => QuoteStateEvent.get(3))
state.save
rescue MethodNotAllowed
self.status = MethodNotAllowed.status
{
:errors => "your error message"
}.to_json
end
# quotes visible to a user
def quotes(query_hsh)
return [] if division_id.nil? || facility_id.nil?
if authorized?('all_quotes')
Quote.all(query_hsh)
elsif authorized?('own_quotes')
Quote.all({:user_id => id}.merge(query_hsh))
end
end
class Freebase
include HTTParty
format :json
base_uri 'http://www.freebase.com/api'
def self.read(q)
return get('/service/mqlread?', :query => {:query => '{"query":' + q + '}'})['result']
end
end
require 'rubygems'
require 'ken'
# authentication is not needed for read-only access
Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
# fetch a resource
resource = Ken.get('/en/new_order') # => <Resource id="/en/new_order" name="New Order">
# let's inspect that resource
resource.attributes.each do |attribute|
puts attribute.property.name
puts "--------------------------------"
# there are 4 possible variants
#######################################
# non-unique value type
# non-unique object type
# unique value type
# unique object type