Skip to content

Instantly share code, notes, and snippets.

@dramsay
dramsay / format_segments.rb
Created February 11, 2020 14:14
Formatting segment targets
def format_segments(segment_string)
groups = segment_string.split(/\)\(/)
groups.map do |group|
group.scan(/\d+/).join(',')
end.join(')(').prepend('(') << ')'
end
SELECT
pid,
now() - pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
-- can take a few minutes
SELECT pg_cancel_backend(__pid__);
explain (analyze on, timing on) select * from foo where id = 500000;
QUERY PLAN
— — — — — — — — — — — — — — —
Index Scan using foo_id_ix on foo (cost=0.42..8.44 rows=1 width=37) (actual time=0.026..0.028 rows=1 loops=1)
Index Cond: (id = 500000)
Execution time: 0.060 ms
@dramsay
dramsay / spec_helper.rb
Last active November 8, 2019 22:08
Rspec configuration
unless ENV['NO_COVERAGE']
require 'simplecov'
SimpleCov.start do
add_filter ".bundle"
end
end
require 'capybara/rspec'
require 'factory_bot_rails'
require 'webmock/rspec'
@dramsay
dramsay / layout-indicator.css
Created September 9, 2019 13:58
Layout indicator
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
* * * * * * * { background-color: rgba(255,0,0,.2); }
* * * * * * * * { background-color: rgba(0,255,0,.2); }
* * * * * * * * * { background-color: rgba(0,0,255,.2); }
@dramsay
dramsay / rss_restriction.rb
Created August 28, 2019 20:49
RSS media restriction
RssRestriction.create!(podcast: p, relationship: 'allow', type_of: 'country', values: ["AR", "AT", "AU", "BE", "BG", "CA", "CL", "CR", "CY", "CZ", "DK", "EC", "SV", "EE", "FI", "FR", "DE", "GB", "GT", "HK", "HU", "ID", "IE", "IL", "IN", "IT", "JP", "LV", "LI", "MY", "MT", "MX", "NL", "NZ", "NI", "NO", "PA", "PY", "PE", "PH", "PL", "PT", "RO", "SG", "SE", "CH", "TH", "TR", "UY", "US", "VN", "ZA"])
@dramsay
dramsay / barometric.rb
Last active July 17, 2019 16:00
Barometric example
order_id = '066b507c-984d-11e9-b068-0b0f7dbba186'
o = Order.find('066b507c-984d-11e9-b068-0b0f7dbba186')
o.title
o.attribution_type = Order.attribution_types[:barometric]
o.attribution_project_id = 6815
o.attribution_exposure_group_id = 100712
o.attribution_control_group_id = -1
o.generate_control_groups(0)
o.save!
@dramsay
dramsay / wbur.rb
Created June 28, 2019 13:52
WBUR Campaign Split
# NOTE - on first pass this only updated the orders for the 'On Point' podcast/campaign - perhaps due to the audio
# file processing on the other order advertisements?
creatives = {
'Circle Round' => [
'https://00e9e64bac22859a14fba4a1ec05abf492e8f152d6f6015cf7-apidata.googleusercontent.com/download/storage/v1/b/wb-creatives-20190627/o/Circle%20Round%2FCircleRound-Xfinity2-MID.mp3?qk=AD5uMEvXRftRjhgwopknKkca24_DBRXK-896DtZLwwyA_h8ZpRmZAZ3Uuv-AcAKXaDQdoBB_xDoXrNDDOLABhsMvUeqBFs2JVe_svDJds1eVWkPTV3sFxv7yIhVmwwEqWNuLMEsaH6tbzVwjWOjThToRxbWBd1Y-q7Sd0D5o_vpewRAEFikn1JfQQcoe5P4IVgHuCyubfzpgNIm4DwO-ATKNL1fMjVW8RhG2tAf0T4sZEUGliOOVxPRYagxKBHsnIleb8nuw7moQDHfBZG91ceQTbFC0W5nwamfZrccIZUY9QvyMz1Kbd8Hh89hP4QgNNdZuNki9f9T6ATi5U6hyx4Uiah1gwb44OuwDJbUmjoAx1kwv3NPt-wGRZPOGpzBFqkyDacd3KrOR2cmp4ddfzDigUNPsFHs8kxt2iRlXxAeyspwgHDiU67wRwg0ophxV5zz_Bcrj2G3jhrJcjrmUhCsyxE5jr4H98iG9ywocAkxY_Px8WLKnoYs71JEIt9XJRNHHPAhi3I6Wyg13qobluzE5_9fJb9ksmU62c7P3NA1rcZNyIhfGncBg2TMOyYcemb7q_QUaVsJxsDiaZ_8DqVYVI-vprAHLL6xEHHMSTtpfB_MziFnAaK
# use by calling from command line and passing in path to file
# ruby anonymizer.rb /path/to/metrics_file.csv
require 'csv'
require 'securerandom'
HASHED_IP = %r|ip$|
IDENTIFIERS = %r[id$]
SECONDS = %r|seconds_downloaded|
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
or
psql: could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?