Skip to content

Instantly share code, notes, and snippets.

View TheAmazingPT's full-sized avatar

The Amazing PT TheAmazingPT

View GitHub Profile
@TheAmazingPT
TheAmazingPT / example.ts
Created July 9, 2019 09:40
How do we want to define array types? Generics vs. array-literal…
type Example = 'string';
type Examples = Array<Example>;
// Option #1
const examples: Array<Example> = ['example 1', 'example 2', 'example 3'];
// Option #2
const examples: Example[] = ['example 1', 'example 2', 'example 3'];
// Option #3
@TheAmazingPT
TheAmazingPT / examples.js
Created July 4, 2019 08:54
Do you prefer import style #1 or #2?
// Import-Style #1
import fs from 'fs';
import fetch from 'node-fetch';
import User from '../shared/types/user';
import Report from '../shared/types/report';
import getUserById from '../shared/libs/get-user-by-id';
import calculateDates from '../shared/libs/dates/calculate-dates';
import validateUserDates from '../shared/libs/dates/validate-user-dates';
import userPreferences from './constants/user-preferences.json';
import getHeaderDates from './libs/get-header-dates';
@TheAmazingPT
TheAmazingPT / deps-finder.bash
Created March 22, 2019 11:08
A little handy tool to find used dependencies in JS scripts
# You can use these two lines to identify
# required dependencies in your code,
# which need to be installed via NPM/yarn.
# Change to `grep -rnoE …` if you want to see
# the filepath and line number of the occurence.
grep -rhoE "from '\w+.*'|require\('\w+.*'\)" \
src/scripts/ | sort | uniq
@TheAmazingPT
TheAmazingPT / newpw.sh
Last active October 10, 2018 08:04
A little handy tool to generate new secure passwords on most Linux machines.
#!/usr/bin/env bash
# This script helps you to generate a new secure password.
# If you don't specify a number, the default length
# will be 32 characters.
# The following would give you a new password with 10 characters.
# newpw 10
# NOTE:
@TheAmazingPT
TheAmazingPT / portfinder.sh
Created July 30, 2018 14:20
How to find the corresponding directory of a script, which runs a process on a specific port.
#!/usr/bin/env bash
# Run this script, after you gave it a name like portfinder, added
# it to your path runtime and gave it an execution flag:
# portfinder 3000
# Required system tools:
# bash, lsof and pwdx
if [[ -z $1 ]]
@TheAmazingPT
TheAmazingPT / default-browser-setting-tutorial.sh
Created July 18, 2018 07:53
A few people told me, that my pr-opener script in a previous tweet was using the wrong browser. This is likely a wrong setting in xdg!
# Find out your current setting
xdg-settings get default-web-browser
# Find all available browsers on your system
grep -rl WebBrowser /usr/share/applications
# Example output of the command above:
# /usr/share/applications/google-chrome.desktop
# /usr/share/applications/firefox.desktop
# /usr/share/applications/webbrowser-app.desktop
@TheAmazingPT
TheAmazingPT / public-ip.sh
Created July 4, 2018 13:23
A handy tool to find out your current public IP address from the command line.
# A handy tool to find out your current
# public IP address from the command line.
function public-ip {
IP=`curl -s icanhazip.com`
echo "Your public IP address is: ${IP}"
}
# Add it to your bash runtime like for example
# putting it into your .bashrc!
@TheAmazingPT
TheAmazingPT / wttr.sh
Created July 3, 2018 15:28
A handy tool for showing the weather in your command line.
# Little tool for showing the current weather!
# Change DEFAULT_CITY to your favourite city.
# wttr // Resolves to wttr Hamburg
# wttr Sidney
# wttr "New York"
function wttr {
DEFAULT_CITY="Hamburg"
CITY="${1:-$DEFAULT_CITY}"
@TheAmazingPT
TheAmazingPT / open-pr.sh
Last active July 2, 2018 14:03
A handy tool for getting to a GitHub pull request page from your command line.
# If you call this function inside a git repository,
# this will open a compare page on Github.
function open-pr {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
REPO=`git remote -v | grep fetch | awk '{print $2}'`
LINK=`echo $REPO | sed 's!git@!https://!' | sed 's!com:!com/!' | head -n1 | sed 's!\b\.git\b!!'`
# For Linux users: change `open` to `xdg-open`
open $LINK/compare/$BRANCH?expand=1
@TheAmazingPT
TheAmazingPT / stitcher.sh
Last active October 6, 2017 14:15
A bash script for stitching jpg's together
# Tested on Ubuntu 16.04 and Bash 4.3.48
#
# Usage: ./stitcher.sh $PWD 5
#
# The stitcher shell script should be in the same directory, where you also find the images directory.
# Inside the images directory, I am assuming to find all the images for stitching.
# The first argument gives me an absolute path to the working directory.
# The second argument says, how many rows shall be rendered.
# In a directory with 20 images, this example would render 5 rows with 4 images in each row.
# The output can be found in output.jpg, in the same directory where this script is located.