Skip to content

Instantly share code, notes, and snippets.

View herestomwiththeweather's full-sized avatar
🏠
Working from home

Tom Brown herestomwiththeweather

🏠
Working from home
View GitHub Profile
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 03:06
single payment authorization view
<%= check_box_tag 'authorize' %> authorize <span id="scope-action"><%= @token.action_name %></span> <img src="<%= @token.action_icon_uri %>"> of <%= @token.amount %> <%= @token.asset %>
unless (access_token.nil? || access_token.authorized_for?(exchange.amount))
false
def authorized_for?(requested_amount)
['single_payment','recurring_payment'].include?(action_id) && requested_amount <= amount.to_f && !invalidated?
end
@herestomwiththeweather
herestomwiththeweather / oauth2_mac_client_example.rb
Created March 12, 2012 19:51
Example code to make hmac signed oauth2 requests
require 'uri'
require 'cgi'
require 'net/https'
require 'json'
require 'oauth2_mac_client'
# oauth2_mac_client gem at https://github.com/herestomwiththeweather/oauth2_mac_client
# usage using this test class:
# > client = OAuth2Client.new
# > client.get_token('refresh_token') # get a new MAC type access token
Verifying that +herestomwiththeweather is my blockchain ID. https://onename.com/herestomwiththeweather
#!/usr/bin/env ruby
require 'rss'
require 'webmention'
require 'time'
string = File.open('latest_time.txt', 'r') { |f| f.read }
latest = string.strip # RSS timestamp of most recent blog post for which webmentions have been sent
latest_found = latest # RSS timestamp of most recent blog post including new ones found
last_time = Time.parse(latest)
from, to, branch = ARGF.read.split " "
if (branch =~ /herestomwiththeweather$/) == nil
puts "Received branch #{branch}, not deploying."
exit
end
deploy_to_dir = '/home/pants/deploy/herestomwiththeweather-jekyll-indieweb'
`unset GIT_DIR && cd "#{deploy_to_dir}" && git pull`
puts "DEPLOY: herestomwiththeweather(#{to}) copied to '#{deploy_to_dir}'"
`cd /home/pants/repositories/herestomwiththeweather-jekyll-indieweb.git/hooks && ./send_webmentions.rb`