Skip to content

Instantly share code, notes, and snippets.

@robertolos
robertolos / psportkill.sh
Last active April 30, 2022 08:22
Kills process running on port
# Add to .bashrc or .zshrc
psportkill() {
if [ $# -eq 0 ]
then
echo "Missing port number. Usage: psportkill 5000"
exit 1
fi
echo "Killing process on port $1"
lsof -i 4tcp:$1 -sTCP:LISTEN | awk '{if(NR>1)print $2}' | xargs kill
if [ $? -eq 0 ]
@robertolos
robertolos / moduleMock.ts
Last active December 19, 2022 23:15
Module mocking in ESM
// # https://jestjs.io/docs/ecmascript-modules#module-mocking-in-esm
// #### module.ts ####
import { getData } from "./submodule";
export const myModule = () => {
return getData();
};
// #### submodule.ts ####
@robertolos
robertolos / initTypescriptProject.sh
Created June 29, 2023 22:08
Initialise a new node project with typescript
# Initialise a new node project with typescript
# usage:
# > ./initTypescriptProject.sh my-app-name
PROJECT_NAME=$1
mkdir $PROJECT_NAME
cd $PROJECT_NAME
npm init -y
yarn add --dev typescript ts-node nodemon rimraf @types/node jest
@robertolos
robertolos / postgres-cheatsheet.md
Created November 10, 2023 16:49 — 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)
@robertolos
robertolos / gist:236c9edd603c716f35d9e4cfe2bb37fb
Created December 21, 2023 14:46
Headless setup raspberry using Raspberry PI Manager from Mac
1. Write Raspberry PI OS to an SD card using Raspberry PI Manager.
2. Create a file named user userconf (or userconf.txt) containing the following:
Code:
`pi:$6$c70VpvPsVNCG0YR5$l5vWWLsLko9Kj65gcQ8qvMkuOoRkEagI90qi3F/Y7rm8eNYZHW8CY6BOIKwMH7a3YYzZYL90zf304cAHLFaZE0`
3. Place userconf (or userconf.txt) plus an empty file named ssh (or ssh.txt) in the BOOT (FAT32) partition of the SD card.
4. Insert the SD card in the Raspberry Pi and it should boot with access to user 'pi' (password : raspberry) via SSH.
@robertolos
robertolos / docker-compose.yml
Created January 3, 2024 17:23
docker-compose mongodb
version: "3"
services:
db:
image: mongo
restart: always
ports:
- 27017:27017
environment: #env variables to pass into the container
MONGODB_DATABASE: nest-course