Skip to content

Instantly share code, notes, and snippets.

Tony Pitale tpitale

Block or report user

Report or block tpitale

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tpitale
tpitale / group_and_count_to_date.sql
Last active Aug 29, 2015
Group count by creation date and sum of count-to-date.
View group_and_count_to_date.sql
SELECT created_on, note_count, sum(note_count) OVER (ORDER BY created_on ASC)
FROM (
SELECT date_trunc('day', created_at) AS created_on, count(1) AS note_count
FROM notes
GROUP BY created_on
ORDER BY created_on DESC
) AS note_counting;
-- WHERE created_on >= '2013-01-01'
@tpitale
tpitale / too_clever.rb
Created Mar 29, 2014
Chained enumerable and block arg destructuring
View too_clever.rb
[1,2,3,4,5].each_cons(2).each_with_index do |(a, b), i|
p a
p b
p i
end
View empty-rows-missing.rb
# connection and profile selection skipped
class Pageview
extend Legato::Model
metrics :pageviews
dimensions :pagePath, :date
filter :for_path, &lambda { |path| contains(:pagePath, path) }
end
@tpitale
tpitale / wait_for_notify.rb
Last active Aug 29, 2015
Implementation of wait_for_notify with PG and Celluloid::IO
View wait_for_notify.rb
def wait_for_notify(&block)
io = pg_connection.socket_io
while @listening do
Celluloid::IO.wait_readable(io) # blocks execution, but unblocks this actor
pg_connection.consume_input # fetch any input on this connection
# read the NOTIFY messages off the socket
while notification = pg_connection.notifies do
block.call(
@tpitale
tpitale / data.tsv
Created May 29, 2014
Minimally responsive (flexible width) D3 Bar Chart
View data.tsv
letter frequency
A .08167
B .01492
C .02782
D .04253
E .12702
F .02288
G .02015
H .06094
I .06966
@tpitale
tpitale / gist:93428db182dd44ec52e5
Created Jun 11, 2014
SideBarEnhancement for ST2
View gist:93428db182dd44ec52e5
import os; path=sublime.packages_path(); (os.makedirs(path) if not os.path.exists(path) else None); window.run_command('exec', {'cmd': ['git', 'clone', 'https://github.com/titoBouzout/SideBarEnhancements', 'SideBarEnhancements'], 'working_dir': path})
import os; path=sublime.packages_path(); window.run_command('exec', {'cmd': ['git', 'checkout', '37429739a0452a2dc36343fb7875ba7fcbeb88a9'], 'working_dir': os.path.join(path, 'SideBarEnhancements')})
@tpitale
tpitale / errors_test.js
Created Jul 6, 2014
Failing test for conflict between Errors.content and a model attribute named content
View errors_test.js
// Added to the bottom of tests/unit/model/errors_test.js
var env, store, Person, Dog;
module("unit/model/errors - model.save() triggers errors", {
setup: function() {
Person = DS.Model.extend({
firstName: DS.attr(),
lastName: DS.attr()
});
@tpitale
tpitale / convert_sf_id.js
Last active Aug 29, 2015
Javascript from salesforce id converter to add suffix characters.
View convert_sf_id.js
function convertId(id) {
if (id == null) return id;
id = id.replace(/\"/g, '');
if (id.length != 15) {
return null;
}
var suffix = "";
for (var i = 0; i < 3; i++) {
var flags = 0;
for (var j = 0; j < 5; j++) {
@tpitale
tpitale / always_center.py
Created Aug 27, 2014
Center Sublime Text 2 on current line when changing
View always_center.py
import sublime_plugin
class AlwaysCenterCommand(sublime_plugin.EventListener):
def on_modified(self, view):
sel = view.sel()
region = sel[0] if len(sel) == 1 else None
if region != None:
view.show_at_center(region)
@tpitale
tpitale / one_row.sql
Last active Aug 29, 2015
One row for each association id SQL
View one_row.sql
CREATE OR REPLACE VIEW next_episode_ids AS (
SELECT id, ROW_NUMBER() OVER(PARTITION BY show_id ORDER BY airs_on) AS r
FROM episodes
WHERE airs_on >= NOW()
);
CREATE OR REPLACE VIEW next_episodes AS (
SELECT * FROM episodes WHERE id IN (
SELECT id FROM next_episode_ids WHERE r = 1
)
You can’t perform that action at this time.