Skip to content

Instantly share code, notes, and snippets.

View tmartin8080's full-sized avatar
๐Ÿ 
๐Ÿก

Troy Martin tmartin8080

๐Ÿ 
๐Ÿก
View GitHub Profile
@tmartin8080
tmartin8080 / big-o.md
Created November 16, 2021 16:47 — forked from PJUllrich/big-o.md
Big-O Time Complexities for Elixir Data Structures
@tmartin8080
tmartin8080 / Map.Helpers
Created February 24, 2020 13:44 — forked from kipcole9/Map.Helpers
Helpers for Elixir Maps: underscore, atomise and stringify map keys
defmodule Map.Helpers do
@moduledoc """
Functions to transform maps
"""
@doc """
Convert map string camelCase keys to underscore_keys
"""
def underscore_keys(nil), do: nil
@tmartin8080
tmartin8080 / with_example.ex
Created February 8, 2020 23:27 — forked from devonestes/with_example.ex
Further refactoring of a with statement
# Step 1
def create_subscription(email, plan_id, payment_method_id) do
with %User{customer_id: nil, name: name} = user <-
Repo.get_by(User, email: email),
{:ok, %Stripe.Customer{id: customer_id}} <-
Stripe.Customer.create(%{
name: name,
email: email,
payment_method: payment_method_id,
@tmartin8080
tmartin8080 / sidekiq_cheat_sheet.md
Last active November 12, 2019 18:42 — forked from wakproductions/sidekiq_cheat_sheet.md
Sidekiq Commands Cheat Sheet
@tmartin8080
tmartin8080 / z.md
Created November 8, 2019 12:26 — forked from mischah/z.md
Installing und initializing z (https://github.com/rupa/z) with help of Homebrew.

#The power of z

Do you spend lots of time doing things like this?

cd this/is/the/path/that/i/want/so/i/type/it/all/out/to/get/whereiwant

With z, you could just do this:

@tmartin8080
tmartin8080 / error-handling-with-fetch.md
Created September 19, 2019 18:59 — forked from odewahn/error-handling-with-fetch.md
Processing errors with Fetch API

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
 })
@tmartin8080
tmartin8080 / install_elixir.md
Created November 30, 2018 16:11 — forked from rubencaro/install_elixir.md
Elixir installation guide

Elixir installation guide

Version numbers should be the ones you want. Here I do it with the last ones available at the moment of writing.

The simplest way to install elixir is using your package manager. Sadly, at the time of writing only Fedora shows the intention to keep its packages up to date. There you can simply sudo dnf install erlang elixir and you are good to go.

Anyway, if you intend to work with several versions of erlang or elixir at the same time, or you are tied to a specific version, you will need to compile it yourself. Then asdf is your best friend.

@tmartin8080
tmartin8080 / measure.md
Created July 15, 2018 20:35 — forked from pglombardo/measure.md
Comprehensive Guide to Ruby Performance Benchmarking

GC.disable

Wall Clock Time versus CPU Time

An important difference to note is the how time is reported by various measurement methods. Wall clock time is the actual time passed in terms of human perception whereas CPU time is the time spent processing the work. CPU time doesn't include any delays waiting on resources to free up such as thread interrupts or garbage collection.

The Work to Measure

To keep things simple, we'll create a Ruby Proc and just repeatedly call that Proc for each of the measurement methods below.

@tmartin8080
tmartin8080 / rails http status codes
Created June 27, 2018 03:08 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@tmartin8080
tmartin8080 / deployUser.md
Created June 26, 2018 22:41 — forked from learncodeacademy/deployUser.md
Adding a deploy user in Linux

(wherever it says url.com, use your server's domain or IP)

Login to new server as root, then add a deploy user

sudo useradd --create-home -s /bin/bash deploy
sudo adduser deploy sudo
sudo passwd deploy

And Update the new password