Skip to content

Instantly share code, notes, and snippets.

database_1 | 2021-10-18 15:32:24 40 [Warning] Aborted connection 40 to db: 'pantheon' user: 'pantheon' host: '172.20.0.6' (Got an error reading communication packets)
database_1 | /launch.sh: line 11: 19 Killed /opt/bitnami/scripts/mariadb/entrypoint.sh /opt/bitnami/scripts/mariadb/run.sh
ocaduca_database_1 exited with code 137
appserver_1 | NOTICE: PHP message: Failed to log error: Warning: session_write_close(): Failed to write session data with "Drupal\Core\Session\WriteSafeSessionHandler" handler in Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->Symfony\Component\HttpFoundation\Session\Storage\{closure}() (line 262 of /app/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php). #0 /app/web/core/includes/bootstrap.inc(600): _drupal_error_handler_real(2, 'session_write_c...', '/app/vendor/sym...', 266, NULL)
appserver_1 | #1 /app/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php(262): _drupal_er
@christopher-b
christopher-b / file_zapper.rb
Last active May 22, 2019 21:21
Canvas FileZapper
# Canvas FileZapper. Zap yer files.
# Monkey patch the File class.
# This is to work around a bug in gems/attachment_fu/lib/attachment_fu#detect_mimetype.
# During att.make_childless, Canvas will call attachment.uploaded_data = data, data being a File
# instance. Attachment#uploaded_data= will call detect_mimetype with data, but will fail if data
# does not respond to #content_type. So we add the content_type method, using the same code that
# detect_mimetype would use anyways.
class File
def content_type
@christopher-b
christopher-b / gist:7cf281a186b94ded0f91277afe13dc1c
Created May 10, 2018 18:50
Apache - log real IP for proxied requests
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
CustomLog "logs/access_log" combined env=!forwarded
CustomLog "logs/access_log" proxy env=forwarded
# From http://www.techstacks.com/howto/log-client-ip-and-xforwardedfor-ip-in-apache.html
@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)
@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();
#!/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 / 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')
@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 / 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 / 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