Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Fairchild fairchild

  • Procore
  • California
View GitHub Profile
@kerlin
kerlin / get_workers.rb
Last active Jan 22, 2020
Calling the Workday API in Ruby with Savon
View get_workers.rb
#!/usr/bin/env ruby
#
# Example Ruby CLI script to retrieve worker data from Workday
# Call on command line with worker id; prints worker name
# add "request" or "response" after worker id and prints the
# outgoing xml or received hash and exits.
#
# Using Savon version 2 for the SOAP client (2.11.2)
#
# Savon defaults to making the message tag the same as the operation name
@soultech67
soultech67 / ruby_readline_issue.md
Last active Apr 6, 2020
ruby bundler: Sorry, you can't use byebug without Readline
View ruby_readline_issue.md

Preamble

On OS/X Sierra, after recently running a brew update I started receiving the error message Sorry, you can't use byebug without Readline when trying to run some rake tasks in my ruby project folder. I observed this in projects and gems that include byebug or pry in their Gemfile or gem.spec. I've found in my googling that many begin encountering this error message after running a brew update but there are other triggering conditions as well.

>> rake aws:show_config
WARN: Unresolved specs during Gem::Specification.reset:
      mime-types (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
    Sorry, you can't use byebug without Readline. To solve this, you need to
@keithpitt
keithpitt / database_state_loader.rb
Last active May 21, 2020
Note that this code only works with PostgreSQL, but it wouldn’t be too hard to adapt our approach for other relational databases.
View database_state_loader.rb
# Add to `spec/support/database_state_loader.rb`
class DatabaseStateLoader
class EnvironmentError < RuntimeError; end
def self.load(path)
new(path).load
end
def initialize(path)
@elsonrodriguez
elsonrodriguez / fast-sc.yaml
Last active Feb 12, 2019
Superset/Caravel on Kubernetes
View fast-sc.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
name: fast
provisioner: kubernetes.io/gce-pd
parameters:
type: pd-ssd
View Effective_Engineer.md

FWIW: I'm not the author of the content presented here (which is an outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?

View nps_queries.sql
/*NPS ROLLING 30-DAYS AVG AND DAILY SCORE CHART*/
SELECT a.date,
a.net_promoters / a.responses * 100 AS score,
(SUM(b.net_promoters)
/
SUM(b.responses)) * 100 AS score_30d
FROM (
SELECT date(s.created_at) AS date,
SUM(CASE WHEN s.score >= 9 THEN 1.0
WHEN s.score <= 6 THEN -1.0
@odewahn
odewahn / error-handling-with-fetch.md
Last active Sep 17, 2020
Processing errors with Fetch API
View error-handling-with-fetch.md

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
  })
@valyala
valyala / README.md
Last active Sep 15, 2020
Optimizing postgresql table for more than 100K inserts per second
View README.md

Optimizing postgresql table for more than 100K inserts per second

  • Create UNLOGGED table. This reduces the amount of data written to persistent storage by up to 2x.
  • Set WITH (autovacuum_enabled=false) on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we never DELETE or UPDATE the table).
  • Insert rows with COPY FROM STDIN. This is the fastest possible approach to insert rows into table.
  • Minimize the number of indexes in the table, since they slow down inserts. Usually an index on time timestamp with time zone is enough.
  • Add synchronous_commit = off to postgresql.conf.
  • Use table inheritance for fast removal of old data:
@duffn
duffn / creating_a_date_dimension_table_in_postgresql.sql
Last active Aug 20, 2020
Creating a date dimension table in PostgreSQL
View creating_a_date_dimension_table_in_postgresql.sql
DROP TABLE if exists d_date;
CREATE TABLE d_date
(
date_dim_id INT NOT NULL,
date_actual DATE NOT NULL,
epoch BIGINT NOT NULL,
day_suffix VARCHAR(4) NOT NULL,
day_name VARCHAR(9) NOT NULL,
day_of_week INT NOT NULL,
You can’t perform that action at this time.