Skip to content

Instantly share code, notes, and snippets.

View jasdeepkhalsa's full-sized avatar

Jasdeep Khalsa jasdeepkhalsa

View GitHub Profile
@jasdeepkhalsa
jasdeepkhalsa / promiseAny.ts
Created January 15, 2021 13:38
Promise Any with TypeScript Generic Return Type
type PromiseAny<T = any> = Promise<T>;
interface IClass {
methodA: (
paramA?: string,
) => PromiseAny | void;
}
@jasdeepkhalsa
jasdeepkhalsa / Dockerfile
Last active November 28, 2020 16:30
Create PHAR
# Disable PHAR readonly for producing PHAR archives
RUN echo 'phar.readonly=0' >> /usr/local/etc/php/conf.d/docker-php-phar-readonly.ini
@jasdeepkhalsa
jasdeepkhalsa / docker-compose.yml
Created August 18, 2020 00:07
Wordpress in Docker & Docker Compose
version: '3.3'
services:
wordpress:
depends_on:
- db
- phpmyadmin
image: wordpress:latest
ports:
- 8000:80
@jasdeepkhalsa
jasdeepkhalsa / postgres.md
Last active August 17, 2020 23:59
Postgres Commands

Install

apt-get install postgresql-12

Login to Postgres as the default user

sudo -u postgres psql
@jasdeepkhalsa
jasdeepkhalsa / pipe.js
Last active March 12, 2021 15:42 — forked from ericelliott/pipe.js
Pipe
// Pipe takes the first argument and pipes it though each of the functions that you provide as the remaining arguments,
// and can be implemented as follows:
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);
const fn1 = s => s.toLowerCase();
const fn2 = s => s.split('').reverse().join('');
const fn3 = s => s + '!'
const newFunc = pipe(fn1, fn2, fn3);
const result = newFunc('Time'); // emit!
@jasdeepkhalsa
jasdeepkhalsa / compose.js
Created July 24, 2020 16:16 — forked from ericelliott/compose.js
Compose implementation
const compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x);
@jasdeepkhalsa
jasdeepkhalsa / rsyncAB.sh
Last active April 3, 2020 08:32
rsync A->B - Transfer a directory from a source server (A) into a directory on a target server (B) via SSH & rsync
#!/usr/bin/env bash
# This script will transfer a directory from a source server (A)
# into a directory on a target server (B)
# Pre-requisites: The script must be run by a user who has SSH / passwordless access to both server A & B
# From StackExchange.com (https://unix.stackexchange.com/a/317815) - Authored by David I. (https://unix.stackexchange.com/users/71948/david-i) adapated from an answer by roaima (https://unix.stackexchange.com/users/100397/roaima) - Under the license: cc by-sa 4.0 with attribution required (https://creativecommons.org/licenses/by-sa/4.0/)
# Slight modifications may have been made to the original script, which are in no way endorsed by the original authors of this script
# Specific alterations include:
# - the rsync parameters checking files by checksum instead of date/time/size
@jasdeepkhalsa
jasdeepkhalsa / mysqlAB.sh
Last active April 3, 2020 08:33
MySQL A->B - Pipe a MySQL database from a source server (A) into a target MySQL database on another server (B)
#!/usr/bin/env bash
# This script will pipe a MySQL database from a source server (A)
# into a target MySQL database on another server (B)
# From StackExchange.com (https://dba.stackexchange.com/a/180) - Authored by David Hall - Under the license: cc by-sa 4.0 with attribution required (https://creativecommons.org/licenses/by-sa/4.0/)
# Slight modifications may have been made to the original script, which are in no way endorsed by the original author(s) of this script
# Specific alterations include:
# - Adding both a source & target hostname & database
# - Updating the command-line options in line with the latest versions of the `mysqldump` & `mysql` command-line tools
@jasdeepkhalsa
jasdeepkhalsa / script.sh
Last active April 9, 2020 08:46
Automatically determining values in a Bash script
#!/usr/bin/env bash
APP=a
if [[ "$1" ]]; then
APP="$1"
fi
# This is automatically determined by the $APP variable
CONFIG="app-default.config"
case "$APP" in
@jasdeepkhalsa
jasdeepkhalsa / build-and-run-docker-image.md
Last active March 31, 2020 14:15
Build and run a Docker image

Build Image

cd into the project root and then...

docker build --tag "app:latest" --file "app.dockerfile" .

Run Image