Skip to content

Instantly share code, notes, and snippets.

View timm-oh's full-sized avatar
🐰

Tim McCarthy timm-oh

🐰
View GitHub Profile
@timm-oh
timm-oh / .zshrc
Last active July 27, 2023 13:44
Creates git branching name according to a specific format
# All other config
# Usage
# $ git:(main) new-task "Setup dockerfile for development"
# $ git:(tim.mccarthy/setup-dockerfile-for-development)
function new-task () {
main_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
username=$(git config user.name | tr '[:blank:]' '.')
branch_detail=$(echo $1 | sed 's/[^[:blank:][:alnum:]-]//g' | tr '[:blank:]' '-')
@timm-oh
timm-oh / .iex.exs
Last active February 1, 2024 20:47
Elixir phoenix docker setup
:logger.debug("""
> `docker attach $(docker compose ps web -q)` to attach IEx.pry()
> Ctrl + P + Q to detach from the container terminal
""")
@timm-oh
timm-oh / create_review_app.rb
Last active May 5, 2022 12:25
Heroku 'Review app' setup
require 'json'
pipeline = "PIPELINE_UUID"
pipeline_owner = "enterprise_team_name or email_address"
name = "heroku_app_name"
# CREATE APP
`heroku apps:create #{name} --team=#{pipeline_owner} --region=eu` # using eu region, otherwise it defaults to us
info_output = `heroku apps:info #{name} --json`
app_info = JSON.parse(info_output)
@timm-oh
timm-oh / Dockerfile
Last active November 3, 2022 14:15
Docker / esbuild combination
ARG RUBY_VERSION=3.1.2
FROM ruby:$RUBY_VERSION-bullseye as builder
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 \
LANG=C.UTF-8 \
BUNDLE_RETRY=3 \
BUNDLE_PATH=/gems
ARG RAILS_ENV=production
ENV RAILS_ENV $RAILS_ENV
# This is needed during the build process because when precompiling assets, the
@timm-oh
timm-oh / build.js
Created April 12, 2022 15:41
esbuild config file with live reloading for rails
#!/usr/bin/env node
import esbuild from "esbuild"
import chokidar from "chokidar"
import http from "http"
const watchDirectories = [
"./app/assets/builds/*",
"./app/views/**/*.erb",
]
@timm-oh
timm-oh / 500.html.erb
Created March 13, 2022 16:30
ERB in error templates without a custom controller
<!-- app/views/errors/500.html.erb -->
<!DOCTYPE html>
<html>
<head>
<title><%= "SUPER COOL TITLE" %></title>
</head>
</html>
@timm-oh
timm-oh / parallel
Created January 26, 2022 13:30 — forked from mjambon/parallel
bash: Run parallel commands and fail if any of them fails
#! /usr/bin/env bash
#
# Run parallel commands and fail if any of them fails.
#
set -eu
pids=()
for x in 1 2 3; do
@timm-oh
timm-oh / decoder.rb
Last active July 3, 2021 09:34
Peach Webhook Decrypter
class PeachPayments::Decoder
def initialize(body:, auth_tag:, iv:, key:)
@body = body
@key = key
@auth_tag = auth_tag
@iv = iv
end
def decode
packed_key, packed_iv, packed_auth_tag, packed_body = *[
@timm-oh
timm-oh / snippet.rb
Last active January 13, 2021 04:52
Ozow integration
# refer to https://ozow.com/integrations/ for more information
# Ordering with the params matters, see the link above for more information
ozow_params = {
'SiteCode': 'SOME_SITE_CODE', # find this here https://dash.ozow.com/MerchantAdmin/Site
'CountryCode': 'ZA', # only supports ZA currently
'CurrencyCode': 'ZAR', # only supports ZAR currently
'Amount': 1000, # this is R1000, not working well for floats though
'TransactionReference': 'SOME_TEST', # your internal reference to match against
'BankReference': "Nice Reference", # the reference that the customer will see on their bank statement
@timm-oh
timm-oh / hash_helper.rb
Created December 26, 2020 17:07
Helper method to convert from dot notation to hash
def dot_to_hash(value)
return value unless value.is_a?(Hash)
value.deep_stringify_keys.each_with_object({}) do |(k,v), result|
root, child = k.split('.')
if child
result[root] ||= {}
result[root][child] = dot_to_hash(v)
else
result[root] = dot_to_hash(v)
end