This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set -- a 'b c' d | |
| ruby -e 'puts %($*), ARGV.map { " #{_1.inspect}" }, ""' $* | |
| ruby -e 'puts %("$*"), ARGV.map { " #{_1.inspect}" }, ""' "$*" | |
| ruby -e 'puts %($@), ARGV.map { " #{_1.inspect}" }, ""' $@ | |
| ruby -e 'puts %("$@"), ARGV.map { " #{_1.inspect}" }, ""' "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pg' | |
| require 'json' | |
| $db = PG.connect | |
| $db.exec <<~SQL | |
| create table if not exists outbox ( | |
| id serial primary key, | |
| processed bool default false not null, | |
| payload jsonb not null | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create table xs (id varchar primary key); | |
| create table ys (id serial primary key, x_id varchar); -- first value joined to x | |
| create table zs (id serial primary key, x_id varchar); -- second value joined to x | |
| -- x's ids are tuples of (number of associated ys, number of associated zs) | |
| insert into xs (id) values ('0,0'), ('1,0'), ('2,0'), ('2,1'), ('2,2'); | |
| insert into ys (x_id) values ('1,0'), ('2,0'), ('2,0'), ('2,1'), ('2,1'), ('2,2'), ('2,2'); | |
| insert into zs (x_id) values ('2,1'), ('2,2'), ('2,2'); | |
| -- So, how does pg fill the rows in with the left join? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This rebuilds the ancestry for `closure_tree` gem with a single query (https://github.com/ClosureTree/closure_tree) | |
| # (rather than the ungodly number of queries it currently uses, which makes it extremely slow) | |
| # ESTABLISH DATABASE CONNECTION | |
| require 'pg' | |
| db = PG.connect dbname: 'nuvocargo_development' | |
| def db.exec(...) | |
| super(...).map { _1.transform_keys &:to_sym } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module DefaultArgs | |
| NOT_SET = Module.new | |
| private def set?(value) = value != NOT_SET | |
| private def not_set?(value) = !set?(value) | |
| # This is the solution that I came up with: | |
| # def self.extended(base) | |
| # base.const_set :NOT_SET, NOT_SET | |
| # super | |
| # end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- vi: ft=pgsql | |
| -- Nice prompt: | |
| -- Modified from here: https://stackoverflow.com/a/19155772 | |
| -- Docs are here: https://www.postgresql.org/docs/9.3/app-psql.html#APP-PSQL-PROMPTING | |
| \set PROMPT1 '%[%033[33m%]%n%[%033[0m%]@%[%033[1;33m%]%/%[%033[0m%]%R ' | |
| \set PROMPT2 :PROMPT1 | |
| -- Nuvocargo specific changes | |
| do $$ begin if exists (select 1 from pg_catalog.pg_namespace where nspname = 'airtable') then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " ===== Smallest Viable Configuration ===== | |
| set nocompatible " Behave more usefully at the expense of backwards compatibility (this line comes first b/c it alters how the others work) | |
| set encoding=utf-8 " Format of the text in our files (prob not necessary, but should prevent weird errors) | |
| filetype plugin on " Load code that configures vim to work better with whatever we're editing | |
| filetype indent on " Load code that lets vim know when to indent our cursor | |
| syntax on " Turn on syntax highlighting | |
| set backspace=indent,eol,start " backspace through everything in insert mode | |
| set expandtab " When I press tab, insert spaces instead | |
| set shiftwidth=2 " Specifically, insert 2 spaces | |
| set tabstop=2 " When displaying tabs already in the file, display them with a width of 2 spaces |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Oh my fucking god, setting the session cookie's SameSite attribute is... | |
| utterly unclear. I thiiiiiiiiiiink you do this, but got timeboxed :P | |
| soooo, moving on with my fkn life | |
| ```ruby | |
| config.session_store :cookie_store, | |
| key: "_nuvocargo_session", | |
| secure: true, # I think :shrug: | |
| same_site: lambda { |req, res| | |
| # I think this should set it to "None" when the request comes from https://deploy-preview-$PR_NUMBER--nuvo-internal-stage.netlify.app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| /* | |
| ruby -e ' | |
| n = 0x5f3759df.to_s(2) | |
| n = "0 10000010 01011".ljust(32, "0").delete(" ") | |
| n = "0 01000001 00010000000000000000000" | |
| n = "0 10111110 01101110101100111011111" | |
| n = n.ljust(32, "0").delete(" ") | |
| sign = (-1) ** n[0].to_i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pg' | |
| db1 = PG.connect | |
| db2 = PG.connect | |
| db3 = PG.connect | |
| # setup (db1) | |
| db1.exec "drop table if exists strs;" | |
| db1.exec "create table strs(val text);" | |
| 1.upto(100) { |i| db1.exec_params "insert into strs(val) values ($1)", [i.to_s] }; |