Skip to content

Instantly share code, notes, and snippets.

require 'socket'
class Graphite
def initialize(host)
@host = host
end
def socket
return @socket if @socket && !@socket.closed?
@socket = TCPSocket.new(@host, 2003)
@christopher-b
christopher-b / redis-graphite.rb
Last active December 11, 2015 17:39
Report Redis stats from (INFO) to Graphite
#!/usr/bin/env ruby
require 'socket'
require 'optparse'
# Collect INFO from Redis, report it to Graphite
opts = OptionParser.new do |opts|
opts.banner = "Usage: redis-graphite.rb redis-host[:redis-port] graphite-host"
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
@christopher-b
christopher-b / passenger-statsd.rb
Last active December 15, 2015 10:39
Passenger - Statsd
#! /usr/bin/ruby
require 'socket'
statsd_host = ""
statsd_port = "8125"
namespace_prefix = "statsd-ruby"
mode = "statsd"
ARGV.each do |arg|
name, value = arg.split '='
@christopher-b
christopher-b / Consumer.php
Last active December 16, 2015 20:49
A Zend Auth Adapter implementation for OAuth. Created for use with LTI tools.
<?php
class Dashboard_Model_OAuth_Consumer extends OCAD_Db_Row
{
public function recordRequest($timestamp, $nonce)
{
if( $timestamp > $this->timestamp )
{
// Update saved timestamp
$this->timestamp = $timestamp;
$this->setNonces(array($nonce)); // Clear saved nonces
@christopher-b
christopher-b / gist:6038992
Last active December 20, 2015 00:08
Canvas LMS rake task to return the number of queued delayed jobs
namespace :ocadu do
"Returns the number of delayed jobs in the queue"
task :job_count => :environment do
puts Delayed::Job.where("run_at < UTC_TIMESTAMP() AND locked_at is null").count
end
end
@christopher-b
christopher-b / gist:11190658
Created April 22, 2014 19:05
Postgres - Drop / Recreate constraints
# These queries generate *other* queries that can be used to drop and recreate constraints on all tables in the database.
# Both must be run while the constrains still exist
# Drop constraints
SELECT 'ALTER TABLE "'||nspname||'"."'||relname||'" DROP CONSTRAINT "'||conname||'";'
FROM pg_constraint
INNER JOIN pg_class ON conrelid=pg_class.oid
INNER JOIN pg_namespace ON pg_namespace.oid=pg_class.relnamespace
ORDER BY CASE WHEN contype='f' THEN 0 ELSE 1 END,contype,nspname,relname,conname
@christopher-b
christopher-b / check.rb
Last active August 26, 2018 21:14
Canvas MySQL -> Postgres Migration
#!/usr/bin/env ruby
# Do sanity check on imported data by comparing the number of rows in each table
require 'pg'
require 'mysql2'
tables = %w( { list the tables to compare here })
p = PG.connect(dbname:'canvas', host: 'postgres.ocad.ca', user: 'canvas_user')
#!/bin/sh
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
@christopher-b
christopher-b / custom.js
Last active July 5, 2016 14:10
Canvas LMS: Add a button to the sidebar to trigger RTE LTI Launch
$(function(){
var $body = $('body');
// Add a button to launch the Outline Builder, which triggers the RTE LTI Launch
if($body.hasClass('syllabus')) {
// #editor_tabs is only visible when the RTE is active
$('#editor_tabs').prepend('<div style="padding-bottom:1em;"><a class="Button Button--primary icon-compose" id="launch_outline_editor_button">Course Outline Builder</a></div>');
$('#launch_outline_editor_button').click(function(){
// Existing RTE LTI buttons are added with aria-label set to the "Name" of the tool, as defined in the tool settings UI, not the XML
$('div[aria-label="Outline Builder"]').click();
@christopher-b
christopher-b / cleanup.rb
Created November 8, 2016 20:14
Canvas - Delete export files
Attachment.where(workflow_state:'zipped').find_each do |attachment|
delete_attachment attachment
};nil
def delete_attachment(attachment)
# Don't delete parent Attachments
return if attachment.children.present?
# Delete associated ContentExports
content_export_for(attachment).try(:delete)