Skip to content

Instantly share code, notes, and snippets.

View thomaswilburn's full-sized avatar
🦝

Thomas Wilburn thomaswilburn

🦝
View GitHub Profile
@thomaswilburn
thomaswilburn / gl.js
Last active October 14, 2017 12:24
Annotated WebGL sample.
/*
We're going to start by adding a canvas to the page and getting a context for it.
*/
var canvas = document.createElement("canvas");
canvas.width = canvas.height = 320;
document.body.appendChild(canvas);
var gl = canvas.getContext("experimental-webgl");
/*
WebGL doesn't know how to draw anything onscreen out of the box. We have to
//taking a crack at it
//totally untested, probably doesn't work
var BatChannel = function(endpoint, interval) {
this.endpoint = endpoint;
this.pending = [];
this.interval = interval || 30000;
this.tick();
};
BatChannel.prototype = {
@thomaswilburn
thomaswilburn / caret-settings-upgrade.md
Created December 3, 2013 17:41
Caret is changing where settings are stored! Here's what you need to know.

Upgrading Settings in Caret: A Note

For most of its development, Caret has used Chrome's synchronized storage as the location for settings "files"--the JSON that gets loaded when you choose the Settings -> User Preferences, for example. In the past this has worked out well, but as these files have grown, they've started to migrate past the 4KB limit that's set on individual entries in sync storage. The first to do so was the Menus configuration. Nobody had submitted any bugs, which I suspect means that nobody actually changes the menus. But since user.json is creeping up on 4KB, we're going to have to make a change.

Sometime around December 4th, an update will roll out that will migrate your custom settings to Chrome's syncFileSystem API, which is backed by Google Drive. Due to some bugs in the way that Chrome handles these files, however, Caret won't actually read from them until a week or so later--it'll just back up the latest version of your settings. If it runs into any problems, you'll get a not

[...]
var loadEmmet = true;
//one-time startup
var init = function() {
aceConfig.themes.forEach(function(theme) {
var option = document.createElement("option");
option.innerHTML = theme.label;
option.setAttribute("value", theme.name);
@thomaswilburn
thomaswilburn / Code.gs
Created August 29, 2014 19:20
Apps Script example for handling custom forms
var sheetID = "xxx-id-goes-here-xxx";
var rowConfig = "timestamp name location favorite note lifespan season contact lat lng zone approve feature".split(" ");
/***
Requests may come in with the following parameters:
name
favorite - player name (number?)
note

Caret

Caret is a serious, graphical programmer's editor running as a Chrome Packaged App. Inspired by Sublime and built on top of the Ace editing component, it offers powerful features like:

  • multiple cursors
  • tabbed editing and retained files
  • syntax highlighting and themes
  • command palette/smart go to
  • hackable, synchronized configuration files
@thomaswilburn
thomaswilburn / Repair.gs
Created September 6, 2014 20:23
Geocoding using Apps Script APIs
var sheet = SpreadsheetApp.openById(sheetID).getSheetByName("Responses");
var rowConfig = "timestamp name location favorite note lifespan season contact lat lng city zone approve feature".split(" ");
function getCol(row, param) {
return row[rowConfig.indexOf(param)];
}
function setCol(row, param, value) {
row[rowConfig.indexOf(param)] = value;
@thomaswilburn
thomaswilburn / global_menu.php
Created November 19, 2014 07:17
Multi-site menu attempt
<?php
//the slot is the menu location string you registered for the global menu
$slot = "menu_name_here";
function global_multisite_nav_menu_filter( $content, $args ) {
global $slot;
$registered = get_registered_nav_menus();
if( !isset( $registered[$slot] ) )
return $content;
@thomaswilburn
thomaswilburn / global_menu.php
Created November 20, 2014 06:53
Global menu for Wordpress that isn't a huge goddamn hack
<?php
//function for getting a global menu
//that caching plugin really was ridiculous, wasn't it?
if (is_multisite() && !is_main_site()) {
switch_to_blog(1); //should send us to the main site temporarily
}
wp_nav_menu("menu_id"); //get the nav menu from the main site context
if (is_multisite() && ms_is_switched()) {
restore_current_blog(); //revert to the network site if we switched it above
@thomaswilburn
thomaswilburn / idbtest.js
Last active August 29, 2015 14:13
oh god indexeddb why
var log = console.log.bind(console);
var Database = function(name, version, upgrade) {
var self = this;
this.ready = new Promise(function(ok, fail) {
var req = window.indexedDB.open(name, version);
req.onupgradeneeded = function(db) {
self.db_ = req.result;
if (upgrade) upgrade();
}