Skip to content

Instantly share code, notes, and snippets.

View ianstarz's full-sized avatar

Ian Storz ianstarz

View GitHub Profile
# 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
/* 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;
@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)