Skip to content

Instantly share code, notes, and snippets.

View ianstarz's full-sized avatar

Ian Storz ianstarz

View GitHub Profile
@ianstarz
ianstarz / MoveTabCommand.py
Last active January 1, 2016 11:49
A custom command for Sublime Text 2 that is shortcut-able and switches the position of the active tab by moving it forward or back one tab position. For the ocd coders out there that like to maintain a particular tab order without leaving the keyboard. Place the MoveTabCommand.py into your "~/Library/Application Support/Sublime Text 2/Packages/U…
import sublime, sublime_plugin
class MoveTabCommand(sublime_plugin.WindowCommand):
def run(self, mod):
view = self.window.active_view()
group_index, tab_index = self.window.get_view_index(view)
self.window.set_view_index(view, group_index,
(tab_index + int(mod)) % len (
self.window.views_in_group(group_index)) )
self.window.focus_view(view)
/* will return null::json on empty resultset */
SELECT array_to_json(array_agg(row_to_json(t))) FROM t;
/*
will return '[]' on empty resultset,
null::json seems to be managed the same way than sql NULL by COALESCE()
*/
SELECT COALESCE(array_to_json(array_agg(row_to_json(t))), '[]') FROM t;
# GET /project_uploads/1/download
def download
authorize! :download, ProjectUpload
@project_upload = ProjectUpload.find(params[:id])
redirect_to(@project_upload.attachment.expiring_url(10))
end
[core]
editor = subl -n -w
excludesfile = ~/.gitignore_global
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
# Turn on git state in command prompt
GIT_PS1_SHOWDIRTYSTATE=true
# Command prompt with "username path (git state) | "
export PS1='\[\033[1;37m\]\u \[\033[0m\]\w$(__git_ps1)\[\033[1;37m\] | \[\033[0m\]'
@ianstarz
ianstarz / longest-common-prefix.js
Created March 15, 2016 17:24
Find the longest common prefix in a list of strings using only a regex
['aaawhu', 'aaaajkssh', 'aaahwv', 'aaa'].join().match(/^(\w*)\w*(?:,\1\w*)*$/).pop();
@ianstarz
ianstarz / logic-gates.js
Last active April 17, 2022 03:34 — forked from shawndumas/taggedTemplate.js
Build up all the logic gates from nand in js
const logicGates = {
nand (a, b) { return !(a && b); },
not (a) { return this.nand (a, a); },
and (a, b) { return this.not (this.nand (a, b)); },
or (a, b) { return this.nand (this.not (a), this.not(b)); },
nor (a, b) { return this.not (this.or (a, b)); },
xor (a, b) { return this.and (this.nand (a, b), this.or(a, b)); },
xnor (a, b) { return this.not (this.xor (a, b)); }
};
@ianstarz
ianstarz / guid.js
Created March 15, 2016 17:27 — forked from shawndumas/guid.js
GUID
var guid = function fn (n) {
return n ?
(n ^ Math.random() * 16 >> n/4).toString(16) :
('10000000-1000-4000-8000-100000000000'.replace(/[018]/g, fn));
};
@ianstarz
ianstarz / get-home-directory.js
Created June 17, 2016 00:25
Node function to get the user's home directory on mac and windows
module.exports = function() {
return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
}
[0, ['a', 'b', 'c'], 2, 'd', 4, 5, 'f', 7, ['g', 'h'], 9].reduce(function rec (prev, curr) {
if (/array/i.test(curr.constructor)) {
return curr.reduce(rec, prev);
} else if (/string/i.test(curr.constructor)) {
prev.push(curr);
}
return prev;
}, []);