Skip to content

Instantly share code, notes, and snippets.

View ryantuck's full-sized avatar
🤙
chillin'

Ryan Tuck ryantuck

🤙
chillin'
View GitHub Profile

Get some high-level data on our sends table.

select
    min(sent_on) as first_date,
    max(sent_on) as latest_date,
    count(*) as total_records,
    count(distinct template) as unique_templates,
    count(distinct sent_on) as unique_dates
from
@ryantuck
ryantuck / sql_201.sql
Created December 1, 2017 23:02
Some SQL 201 tricks for parsing email data
with
email_data as (
select
s.id as send_id,
s.template,
s.sent_on,
o.opened_on,
case
when opened_on is null then false
@ryantuck
ryantuck / gpg_test.py
Last active April 30, 2024 23:44
working example of using gnupg in python
# install:
# pip3 install python-gnupg
# note - gpg needs to be installed first:
# brew install gpg
# apt install gpg
# you may need to also:
# export GPG_TTY=$(tty)
@ryantuck
ryantuck / facebook_scraping.md
Last active April 12, 2023 17:45
Scraping Facebook data using its Graph API

python sdk

Install facebook SDK

pip3 install facebook-sdk

Pull data:

@ryantuck
ryantuck / sequences.sql
Created September 11, 2017 22:35
messing around with sequences in postgres
drop table if exists seq_test;
create table seq_test as
with
dates as (
select
0 as id,
generate_series(
'2017-01-01'::date,
@ryantuck
ryantuck / balances.txt
Last active May 7, 2017 16:40
nashville bookie calcs
processing split transactions
who | total | each | what
tuck | 130 | 14.44 | Groceries
tuck | 11 | 1.22 | Uber back from groceries
sara | 47 | 7.83 | Dommy doms
tuck | 18 | 3.6 | Lyft to smellrose
sara | 7 | 2.33 | Uber
tuck | 18 | 3.6 | Lyft from santas
tuck | 70 | 10.0 | Lunch
@ryantuck
ryantuck / aux.py
Last active March 14, 2017 19:12
logging demo in python
import logging
log = logging.getLogger('my-app.aux')
def log_this(msg):
if isinstance(msg, int):
log.debug('{} is an int!'.format(msg))
return None
from __future__ import division
from collections import Counter
import itertools
import six
n_dice = 6
n_sides_per_die = 6
options = range(1, n_sides_per_die+1)
@ryantuck
ryantuck / coin_flips.py
Last active February 6, 2017 15:28
Complexity calculation for sorting a list of N items by flipping a coin.
# How many coin flips does it take to randomly shuffle a list of length N?
# My guess is to start with a list of all possible permutations, e.g.
# ABC
# ACB
# BAC
# BCA
# CAB
# CBA
@ryantuck
ryantuck / excel_csv_export.md
Last active March 17, 2017 19:10
How to overcome Excel being shitty with csv outputs

excel / csv hell

Excel has 2 options for outputting csv files:

  • 'CSV UTF-8' yields UTF-8 Unicode English text, with very long lines, with CR line terminators
  • 'Comma Separated Values' yields Non-ISO extended-ASCII English text, with very long lines, with CRLF line terminators

The first option gives you UTF8 encoding but ends lines with this weird ^M character, which is a DOS thing. The second gives you nice unix line breaks but has ASCII encoding which is no good.

So what you need to do is export as 'CSV UTF-8' and then do the following (to make that ^M you need to hit ctrl-V ctrl-M):