Skip to content

Instantly share code, notes, and snippets.

View michaelminter's full-sized avatar

Michael Minter michaelminter

View GitHub Profile
@michaelminter
michaelminter / statement_sql.rb
Created November 13, 2019 18:14
Selecting data with group by comparing arrays
# @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
nc -vz google.com 80
# Connection to google.com 80 port [tcp/http] succeeded!
@michaelminter
michaelminter / s3-download.sh
Created September 12, 2019 18:04
Download files from S3 on command line
ssh -fN -L 5433:db.prod:5432 bastion-prod
aws s3 cp s3://<dir>/prod/ . --recursive --exclude "*" --include "201901*"
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 June 27, 2019 06:19 — 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
// === 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 / api_logger.rb
Last active June 17, 2019 04:01 — forked from dblock/api_logger.rb
Rails Grape API logger
class ApiLogger < Grape::Middleware::Base
def before
Rails.logger.info "[api] Requested: #{request_log_data.to_json}\n" +
"[api] #{response_log_data[:description]} #{response_log_data[:source_file]}:#{response_log_data[:source_line]}"
end
private
def request_log_data
@michaelminter
michaelminter / branch-color.sh
Created October 1, 2012 17:47 — forked from yujiberra/gist:1144329
Bash profile with color current git branch color coded by status
# Git status bash prompt
#
# In addition to printing the current working directory, this prompt will
# show a number of things if you are in a git repository:
# - The current branch you are in
# - Whether there are untracked files in the repository (there will be an
# asterisk after the branch nome if there are)
# - Whether there are any unmerged/unstaged/staged changes or if the directory
# is clean. See below for the colors that will be used, and change them if
# you'd like.
@michaelminter
michaelminter / notes.md
Created November 14, 2012 18:05
FIXME, TODO, and OPTIMIZE code comments

You can add some special notes to your source code comments in Rails to remind you later of stuff you need to do:

class Article < ActiveRecord::Base
  # TODO add named_scopes
  # FIXME method A is broken
  # OPTIMIZE improve the code 

  has_many :comments
  ....

end

module Contents
class ExerciseWrapper < Contents::BaseWrapper
attribute :name, String
attribute :type
validate :name, presence: true
def to_fhir
{
one: :attribute_name,