Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Tom Brown herestomwiththeweather

🏠
Working from home
View GitHub Profile
View erase group currencies
Exchange.all.each {|e| e.destroy if e.group}
Account.all.each {|a| a.destroy if a.group}
Group.all.each {|g| g.adhoc_currency = false; g.unit = nil; g.save!}
View rel-payment bookmarklet
javascript:(function(){ asset_urls = [];var links = document.getElementsByTagName("a");for(var i=0;i<links.length;i++){if (links[i].getAttribute('rel') == 'payment') { asset_urls.push(links[i].getAttribute('href'));}} window.name = 'receiver'; var remoteWin=window.open('','','resizable=yes,width=550,height=550'); remoteWin.document.write('<html><body>'); for(var j=0;j<asset_urls.length;j++){remoteWin.document.write('<a href="' + asset_urls[j] + '/new?to=' + encodeURIComponent(window.location.href) + '">' + asset_urls[j] + '</a><br><br>');} remoteWin.document.write('') })();
View simpler opentransact
javascript:(function(){ asset_urls = [];var links = document.getElementsByTagName("a");for(var i=0;i<links.length;i++){if (links[i].getAttribute('href').match(/\/transacts/)) { asset_urls.push(links[i].getAttribute('href'));}} var remoteWin=window.open('','','resizable=yes,width=550,height=550'); remoteWin.document.write('<html><body>'); for(var j=0;j<asset_urls.length;j++){remoteWin.document.write('<a href="' + asset_urls[j] + '/new?to=' + encodeURIComponent(window.location.href) + '">' + asset_urls[j] + '</a><br><br>');} remoteWin.document.write('') })();
View twitter & opentransact
javascript:(function(){ asset_urls = [];var twitter_id='';var metatags=document.getElementsByTagName("meta");for(var j=0;j<metatags.length;j++){if(metatags[j].getAttribute('name') == 'session-userid') {twitter_id=metatags[j].getAttribute('content');}} var links = document.getElementsByTagName("a");for(var i=0;i<links.length;i++){if (links[i].getAttribute('href') && links[i].getAttribute('href').match(/\/transacts/)) { asset_urls.push(links[i].getAttribute('href'));}} var remoteWin=window.open('','','resizable=yes,width=550,height=550'); remoteWin.document.write('<html><body>'); for(var j=0;j<asset_urls.length;j++){remoteWin.document.write('<a href="' + asset_urls[j] + '/new?to=' + twitter_id + '">' + asset_urls[j] + '</a><br><br>');} remoteWin.document.write('</body></html>') })();
View groupy branch migration
1. create a group -> group_id
2. delete new group's forum and assign old main forum to new group:
Forum.find_by_group_id(group_id).delete
g = Group.find(group_id)
f = Forum.first(:conditions => ['group_id IS ?',nil])
f.group = g
f.save
3. change all members' default accounts to belong to the new group:
@herestomwiththeweather
herestomwiththeweather / gist:717659
Created Nov 27, 2010
RSpec and CanCan Authorization for Intentional Economics
View gist:717659
@e.amount = 1.0
@e.customer = @p2
@membership.roles = ['individual']
@membership.save
account = @p2.account(@g)
account.balance = 0.0
account.credit_limit = 0.5
account.save!
@herestomwiththeweather
herestomwiththeweather / gist:717685
Created Nov 27, 2010
RSpec and CanCan Authorization for Intentional Economics
View gist:717685
can :create, Exchange do |exchange|
unless exchange.group
# the presence of group is validated when creating an exchange
# group will be nil for the new method, so allow it
true
else
membership = Membership.mem(person,exchange.group)
unless membership
false
else
@herestomwiththeweather
herestomwiththeweather / gist:717686
Created Nov 27, 2010
RSpec and CanCan Authorization for Intentional Economics
View gist:717686
def authorized?(amount)
credit_limit.nil? or (amount <= balance + credit_limit)
end
View create_request_token
def create_request_token(params={})
if params[:scope]
scope_uri = URI.parse(params[:scope])
# XXX ignoring host:port and assuming it's our host:port
filepath = RAILS_ROOT + '/public' + scope_uri.path
if File.exist?(filepath)
# valid asset is required
asset = CGI::parse(scope_uri.query)['asset'][0]
unless asset.blank?
group = Group.find_by_asset(asset)
@herestomwiththeweather
herestomwiththeweather / authorize.html.erb
Created May 21, 2011
single payment authorization view
View authorize.html.erb
<%= check_box_tag 'authorize' %> authorize <span id="scope-action"><%= @token.action_name %></span> <img src="<%= @token.action_icon_uri %>"> of <%= @token.amount %> <%= @token.asset %>