Skip to content

Instantly share code, notes, and snippets.

@katspaugh
katspaugh / suggest.js
Created January 13, 2011 20:58
Displays a suggestions box.
(function (globals, exports, $, doc) {
/*
** Takes one @options argument with properties:
** - 'list' -- a hashtable or array of possible suggestions,
** - 'propName' -- a property with suggestions in the hashtable,
** - 'input' -- an input element or input selector,
** - 'callback' -- what to do on option select,
** - 'focusFirst' -- whether to set focus on the first option,
** - 'meaningfulLength' -- how many characters can provide meaning.
*/
@katspaugh
katspaugh / .vimrc
Created January 18, 2011 01:04
Alphabetically sorted!
set encoding=utf-8 fileencodings=utf-8
syntax on
"syntax sync fromstart
let no_buffers_menu=1
set backspace=indent,eol,start
set history=50
set hlsearch
set incsearch
@katspaugh
katspaugh / Bash prompt
Created January 20, 2011 20:55
Time, working directory, background jobs, a new line.
export PS1='\t \w {\j}\n> '
@katspaugh
katspaugh / gist:976695
Created May 17, 2011 15:29
createElement proxy
(function (docInstance) {
var Monitor = function () {
return this.init.apply(this, arguments);
};
Monitor.prototype = {
Resources: {
img: true,
script: true
},
@katspaugh
katspaugh / bsearch.js
Created June 10, 2011 08:51
Binary search
Array.prototype.bsearch = function (x) {
var min = 0, max = this.length;
while (min <= max) {
var mid = Math.floor((min + max) / 2),
val = this[mid];
if (val === x) {
return mid;
}
@katspaugh
katspaugh / statusbar.lua
Created June 15, 2011 21:08
dwm statusbar
local function exec (cmd, ...)
local argstr = (table.maxn(arg) == 0 and '') or
string.format(' %q', table.concat(arg))
return os.execute(cmd .. argstr)
end
local function read (cmd)
local prog = io.popen(cmd)
local pout = prog:read('*a')
function until(cond, callback, delay) {
(function fn() {
cond() ? callback() : setTimeout(fn, delay)
})()
}
@katspaugh
katspaugh / observer.js
Created July 22, 2011 12:23
Minimal observer, needed too often.
var Observer = (function () {
'use strict';
return {
on: function (event, fn) {
if (!this.handlers) { this.handlers = {}; }
var handlers = this.handlers[event];
if (!handlers) {
handlers = this.handlers[event] = [];
@katspaugh
katspaugh / getClassList.js
Created September 29, 2011 12:46
classList shim
var getClassList = (function () {
'use strict';
var ClassList = {}, s = ' ';
ClassList.add = function (cl) {
var className = this.element.className,
list = className.split(s);
list.push(cl);
this.element.className = list.join(s);
};
@katspaugh
katspaugh / javascript.vim
Created October 11, 2011 09:13
Highlight trailing JavaScript commas as errors
syn match javaScrParenError /,\(\_s*[\]})]\)\@=/