title | layout | prism_languages | updated | category | source | |
---|---|---|---|---|---|---|
PostgreSQL JSON |
2017/sheet |
|
2017-09-22 |
Databases |
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
=begin | |
Given 2 water jugs of different sizes and an unlimited source of water, perform different operations to end up with some goal amount of water. | |
Write out the operations and how much water is in the jugs at each step. | |
Problem 1 --- Small = 3, Big = 5, Goal = 4 | |
- Start (0, 0) | |
- Fill small (3, 0) | |
- pour to big (0, 3) | |
- Fill small (3, 3) |
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
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 |
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
/* | |
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 | |
*/ |
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
# @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 |
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
nc -vz google.com 80 | |
# Connection to google.com 80 port [tcp/http] succeeded! |
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
ssh -fN -L 5433:db.prod:5432 bastion-prod | |
aws s3 cp s3://<dir>/prod/ . --recursive --exclude "*" --include "201901*" |
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
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)) |
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
// === Arrays | |
var [a, b] = [1, 2]; | |
console.log(a, b); | |
//=> 1 2 | |
// Use from functions, only select from pattern | |
var foo = () => [1, 2, 3]; |
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
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 |
NewerOlder