Skip to content

Instantly share code, notes, and snippets.

@musab
musab / objectDefault.ts
Created February 5, 2019 14:27
Set default objects with Object.assign
type MenuConfig = {title?: string, body?: string, buttonText?: string, cancellable?: boolean};
function createMenu(config: MenuConfig) {
const menuConfig = Object.assign({
title: 'Foo',
body: 'Bar',
buttonText: 'Baz',
cancellable: true
}, config);
}
@musab
musab / perf.js
Last active February 11, 2019 18:29
view the amount of time a function takes to execute
import { performance } from 'perf_hooks'
const start = performance.now();
doSomething(); // <---- The function you're measuring time for
const end = performance.now();
console.log("Call to doSomething took " + (end - start) + " milliseconds.")
@musab
musab / kube.md
Last active August 19, 2019 17:37
Kubernetes terminology

Kubernetes terminology:

  1. Pods
  • Group of containers, and is the smallest unit that Kubenetes adminsters. Pods have a single IP address that is applied to every container withiun the pod. ner.
  1. Deployments
  • Define the scale at which you want to run your application by letting you set the details of how you would like the pods replicated on your Kubenertes pods.
  1. Services
  • Kubernetes doesn’t treat its pods as unique, long-running instances; if a pod encounters an issue and dies, it’s Kubernetes’ job to replace it so that the application doesn’t experience any downtime.
@musab
musab / example.js
Created June 9, 2020 19:36
tsdoc example
export class Statistics {
/**
* Returns the average of two numbers.
*
* @remarks
* This method is part of the {@link core-library#Statistics | Statistics subsystem}.
*
* @param x - The first input number
* @param y - The second input number
* @returns The arithmetic mean of `x` and `y`
@musab
musab / msg.txt
Created January 18, 2021 19:52
Writing good commit messages
// https://lazau.com/articles/good_commit_messages.html
Short summary of 50 chars or less.
Detailed text which can span multiple paragraphs. Each paragraph
should be line wrapped at 72 chars.
Relevant Links:
- https://myco.atlassian.net/browse/TICKET-32138
@musab
musab / postgres-cheatsheet.md
Created February 16, 2021 18:16 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

TZ='UTC'
NODE_ENV=development
PORT=8000
API_TOKEN=c03ec4d8-3cbe-43ff-98f8-f010cb5cb45e
MIGRATION_DB_HOST=localhost
MIGRATION_DB_PORT=5432
MIGRATION_DB_name=noted
MIGRATION_DB_USER=postgres
MIGRATION_DB_PASS=B3Th3B3st
DATABASE_URL='postgres://postgres:B3Th3B3st@localhost/notes'
@musab
musab / docker.md
Created January 20, 2022 14:00
docker commands cheatsheet

Run a docker image

docker run nginx

Run a specific tag of a docker image

docker run redis:4.0

List all running containers

@musab
musab / interface_and_di.go
Last active March 25, 2022 17:23
Go Interfaces and Dependency Injection for Testing
// you can play with the code via https://go.dev/play/p/bVfCe51O0en
package main
import "fmt"
// src/add.go
type Adder interface {
add(int, int) int