Skip to content

Instantly share code, notes, and snippets.

View grahamb's full-sized avatar
🇨🇦
As Canadian as possible under the circumstances

Graham Ballantyne grahamb

🇨🇦
As Canadian as possible under the circumstances
View GitHub Profile
(function() {
require['vendor/jquery.dataTables'];
}).call(this);
require ['jquery', 'sfu_stats/vendor/jquery.dataTables'], ($) ->
// do things here that rely on jquery.dataTables
$('#courses').dataTable({.......});
courses = Course.all(:conditions => "root_account_id = 2 AND enrollment_term_id = 5 AND workflow_state != 'deleted'")
types = ['StudentEnrollment', 'TeacherEnrollment', 'TaEnrollment', 'DesignerEnrollment', 'ObserverEnrollment', 'StudentViewEnrollment']
total_enrollments = {}
types.each do |t|
total_enrollments[t] = 0
end
courses.each do |c|
enrollments = c.enrollments.count(:distinct => true, :group => 'enrollments.type', :select => 'users.id', :conditions => 'enrollments.role_name IS NULL')
puts "#{c.id} #{enrollments}"
enrollments.each do |type, num|
Enrollment.count(
:select => "enrollments.course_id || ':' || enrollments.user_id",
:distinct => true,
:joins => :course,
:group => "enrollments.type",
:conditions => ["
enrollments.course_id = courses.id AND
enrollments.root_account_id = 2 AND
courses.enrollment_term_id = 5 AND
enrollments.role_name IS NULL AND
@grahamb
grahamb / offline.js
Created May 27, 2013 17:52
Offline collector to stand in for graphite during outages.
var net = require('net');
var fs = require('fs');
var file = '/tmp/offlinecache';
var port = 2003;
net.createServer(function(socket) {
socket.name = socket.remoteAddress + ":" + socket.remotePort;
console.log ("Connection: %s", socket.name);
socket.on('data', function(data) {
console.log(data.toString());
onPage(/\/courses\/\d+\/settings/, function() {
// do something
});
hasAnyRole('admin', function(hasRole) {
if (hasRole) {
// do something
} else {
// do something else
}
# works
require 'bamboo_api'
SCHEDULER.every '30s', :first_in => 0 do
BambooApi.new({
end_point: settings.bamboo[:bamboo_host],
username: settings.bamboo[:bamboo_username],
password: settings.bamboo[:bamboo_password]
@grahamb
grahamb / gist:8718012
Created January 30, 2014 20:25
canvastree
├── /var/rails/canvas
│ ├── current -> /var/rails/canvas/releases/20140128222236
│ ├── releases
│ │ ├── 20140128214428
│ │ ├── 20140128215321
│ │ ├── 20140128220058
│ │ ├── 20140128220329
│ │ └── 20140128222236
│ └── shared
│ ├── cached-copy
@grahamb
grahamb / gist:9355963
Created March 4, 2014 21:22
migration error
== AddAttachmentRootAttachmentForeignKey: migrating ==========================
rake aborted!
An error has occurred, all later migrations canceled:
uninitialized constant Shard::IDS_PER_SHARD