Skip to content

Instantly share code, notes, and snippets.

@cmaher
cmaher / .vimrc
Last active December 9, 2015 20:38
" enable some stuff
set nocompatible
"enable pathogen
call pathogen#infect()
"open files relative to current file
cnoremap <C-E> edit <C-R>=expand("%:h")<CR>/
" turn on proper file recognition
@cmaher
cmaher / solarized-dark-custom
Created December 18, 2012 03:42
Modified solarized-dark palette
colors 1-16
#cb4b16:#d68594:#859900:#b58900:#2998e6:#cbd87d:#2ba79e:#93a1a1:#cb4b16:#dc322f:#859900:#b58900:#268bd2:#d33682:#2aa198:#eee8d5
cursor_color = "#686868"
foreground_color = "#839496"
background_color = "#002b36"
@cmaher
cmaher / anki_ravenbrook_heisig_kanji.js
Created April 23, 2013 18:48
Convert kanji from ravenbrook to anki cards (run in console)
//Assume the kanji are from
// http://www.ravenbrook.com/project/etp24/tool/cgi/heisig-index/?action=frame_order
//newlines replaced with '^'
var parseKanji = function (kanjiList) {
return kanjiList.split("^").map(function (line) {
var k = line.split("\t").slice(0,2);
return {
character: k[0],
heisigNumber: k[1],
@cmaher
cmaher / proxy_example.js
Last active August 29, 2015 14:03
Backbone.Radio.proxy usage
var source = Backbone.Radio.channel('source');
var proxy = Backbone.Radio.channel('proxy');
// 1 to 1 mapping
proxy.proxyEvents(source, {
'source:foo': 'proxy:foo'
});
proxy.on('proxy:foo', console.log);
source.trigger('source:foo', 1); // triggers proxy:foo on proxy, prints 1
@cmaher
cmaher / jquery-promise.js
Last active August 29, 2015 14:07
A subset of es6-Promise behavior implemented using jQuery.Deferred. Designed with cmaher/backbone.hoard in mind, but is general-purpose.
'use strict';
var Promise = function (callback) {
var deferred = $.Deferred();
callback(deferred.resolve, deferred.reject);
return deferred.promise();
};
Promise.all = function (promises) {
return $.when.apply(null, promises);
@cmaher
cmaher / in-memory-localstorage.js
Last active August 29, 2015 14:08
Basic in-memory localStorage API for use with cmaher/backbone.hoard
// around 5MB, matching common localStorage limit
var STORAGE_SIZE_DEFAULT_LIMIT = 5000000;
var InMemoryStorage = function () {
this.storage = {};
this.size = 0;
};
_.extend(InMemoryStorage.prototype, {
setItem: function (key, value) {
@cmaher
cmaher / gistbook.json
Created December 9, 2014 15:20
Sample components of client-side architecture
{"title":"Sample components of client-side architecture","author":"cmaher","pages":[{"pageName":"","sections":[{"type":"javascript","source":"var SharedContextModel = Backbone.Model.extend({\n\tinitialize: function () {\n\t\tthis.set(JSON.parse($('#initialContext').html()));\n\t},\n\n\tpushChangesTo: function (other) {\n\t\tother.set(this.toJSON());\n\t\tother.listenTo(this, 'change', _.bind(function () {\n\t\t\tother.set(this.toJSON());\n\t\t}, this));\n\t}\n});"},{"type":"javascript","source":"var BaseAppRouter = Marionette.AppRouter.extend({\n\n initialize: function(options) {\n \tthis.sharedContextModel = options.sharedContextModel;\n this.listenTo(this.sharedContextModel, 'change', this._setQueryString);\n },\n\n _setQueryString: function() {\n // get a new set of params consisting of the old params extended by new params from the SCM\n var newParams = this.sharedContextModel.toJSON();\n var oldParams = $.url().param();\n var allParams = _.extend({}, oldPara
@cmaher
cmaher / es6-backbone-events
Last active August 29, 2015 14:12
Export BackboneEvents as a standalone ES6 module
# assumes GNU Sed
# for OSX: `brew install gnu-sed; alias sed=gsed`
# Known to work with Bacbone 1.1.2
echo " import _ from 'lodash';
var root = {};
var Backbone = {};
var $;
$(sed '/^\s*\/\/\s*Initial Setup\s*$/,/^\s*\/\/\s*Backbone.Model\s*$/{//!b};d' backbone.js)
export default Events;" > backbone.events.js
@cmaher
cmaher / hoard-model.js
Created January 16, 2015 22:53
Using Hoard with a Model
var cacheControl = new Backbone.Hoard.Control();
var MyModel = Backbone.Model.extend({
url: function () {
return '/my-models/' + this.id;
},
sync: cacheControl.getModelSync()
});
@cmaher
cmaher / hyper-show-hide.ahk
Created October 2, 2017 12:50
AHK script for replacing hyper-summon with WSL
^`::
IfWinExist, Hyper
{
if WinActive("Hyper")
{
Send !{Escape}
}
else
{