Skip to content

Instantly share code, notes, and snippets.

View schuyberg's full-sized avatar

Schuyler Lindberg schuyberg

  • The University of British Columbia
  • Vancouver, BC
View GitHub Profile
@schuyberg
schuyberg / statblockerer.user.js
Last active July 19, 2019 21:31
add buttons to open articles and statblocks from d20pfsrd for easy saving / printing
// ==UserScript==
// @name d20pfsrd Statblockerer
// @match *://www.d20pfsrd.com/*
// @description adds buttons open a statblock from d20pfsrd.com in a new window to print or save
// @author schuyberg
// @grant none
// @version 0.1
// @updateURL https://gist.github.com/schuyberg/794d78bd34a0661cb72d5833a2a83934/raw/statblockerer.user.js
// @downloadURL https://gist.github.com/schuyberg/794d78bd34a0661cb72d5833a2a83934/raw/statblockerer.user.js
// @run-at document-end
@schuyberg
schuyberg / d20pfsrd-print-card
Last active May 26, 2019 06:21
Tampermonkey script to print d20pfsrd pages onto a 3x5 cards - adds buttons to print .statblock, and .article-content
// ==UserScript==
// @name d20pfsrd Print Card 2
// @match www.d20pfsrd.com/*
// @description print a statblock from d20pfsrd.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const right_sidebar = document.querySelector(".right-sidebar");
@schuyberg
schuyberg / spotify_link_labels.tampermonkey.js
Last active February 10, 2018 19:52
Browse Spotify by Label! -- a Tampermonkey script to make copyright statements into hyperlinks in Spotify web player
@schuyberg
schuyberg / color-conversion-algorithms.js
Created December 14, 2017 20:18 — forked from mjackson/color-conversion-algorithms.js
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation
chmod 700 $HOME/.ssh
chmod go-w $HOME $HOME/.ssh
chmod 600 $HOME/.ssh/authorized_keys
chown `whoami` $HOME/.ssh/authorized_keys
@schuyberg
schuyberg / clogs.php
Last active September 27, 2017 23:54
log to the JS console from PHP
// use this anywhere in your php app
function console_log() {
$messages = func_get_args();
if(!$GLOBALS['cLogs']){
$GLOBALS['cLogs'] = array();
}
$GLOBALS['cLogs'] = array_merge($GLOBALS['cLogs'], $messages);
}
// use this at the bottom of the global template (or wherever you can insert some js)
@schuyberg
schuyberg / ProvinceState Arrays
Created September 11, 2017 21:33 — forked from james2doyle/ProvinceState Arrays
PHP array for states and Provinces in Canada and the US
$provinces = array(0 => 'Alberta',
1 => 'British Columbia',
2 => 'Manitoba',
3 => 'New Brunswick',
4 => 'Newfoundland and Labrador',
5 => 'Northwest Territories',
6 => 'Nova Scotia',
7 => 'Nunavut',
8 => 'Ontario',
9 => 'Prince Edward Island',
// generates a table of contents
// blame @schuyberg 2016
//
//
// use on jquery object you want it appended before (usually first header)
// hStart = number: html heading level to start on (ie. 2 would be h2)
// depth = number: depth to traverse heading heirarchy (h2 + 1 = h2, h3)
// example: jQuery('h2').first().toc(2,1); --> adds contents before first h2 tag, includes h2, h3 tags.
$.fn.toc = function(hStart, depth){
/* AngularJS Print Service
thanks to Bahmni for the original code at https://github.com/Bhamni/openmrs-module-bahmniapps/blob/master/ui/app/common/ui-helper/printer.js
** modified here to work with ie10/11 */
services.factory('printer', [ '$rootScope', '$compile', '$http', '$timeout', 'utility', function ($rootScope, $compile, $http, $timeout, utility) {
var printHtml = function (html) {
var hiddenFrame = $('<iframe name="printframe" style="position: absolute; left: -9999px;"></iframe>').appendTo('body')[ 0 ];
var htmlContent = "<!doctype html>" +
'<head><meta http-equiv="X-UA-Compatible" content="IE=edge"></head>' +
@schuyberg
schuyberg / gist:2b5877f90a5f4bda5d4b
Last active August 29, 2015 14:22
AngularJS $rootScope.$emit service pattern
// pattern for creating servicesto communicate efficiently between angular components
services.factory('changeService', ['$rootScope',
function ($rootScope) {
var changeService = {};
// use changeService.changed(action) in controller to act on changes
changeService.changed = function(callback){
$rootScope.$on('change', callback);