Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Minter michaelminter

View GitHub Profile
View query_class.rb
class BaseQuery
attribute_accessor :object, :query
def initialize
@object = Null
@query = [@object]
end
def execute
@query.map.with_index { |q, i| i == 0 ? q : merge(q) }.join(send '.') # wtf
View sql_template.sql
/*
CONTEXT:
- add a brief description of why we need this query
RESULT EXPECTATION
- add a brief description of your expectations for the query result
ASSUMPTION:
- add assumption about business logic
- add assumption about data
*/
@michaelminter
michaelminter / statement_sql.rb
Created Nov 13, 2019
Selecting data with group by comparing arrays
View statement_sql.rb
# @param [String] account_id
# @param [String] exclusions
def statement(account_id, exclusions = nil)
<<-STATEMENT
SELECT
JSON_AGG(profiles.id) id,
JSON_AGG(users.external_id) external_id
FROM profiles
LEFT JOIN users ON users.id = profiles.user_id
WHERE
View check_connection.bash
nc -vz google.com 80
# Connection to google.com 80 port [tcp/http] succeeded!
@michaelminter
michaelminter / s3-download.sh
Created Sep 12, 2019
Download files from S3 on command line
View s3-download.sh
ssh -fN -L 5433:db.prod:5432 bastion-prod
aws s3 cp s3://<dir>/prod/ . --recursive --exclude "*" --include "201901*"
View postgresql-json.md
View scope_messages_by_two.rb
scope :by_persons, ->(person1, person2) do
arel = Communication.arel_table
up_context1 = arel.grouping(arel[:sender_type].eq(person1.class.name).and(arel[:sender_id].eq(person1.id)))
dn_context1 = arel.grouping(arel[:sender_type].eq(person2.class.name).and(arel[:sender_id].eq(person2.id)))
up_context2 = arel.grouping(arel[:recipient_type].eq(person1.class.name).and(arel[:recipient_id].eq(person1.id)))
dn_context2 = arel.grouping(arel[:recipient_type].eq(person2.class.name).and(arel[:recipient_id].eq(person2.id)))
context1 = arel.grouping(up_context1.or(dn_context1))
context2 = arel.grouping(up_context2.or(dn_context2))
@michaelminter
michaelminter / destructuring.js
Created Jun 27, 2019 — forked from mikaelbr/destructuring.js
Complete collection of JavaScript destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
View destructuring.js
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@michaelminter
michaelminter / csv_to_s3.rb
Created Apr 29, 2019
Upload CSV stream from Rails to S3
View csv_to_s3.rb
def query_results
ActiveRecord::Base.connection.execute('SELECT name FROM accounts;').to_a
end
# @params [Array<Hash>] records
def generate_csv(records)
attributes = records.first.keys
CSV.generate(headers: true) do |csv|
csv << attributes
View exercise_wrapper.rb
module Contents
class ExerciseWrapper < Contents::BaseWrapper
attribute :name, String
attribute :type
validate :name, presence: true
def to_fhir
{
one: :attribute_name,