Skip to content

Instantly share code, notes, and snippets.

View DavidEdwards1's full-sized avatar

DavidEdwards1

View GitHub Profile
require 'csv'
def split_and_tokenise(string_to_tokenise)
string_to_tokenise.to_s.downcase.gsub(/[^a-z0-9]/, ' ').
split(" ").
map { |token| Digest::SHA256.hexdigest token }.
join(" ")
end
def tokenise(string_to_tokenise)
@DavidEdwards1
DavidEdwards1 / brand_power.r
Last active August 21, 2018 15:03
Brand Messaging experiment power analysis code
effect_sizes <- (1:200*0.001+1)
av.monthly.impressions <- 23742/2
av.monthly.click_throughs <- 8367/2
baseline_ctr <- av.monthly.click_throughs/av.monthly.impressions
baseline_signup_rate <- 0.0212 * baseline_ctr
n_samples_ctr <- double(length(effect_sizes))
n_samples_signup_rate <- double(length(effect_sizes))
@DavidEdwards1
DavidEdwards1 / accountant_count.rb
Last active January 24, 2018 16:00
Gist to calculate (roughly) the number of account managers who logged in the last year
switch_to_slave_db
PRACTICES_TO_IGNORE = %w[
12506
17
13699
11040
13952
68
18555
switch_to_slave_db
# not going to be offered if they have ever had mfa bank feed
# so just check for created date of feeds with yodlee_mfa_type
company_bank_feeds = BankFeed.joins(:bank_account).joins(:bank_service).
where('bank_services.yodlee_mfa_type is not null').
group('bank_accounts.company_id').minimum(:created_at)
all_companies = Company.joins(:subscription).
where("subscriptions.cancelled_at > '2017-01-01' or subscriptions.cancelled_at is null").
@DavidEdwards1
DavidEdwards1 / new_banking_rollout.rb
Last active November 23, 2017 11:07
The idea of this gist is to generate the number/proportion of companies that would have to get removed from the new banking rollout if it had gone out on 1st Jan 2017 until 1st Nov 2017. This means that we care about companies that were created before Jan 1st and were still users and any companies created since then.
def check_banking(company,first_compare_date)
# look at vat status on first_compare_date, currently and for the year so far
previous_vat_registration = company.is_vat_registered_on?(first_compare_date)
current_vat_registration = company.is_vat_registered?
vat_registered_this_year = company.is_vat_deregistered? && company.vat_deregistration_effective_date > first_compare_date
# mfa bank feeds, check currently enabled and currently disabled separately
still_enabled_previous_bank_feeds = company.bank_feeds.to_a.
select { |feed| feed.state == 'enabled' }.
@DavidEdwards1
DavidEdwards1 / supervisor-redash-smartos.conf
Created August 23, 2017 21:15
Supervisor config file for smartOS
[inet_http_server]
port = 127.0.0.1:9001
[supervisord]
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:redash_server]
command=/opt/redash/current/bin/run gunicorn -b 127.0.0.1:5000 --name redash -w 4 --max-requests 1000 redash.wsgi:app
@DavidEdwards1
DavidEdwards1 / install-redash.sh
Created August 23, 2017 21:10
Install re:dash on smartOS
#!/bin/bash
#
# This script is an attempt to rewrite the Ubuntu setup script for Redash along with supervisor, nginx,
# PostgreSQL and Redis.
#
# This script is not idempotent and if it stops in the middle, you can't just run it again. You should either
# understand what parts of it to exclude or just start over on a new VM (assuming you're using a VM).
# This sets to immediately exit on a non-zero return status and also
# any unset Environment Variables are flagged as an error