Skip to content

Instantly share code, notes, and snippets.

List *tree;
char *str;
str = StringValueCStr(input);
tree = raw_parser(str);
str = nodeToJSONString(tree);
// Save stderr for result
read(stderr_pipe[0], stderr_buffer, STDERR_BUFFER_LEN);
/*
* raw_parser
* Given a query in string form, do lexical
* and grammatical analysis.
*
* Returns a list of raw (un-analyzed) parse trees.
*/
List *
raw_parser(const char *str)
{
AVG | QUERY
---------------------------------------------------------------------------------
96.5ms | SELECT q.classification, date_part(?, qsh.collected_at) AS collected_at, SUM(qsh.total_time) / SUM(qsh.calls) AS avg FROM query_snapshot_hourlies qsh JOIN queries q ON (qsh.query_id = q.id) WHERE qsh.database_id = ? AND qsh.collected_at BETWEEN ? AND ? AND q.database_id = ? AND NOT truncated GROUP BY q.classification, qsh.collected_at ORDER BY qsh.collected_at
87.4ms | SELECT q.id AS query_id, normalized_query, classification, SUM(total_time) AS total_time, SUM(calls) AS calls, SUM(total_time) / SUM(calls) AS avg_time FROM query_snapshot_hourlies qsh JOIN queries q ON (qsh.query_id = q.id) WHERE qsh.database_id = ? AND qsh.collected_at BETWEEN ? AND ? AND q.database_id = ? AND NOT truncated AND (q.classification IS NULL OR q.classification IN (?)) GROUP BY q.id
47.9ms | SELECT "schema_indices".* FROM "schema_indices" INNER JOIN "schema_tables" ON "schema_indices"."table_id" = "schema_tables"."id" WHER
require 'rubygems'
require 'mixlib/cli'
require 'pg'
require 'curses'
class CLIHelper
include Mixlib::CLI
option :database,
short: "-d DATABASE",
AVG | QUERY
--------------------------------------------------------------------------------
1.5ms | SELECT "users".* FROM "users"
0.1ms | SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?
0.1ms | UPDATE "users" SET "fullname" = $1, "updated_at" = $2 WHERE "users"."id" = ?
0.0ms | SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1
@lfittl
lfittl / bad.rb
Last active August 29, 2015 14:04
Rails default_scope = evil
class Notification
belongs_to :user
default_scope { order('id desc') }
end
class User
has_many :notifications
end
/usr/bin/walmgr /etc/walmgr/master.ini xarchive %p %f >> /var/log/postgresql/archivecmd.log
lfittl@capricorn:~/Documents/soup/vendor/rails%> git push --tags
error: refs/heads/1-2-stable does not point to a valid object!
error: refs/heads/2-0-stable does not point to a valid object!
error: refs/heads/2-1-stable does not point to a valid object!
error: refs/heads/2-2-stable does not point to a valid object!
error: refs/heads/3-0-unstable does not point to a valid object!
error: refs/heads/active_model does not point to a valid object!
error: refs/heads/master does not point to a valid object!
error: refs/heads/path_refactor does not point to a valid object!
error: refs/heads/wip_abstract_controller does not point to a valid object!
lfittl@capricorn:~/Documents/soup/vendor/rails%> git push
error: refs/heads/1-2-stable does not point to a valid object!
error: refs/heads/2-0-stable does not point to a valid object!
error: refs/heads/2-1-stable does not point to a valid object!
error: refs/heads/2-2-stable does not point to a valid object!
error: refs/heads/3-0-unstable does not point to a valid object!
error: refs/heads/active_model does not point to a valid object!
error: refs/heads/master does not point to a valid object!
error: refs/heads/path_refactor does not point to a valid object!
error: refs/heads/wip_abstract_controller does not point to a valid object!
app@core:/soup/shared/git_cache/vendor$ git clone git@github.com:soup/rails.git rails
Initialized empty Git repository in /soup/shared/git_cache/vendor/rails/.git/
error: refs/heads/1-2-stable does not point to a valid object!
error: refs/heads/2-0-stable does not point to a valid object!
error: refs/heads/2-1-stable does not point to a valid object!
error: refs/heads/2-2-stable does not point to a valid object!
error: refs/heads/3-0-unstable does not point to a valid object!
error: refs/heads/active_model does not point to a valid object!
error: refs/heads/master does not point to a valid object!
error: refs/heads/path_refactor does not point to a valid object!