Skip to content

Instantly share code, notes, and snippets.

View thomas-mcdonald's full-sized avatar

Thomas McDonald thomas-mcdonald

View GitHub Profile
SELECT
functions.id,
functions.slug,
ts_rank(setweight(to_tsvector('english', functions.name), 'A') || setweight(to_tsvector('english', coalesce(functions.search_docs,'')), 'B'), query) as rank
FROM (
SELECT DISTINCT on (functions.slug) functions.*
FROM functions
INNER JOIN "klasses" ON "klasses"."id" = "functions"."klass_id"
INNER JOIN "versions" ON "versions"."id" = "klasses"."version_id"
ORDER BY functions.slug ASC, string_to_array(regexp_replace(versions.name, '[^0-9.]', '', 'g'), '.')::int[] DESC
libref_dev=# EXPLAIN ANALYZE SELECT "functions".* FROM "functions" INNER JOIN "klasses" ON "klasses"."id" = "functions"."klass_id" INNER JOIN "versions" ON "versions"."id" = "klasses"."version_id" WHERE "versions"."project_id" = 2 AND "functions"."slug" = 'ActionController/ParameterEncoding/ClassMethods/instance/skip_parameter_encoding' ORDER BY string_to_array(regexp_replace(versions.name, '[^0-9.]', '', 'g'), '.')::int[] ASC;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=3189.68..3189.69 rows=1 width=1279) (actual time=45.787..45.788 rows=2 loops=1)
Sort Key: ((string_to_array(regexp_replace((versions.name)::text, '[^0-9.]'::text, ''::text, 'g'::text), '.'::text))::integer[])
Sort Method: quicksort Memory: 29kB
-> Nested Loop (cost=18.84..3189.67 rows=1 width=1279) (actual time=3.918..45.772 r
@thomas-mcdonald
thomas-mcdonald / attempt1.txt
Last active September 22, 2019 20:13
3n -> n query playground
SELECT * FROM (
SELECT "functions".* FROM "functions" WHERE "functions"."klass_id" = 242 AND "functions"."name" = 'change'
UNION
SELECT "functions".* FROM "functions" WHERE "functions"."klass_id" = 661 AND "functions"."name" = 'change'
UNION
SELECT "functions".* FROM "functions" INNER JOIN "klasses" ON "klasses"."id" = "functions"."klass_id" INNER JOIN "versions" ON "versions"."id" = "klasses"."version_id" WHERE "versions"."id" = 1 AND "functions"."name" = 'change'
) as subquery LIMIT 1
however postgres will execute all union queries even if the first query returns a result
@thomas-mcdonald
thomas-mcdonald / instrumentation.rb
Created August 8, 2019 13:47
count number of active record objects instantiated
ActiveSupport::Notifications.subscribe "instantiation.active_record" do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
RequestStore.store[:object_count] ||= 0
RequestStore.store[:object_count] += event.payload[:record_count]
end
ActiveSupport::Notifications.subscribe "process_action.action_controller" do
Rails.logger.info "AR Object count: #{RequestStore.store[:object_count]}"
end
import { ISelectProps } from "@blueprintjs/labs";
import * as React from "react";
import { DropdownButton } from "./DropdownButton";
interface IDisableableSelectProps {
disabled?: boolean;
text: string;
}
export function disableableSelect<T>(
@thomas-mcdonald
thomas-mcdonald / linkextract.php
Created February 2, 2013 12:29
MediaWiki internal link handler
function replaceInternalLinks2( &$s ) {
static $tc = FALSE, $e1, $e1_img;
# the % is needed to support urlencoded titles as well
if ( !$tc ) {
$tc = Title::legalChars() . '#%';
# Match a link having the form [[namespace:link|alternate]]trail
$e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
# Match cases where there is no "]]", which might still be images
$e1_img = "/^([{$tc}]+)\\|(.*)\$/sD";
}
@thomas-mcdonald
thomas-mcdonald / union.hs
Created January 13, 2013 21:09
union lol
union [] [] = []
union [] ys = ys
union xs [] = xs
union (x@(n,_):xs) ys
| has n ys = (join x (find n ys)):(union xs (without n ys))
| otherwise = x:(union xs ys)
where
find p = filter (\x -> fst x == p)
without p = filter (\x -> fst x != p)
has p = length (find p) != 0
@thomas-mcdonald
thomas-mcdonald / brew --config
Last active December 10, 2015 12:58
gst-plugins-ugly homebrew ticket
> brew --config ~
HOMEBREW_VERSION: 0.9.3
HEAD: 4baf64237d8fefba68a24e2237d08311592f00bb
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit ivybridge
OS X: 10.8.1-x86_64
Xcode: 4.5.2
CLT: 4.5.0.0.1.1249367152
LLVM-GCC: build 2336
@thomas-mcdonald
thomas-mcdonald / gist:4380609
Created December 26, 2012 14:27
cdrtools binaries
> brew install cdrtools
==> Downloading ftp://ftp.berlios.de/pub/cdrecord/cdrtools-3.00.tar.gz
######################################################################## 100.0%
######################################################################## 100.0%==> make INS_BASE=/usr/local/Cellar/cdrtools/3.00 INS_RBASE=/usr/local/Cellar/cdrtools/3.00 install
/usr/local/Cellar/cdrtools/3.00: 176 files, 1.8M, built in 55 seconds
> brew list cdrtools
/usr/local/Cellar/cdrtools/3.00/etc/default/rscsi
/usr/local/Cellar/cdrtools/3.00/include/scg/ (12 files)
/usr/local/Cellar/cdrtools/3.00/include/schily/ (101 files)
@thomas-mcdonald
thomas-mcdonald / gist:2950487
Created June 18, 2012 20:21
Madeon over HTTP
require 'gst'
require 'sinatra'
class App < Sinatra::Application
configure do
Gst.init
@@pipeline = Gst::ElementFactory.make("playbin2")
@@pipeline.uri = GLib.filename_to_uri(File.expand_path(File.dirname(__FILE__)) + '/icarus.mp3')
end