Skip to content

Instantly share code, notes, and snippets.

View benmacleod's full-sized avatar

Ben MacLeod benmacleod

  • Melbourne, Australia
View GitHub Profile
@benmacleod
benmacleod / monthly_donation_amount_changes.sql
Created May 20, 2022 03:32
Capturing where a donation's amount doesn't match a subscription's amount
SELECT s.region_id, s.frequency, s.payment_provider, s.payment_method, s.created_at, s.id, s.email, s.amount_in_local, d.amount_in_local, >
FROM subscriptions s
JOIN donations d ON s.id = d.subscription_id
WHERE d.amount_in_local != s.amount_in_local
AND s.created_at > CURRENT_TIMESTAMP - INTERVAL '3 years'
GROUP BY 1,2,3,4,5,6,7,8,9
ORDER BY 1,2,3,4,5
;
-- Some reasons:
Master: [DEBUG Nuvola] master.vala:111: Compositing mode disabled because of WebKitGTK < 2.13.4
Master: [DEBUG Gtk] Connecting to session manager
Master: [DEBUG DioriteGtk] DesktopShell.vala:96: Shell: compiz (null), CSD 0, appmenu 1, menubar 0
Master: [DEBUG Nuvola] WebAppRegistry.vala:169: Found web app Test at /usr/share/nuvolaplayer3/web_apps/test, version 1.0
Master: [DEBUG Nuvola] WebAppRegistry.vala:169: Found web app 8tracks at /usr/share/nuvolaplayer3/web_apps/8tracks, version 5.1
Master: [DEBUG Nuvola] WebAppRegistry.vala:169: Found web app Amazon Cloud Player at /usr/share/nuvolaplayer3/web_apps/amazon_cloud_player, version 5.1
Master: [DEBUG Nuvola] WebAppRegistry.vala:169: Found web app Bandcamp at /usr/share/nuvolaplayer3/web_apps/bandcamp, version 2.1
Master: [DEBUG Nuvola] WebAppRegistry.vala:169: Found web app Deezer at /usr/share/nuvolaplayer3/web_apps/deezer, version 2.4
Master: [DEBUG
@benmacleod
benmacleod / debug_ajax_datatable.rb
Last active April 13, 2016 02:33
Debug an AJAX Datatable from the Rails 4 console
# Using a datatable as per https://github.com/antillas21/ajax-datatables-rails
app.get '/things'
controller = ThingsController.new
controller.request = app.request
controller.params = ActionController::Parameters.new({search: 'Thing Name'})
datatable = ThingDatatable.new(controller.view_context)
datatable.send(:data)
# This is what my params looks like
{:group_id=>86,
:payer_id=>1982,
:account_type=>"standard",
:sms_credit_price_ex_tax=>"0.025",
:auto_purchase_sms_credits_amount=>1000,
:setup_invoice=>true,
:locale=>"en-GB",
:timezone=>"London",
@benmacleod
benmacleod / Gemfile
Last active August 29, 2015 14:14
Adding CORS support to a Ruby on Rails app working with a Squawkbox editor session
source 'https://rubygems.org'
gem 'rails'
# etc, etc.
gem 'rack-cors', require: 'rack/cors'
class Account
has_many :payment_methods
end
describe 'DELETE #destroy' do
let(:dummy) { mock('Dummy') }
it "should find the object with the given ID and destroy it" do
# set the expectations about the interactions
Dummy.should_receive(:find).with(99).and_return dummy
dummy.should_receive(:destroy)
delete :destroy, id: 99
end
end
<%= simple_form_for @item do |i| %>
<%= i.input :name %>
<%= i.input :description %>
<%= i.input :price %>
<%= i.input :zip %>
<%= i.input :weight %>
<%= i.input :volume %>
<%= i.simple_fields_for :item_images do |image| %>
<% image.input :image, as: :file %>
<% end %>
@benmacleod
benmacleod / comment..rb
Last active December 27, 2015 12:49 — forked from workmad3/comment..rb
def self.create_from_parent(parent_type, parent_id, comment_params, current_account)
parent = parent_type.safe_constantize
raise ActiveRecord::RecordNotFound unless parent && (parent.reflect_on_association(:comments).klass == self)
parent.find(parent_id).comments.create(comment_params.merge(account: current_account))
end
class Contact < ActiveResource::Base
self.site = 'http://localhost:3000/service/v1/'
self.user = (a = Account.find(1)).users.first.email
self.password = a.web_service_key
end
c = Contact.find 1