Skip to content

Instantly share code, notes, and snippets.

View donnoman's full-sized avatar

Donovan Bray donnoman

View GitHub Profile
@donnoman
donnoman / trigger.rb
Created August 17, 2016 16:06
Buildkite v2 API Build Trigger Script
#!/usr/bin/env ruby
require "bundler"
Bundler.setup
require "httparty"
unless ENV["BUILDKITE_KEY"]
puts "you need to set your BUILDKITE_KEY"
exit 1
@donnoman
donnoman / schedule
Last active November 12, 2021 00:22
Buildkite GraphQL Cron Scheduler
#!/usr/bin/env ruby
require "bundler"
Bundler.setup
require "httparty"
require "byebug"
unless ENV["BUILDKITE_KEY"]
puts "you need to set your BUILDKITE_KEY"
@donnoman
donnoman / gdirectory.rb
Last active October 5, 2015 21:32
Ruby HTTParty Example of retrieving all Google Apps Domain Users via admin-sdk/directory/v1
#!/usr/bin/env ruby
require 'googleauth'
require 'httparty'
require 'active_support/all'
class GDirectory
# https://github.com/jnunemaker/httparty
include HTTParty
#!/usr/bin/env ruby
require 'openssl'
require 'securerandom'
require 'byebug'
# http://docs.ruby-lang.org/en/2.1.0/OpenSSL/Cipher.html#class-OpenSSL::Cipher-label-Authenticated+Encryption+and+Associated+Data+-28AEAD-29
# http://security.stackexchange.com/questions/17044/when-using-aes-and-cbc-is-it-necessary-to-keep-the-iv-secret
ENV['ENCRYPTED_ATTRIBUTES_KEY']=SecureRandom.hex(40) #This isn't a real key used anywhere but it's representative
ENV['ENCRYPTED_ATTRIBUTES_ALGORITHM']='aes-256-gcm'
@donnoman
donnoman / gist:1643445
Created January 19, 2012 22:41
God Init Script for Ubuntu/Debian
#! /bin/sh
### BEGIN INIT INFO
# Provides: god
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: God initscript
### END INIT INFO
@donnoman
donnoman / raise-in-a-block.rb
Created December 29, 2011 00:42
Ruby Raise in a block test
ree-1.8.7-2010.02 :001 > def me
ree-1.8.7-2010.02 :002?> yield
ree-1.8.7-2010.02 :003?> end
=> nil
ree-1.8.7-2010.02 :004 >
ree-1.8.7-2010.02 :005 > me do
ree-1.8.7-2010.02 :006 > begin
ree-1.8.7-2010.02 :007 > raise "goobers"
ree-1.8.7-2010.02 :008?> rescue
ree-1.8.7-2010.02 :009?> p "I caught the goober"
@donnoman
donnoman / gist:1112243
Created July 28, 2011 18:50
Cucumber Template
# http://rspec.info/
# http://peepcode.com/products/rspec-user-stories
# http://dannorth.net/whats-in-a-story
# http://www.lukeredpath.co.uk/2006/8/29/developing-a-rails-model-using-bdd-and-rspec-part-1
# http://www.benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories/
# http://www.benmabey.com/2008/02/04/rspec-plain-text-stories-webrat-chunky-bacon/
# http://www.chariotsolutions.com/slides/pdfs/ete2008-IntegrationTestingWithRSpec.pdf
# http://www.joesniff.co.uk/ruby/telling-a-good-story-rspec-stories-from-the-trenches.html
# How does using stories help testing?
@donnoman
donnoman / gist:1112161
Created July 28, 2011 18:19
Sample Cucumber Spec
Story: Visitor should be able to log in
As a visitor
I should be able to login
So that I can have access to the application
Scenario: Visitor visits the home page
Given a logged out visitor
When visitor goes to the home page
Then visitor should see the sessions/new page
@donnoman
donnoman / ruby_recursive.rb
Created February 3, 2011 19:17
Just a simple recursion test
#faking the rails class to keep the test simple
class Rails
def self.env
"development"
end
end
def get_descriptor(descriptor, descriptor_keys = Rails.env, i = 0)
if descriptor.is_a?(Array) || descriptor.is_a?(String)
descriptor
SELECT MAKEDATE(YEAR(CURRENT_DATE()),DAYOFYEAR(CURRENT_DATE()) - rn.id + 1) as `date`,
(
SELECT SUM(ROUND(rp.amount/(rp.interval * 30) * IF(spay.service_end_date,1,0),2)) as dv
FROM subscribers sub
JOIN subscriptions s ON s.subscriber_id = sub.id AND s.is_suspended = false AND s.autobill_failure_count = 0
JOIN subscription_plans sp ON sp.id = s.subscription_plan_id AND sp.id NOT IN (6,12)
JOIN renewal_periods rp ON s.renewal_period_id = rp.id
JOIN subscription_payments spay ON spay.subscription_id = s.id
WHERE s.deleted_at IS NULL
AND DATE(spay.service_begin_date) <= `date`