Skip to content

Instantly share code, notes, and snippets.

View cmatheson's full-sized avatar

Cameron Matheson cmatheson

  • WorkOS
  • South Jordan, UT
View GitHub Profile
# returns the closest 15 minute interval
def closest(n)
closest_interval = [0, 15, 30, 45, 60].map { |m|
[m, (m - n).abs]
}.min_by { |_, minutes_away|
minutes_away
}
closest_interval.first
end
@cmatheson
cmatheson / inline_styles.diff
Last active December 15, 2015 11:09
diffstat from pruning inline styles in canvas
.../_cas_settings.html.erb | 8 +-
.../_ldap_settings.html.erb | 26 ++--
.../_ldap_settings_fields.html.erb | 38 +++---
.../_ldap_settings_test.html.erb | 22 ++--
.../_saml_settings.html.erb | 18 +--
.../account_authorization_configs/index.html.erb | 6 +-
app/views/accounts/_add_course_or_user.html.erb | 6 +-
app/views/accounts/_course.html.erb | 6 +-
app/views/accounts/avatars.html.erb | 16 +--
app/views/accounts/courses.html.erb | 2 +-
@cmatheson
cmatheson / css.treetop
Created March 15, 2013 00:11
treetop styleguide example
grammar Css
rule body
(styleguide / comment)* {
def val
Hash[
elements.map(&:val).compact
]
end
}
end
@cmatheson
cmatheson / quiz_questions.txt
Created March 13, 2013 20:55
just some sample quiz questions scraped from the interwebs for testing quiz statistics
[
["The main function of myelin is to",
["form a protective coating over nerve axons.",
"affect the speed of nerve impulses.",
"block the reception of acetylcholine.",
"aid a nerve's receptivity to neurotransmitters by increasing the number of receptor sites available."]],
["The part of the nerve cell specialized for conducting information is the",
["axon.",
"cell body.",
@cmatheson
cmatheson / generate_big_quiz.rb
Created March 13, 2013 20:53
this is good for testing Quiz#statistics performance
COURSE_ID = 5 # replace this with id of course with many (>=500) students
# generating a large course is left as an exercise to the reader
course = Course.find(COURSE_ID)
# generate quiz
q = course.quizzes.create! :title => "Big Quiz"
eval(File.read 'quiz_questions.txt').each_with_index do |(question, as), i|
answers = as.map.with_index { |a, j|
@cmatheson
cmatheson / perftools example.rb
Last active December 14, 2015 20:59
perftools.rb example
# log_to_stdout! (useful if you're running this as a script/runner thing)
Object.send(:remove_const, :RAILS_DEFAULT_LOGGER)
Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
ActiveRecord::Base.logger = Rails.logger
Mailman.config.logger = Rails.logger
ActiveRecord::Base.connection_handler.clear_all_connections!
require 'perftools' # add perftools.rb to your Gemfile
time = Time.now.to_i
@cmatheson
cmatheson / jerkins.pl
Created February 27, 2013 23:32
jerkins!!! (irssi plugin)
use strict;
Irssi::command_bind jerkins => sub {
my ($data, $server, $witem) = @_;
return unless $witem;
my $poo = ":poop: :persevere: :poop:";
$server->send_raw(
"PRIVMSG $witem->{name} :$poo http://ryanflorence.com/gifs/jenkins.gif $poo"
);
@cmatheson
cmatheson / subst.pl
Last active December 14, 2015 06:49
handy substitutions for irc
use strict;
Irssi::signal_add('message public', 'event_substitute_text');
Irssi::signal_add('message private', 'event_substitute_text');
sub event_substitute_text {
my ($server, $text, $nick, $address, $target) = @_;
my %substitions = (
':\+1:' => '👍',
@cmatheson
cmatheson / instructurezendesk.js
Created July 26, 2012 19:40 — forked from ryankshaw/instructurezendesk.js
Instructure Zendesk Agent-only mods
previousjQuery = jQuery;
jQuery(function($){
// only run in browsers that can do localStorage (not IE) and only on the tickets page
if ('localStorage' in window && $('body').hasClass('tickets-show')) {
// I want to make sure that this always runs with my version of jquery, not zendesk's
$.getScript('http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js', function(){
jQuery(function($){
function getThisZendeskTicketFromRestApi(callback){
var UrlToThisTicket = window.location.protocol + "//" + window.location.host + window.location.port + window.location.pathname;