Skip to content

Instantly share code, notes, and snippets.

@r38y
r38y / run_dms.rb
Created October 22, 2015 20:20
RunDMS
require 'net/https'
require 'uri'
class RunDMS
def self.snitch(id, options={}, &block)
dead_man = new(id, options)
block.call
dead_man.snitch
end
<?xml version="1.0" encoding="ISO-8859-1"?>
<?qbxml version="7.0"?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError">
<BillAddRq>
<BillAdd>
<TxnDate>2015-08-13</TxnDate>
<VendorRef>
<ListID>8000077D-1356714929</ListID>
</VendorRef>
<?xml version="1.0" encoding="ISO-8859-1"?>
<?qbxml version="7.0"?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError">
<BillAddRq>
<BillAdd>
<VendorRef>
<ListID>80000438-1429823956</ListID>
</VendorRef>
<ItemLineAdd>
@r38y
r38y / discussion.rb
Created January 11, 2015 01:52
Tokenable with settable token name
class Discussion < ActiveRecord::Base
include Tokenable
set_token_field_name :other_token_name
end
@r38y
r38y / no-promo.txt
Last active August 29, 2015 14:05
Databases not promoting
# HEROKU_POSTGRESQL_GREEN was the old master
# I promoted then got rid of the original master (because it was staging)
# noticed that the follower was still a follower
➜ twinit.bauernet.me git:(split-test) heroku pg:info -r staging
=== HEROKU_POSTGRESQL_MAROON_URL (DATABASE_URL)
Plan: Standard 2
Status: Available
Data Size: 7.76 GB
Tables: 16
@r38y
r38y / set_time_zone_back.rb
Last active August 29, 2015 14:04
Set timezone method that sets the time zone back after the request
class ApplicationController < ActionController::Base
around_action :set_timezone
def set_timezone
old_time_zone = Time.zone
Time.zone = current_user.time_zone
yield
ensure
Time.zone = old_time_zone
end
-- winning_count is a random number between 0 and 1
-- times the sum of the weights
SELECT id
FROM (
SELECT id, SUM(weight) OVER (ORDER BY id) S
FROM entries WHERE drawing_id = #{@drawing.id}
) Q
WHERE S >= winning_count
ORDER BY id
LIMIT 1;
CREATE DATABASE new_clone WITH TEMPLATE old_database;
require 'spec_helper'
describe 'creating a person' do
it 'works with valid attributes' do
user = create(:user)
post "/api/people.json",
{ person: { name: 'Bob Johnson' } },
{ 'Authorization' => "Token token=#{user.authentication_token}" }
class NullPhoto
def file
@file = OpenStruct.new(
url: 'https://dossi-prod.s3.amazonaws.com/default-avatar.png'
)
end
# is this kosher?
def blank?
true