Skip to content

Instantly share code, notes, and snippets.

View imedadel's full-sized avatar
🏗️
Building something

Imed Adel imedadel

🏗️
Building something
View GitHub Profile
@imedadel
imedadel / stripe-keys-and-ids.tsv
Created September 27, 2022 20:22 — forked from fnky/stripe-keys-and-ids.tsv
Stripe keys and IDs
Prefix Description Notes
ac_ Platform Client ID Identifier for an auth code/client id.
acct_ Account ID Identifier for an Account object.
aliacc_ Alipay Account ID Identifier for an Alipay account.
ba_ Bank Account ID Identifier for a Bank Account object.
btok_ Bank Token ID Identifier for a Bank Token object.
card_ Card ID Identifier for a Card object.
cbtxn_ Customer Balance Transaction ID Identifier for a Customer Balance Transaction object.
ch_ Charge ID Identifier for a Charge object.
cn_ Credit Note ID Identifier for a Credit Note object.
@imedadel
imedadel / generic-env.go
Created September 23, 2022 21:33
Generic function to load and parse environment variable in Go
func getEnv[T int | string | bool](str string) T {
env, ok := os.LookupEnv(str)
if !ok {
log.Fatalf("%s environment variable required but not set", str)
}
var v T
switch t := any(&v).(type) {
case *string:
*t = env
@imedadel
imedadel / cache.ts
Created September 17, 2022 12:41 — forked from steveruizok/cache.ts
weak map gist
export class Cache<T extends object, K> {
items = new WeakMap<T, K>()
get<P extends T>(item: P, cb: (item: P) => K) {
if (!this.items.has(item)) {
this.items.set(item, cb(item))
}
return this.items.get(item)!
}
@imedadel
imedadel / dockerignore-test.sh
Created September 21, 2020 14:19 — forked from sgdan/dockerignore-test.sh
Test the ".dockerignore" file to ensure the build context doesn't contain unwanted files
#!/bin/sh
# Based on BMitch's answer from:
# https://stackoverflow.com/questions/38946683/how-to-test-dockerignore-file
# Note: will create and delete temporary file "Dockerfile.build-context"
# 1. Copy to project folder where image is being built
# 2. Run script
# 3. You should see list of files in build context
@imedadel
imedadel / setup-ubuntu.sh
Last active September 21, 2020 23:47
Setup AWS EC2 (Elastic Compute Cloud) with Ubuntu 20.04 (Focal), Docker, Docker Compose, and AWS ECR (Elastic Container Registry)
# Docker
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt update
sudo apt install docker-ce
sudo usermod -aG docker ubuntu
# Docker Compose
@imedadel
imedadel / tagged-sql.ts
Created August 22, 2020 14:03
Tagged templates for writing SQL queries for `pg`
export const sql = (query: TemplateStringsArray, ...params: any[]) => ({
text: query.reduce((acc, curr, idx) => acc + '$' + idx + curr),
values: params,
})
// Example
const name = 'joe'
const email = 'joe[at]gmail.com'
// Before
@imedadel
imedadel / docker-localhost.md
Created July 29, 2020 13:00
How to connect to localhost from within Docker
  • Connect to localhost from Docker on Linux:
 docker run --network="host" --rm williamyeh/wrk -t8 -c100 -d30s http://localhost:3000
  • Connect to localhost from Docker on Windows and Linux:
 docker run --network="host" --rm williamyeh/wrk -t8 -c100 -d30s http://host.docker.internal:3000
/* Raster v20 (release package) (rsms.me/raster) */
@import url("https://rsms.me/inter/inter.css");@import url("https://rsms.me/res/fonts/iaw.css");:root{--fontSize:12px;--sansFont:"Inter";--monoFont:"iaw-mono";--lineHeight:calc(var(--fontSize)*1.5);--baseline:calc(var(--lineHeight)/2);--blockSpacingTop:0px;--blockSpacingBottom:var(--lineHeight);--hrThickness:2px;--h1-size:2.8rem;--h2-size:2.2rem;--h3-size:1.4rem;--h4-size:1.1rem;--columnGap:calc(var(--lineHeight)*2);--rowGap:var(--lineHeight);--displayScale:1;--pixel:1px;--foreground-color-rgb:0,0,0;--foreground-color-a:1;--foreground-color:rgba(var(--foreground-color-rgb),var(--foreground-color-a));--background-color:#fff}@supports (font-variation-settings:normal){:root{--sansFont:"Inter var";--monoFont:"iaw-mono-var"}}@media only screen and (-webkit-min-device-pixel-ratio:1.5),only screen and (min-device-pixel-ratio:1.5),only screen and (min-resolution:1.5dppx){:root{--displayScale:2;--pixel:0.5px}}@media only screen and (-webkit-min-device-pixel-ratio:2.5
docker-compose up -d --no-deps --build <service name>
@imedadel
imedadel / 7z-windows.md
Created May 15, 2020 17:37
How to add 7z to bash in Windows

For environment variables:

Right click the Computer icon on your desktop and choose Properties from the menu. Click on the Advanced system settings link and then click Environment Variables. Under the section System Variables, select the environment variable you want to edit, and click Edit