Skip to content

Instantly share code, notes, and snippets.

@lcenchew
Last active September 12, 2023 09:54
Show Gist options
  • Save lcenchew/bed768aaece10dc4657891608ff8fb85 to your computer and use it in GitHub Desktop.
Save lcenchew/bed768aaece10dc4657891608ff8fb85 to your computer and use it in GitHub Desktop.
00 Notes - a collection of various notes on computer stuffs #notes

Database

MS SQL Server

some basic stuffs

SELECT name FROM sys.databases

Install SQL Server (mssql) extension
use vs code intellisense by changing to SQL language mode and typing sql to list commands

T-SQL reference

MySQL

SQLite

create a database sqlite3 db_name.db

In sqlite> prompt ` .database

create table foo( id int not null, name varchar(255), bar int, primary key (id) );

.quit `

Docker Notes

macOS

Installing

brew cask install docker

Access files

On macOS, Docker is running in a hypervisor (VM, similar Virtualbox previously). Thus, files can be in one of 3 layers - local | VM | container

Container can mount folder from local, VM or from Volume (think of it like a container disk)

Files sharing: local - VM : Docker Desktop > Preferences > Resources > File Sharing
Local folders under /Users, /Volume, /private, /tmp can be mounted into container

Other folders not from the above shared folders are from inside the VM

bind mount folder into container using -v or --mount

mount Volume

Getting path and accessing persistent volumes volume mount on macOS

image

Container images

Where are the images keep? Manage disk usage.

Preferences > Resources > Advanced ~/Library/Containers/com.docker.docker/Data/vms/0/data

docker image ls
docker container ls -a
docker system df -v
docker system prune

phpmyadmin

docker pull phpmyadmin/phpmyadmin

docker run --name myadmin -p 8080:80 -d -e PMA_HOST=dbhost  phpmyadmin

Node.js

macOS

brew install node
brew install nvm
mkdir ~/.nvm

zsh add to ~/.zshrc

Recommended by Homebrew nvm install

export NVM_DIR="$HOME/.nvm"
  [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

npm init
npm install

package.json

Security

keytool

Generate self-signed key and cert

openssl req -x509 -newkey rsa:4096 -keyout cakey.pem -out cacert.pem -days 900

keytool -printcert -file cacert.pem
openssl x509 -in cacert.pem -text -noout

openssl General

view files

openssl rsa -noout -text -in key.pem
openssl req -noout -text -in csr.pem
openssl x509 -noout -text -in cert.pem
openssl pkcs12 -info -in file.p12

Self-signed CA

This is a good reference: https://jamielinux.com/docs/openssl-certificate-authority/index.html

openssl genrsa -out rootca.key.pem 4096

openssl req -new -sha256 -x509 -days 3650 -nodes \
  -key rootca.key.pem \
  -subj "/C=SG/ST=Singapore/L=SG/O=Company/OU=Department/CN=Root CA" \
  -out rootca.cert.pem

verify

openssl x509 -noout -text -in rootca.cert.pem

Sub CA Cert

key

openssl genrsa -out subca1.key.pem 2048

CSR

openssl req -new -sha256 \
   -key subca1.key.pem \
   -subj "/C=SG/ST=Singapore/L=SG/O=Company/OU=Department/CN=Sub CA" \
   -out subca1.csr.pem

sign CSR with root key+cert, produce cert

openssl x509 -req -days 730 -sha256 \
   -in subca1.csr.pem \
   -CAkey rootca.key.pem \
   -CA rootca.cert.pem \
   -CAcreateserial \
   -out subca1.cert.pem

verify

openssl x509 -noout -text -in subca1.cert.pem
openssl verify -CAfile rootca.cert.pem subca1.cert.pem

cert chain

cat subca1.cert.pem rootca.cert.pem > ca-chain.cert.pem

Server Cert

key

openssl genrsa -out server1.key.pem 2048

CSR

openssl req -new -sha256 \
   -key server1.key.pem \
   -subj "/C=SG/ST=Singapore/L=SG/O=Company/OU=Department/CN=server1.example.com" \
   -out server1.csr.pem

sign CSR with root key+cert, produce cert

openssl x509 -req -days 730 -sha256 \
   -in server1.csr.pem \
   -CAkey subca1.key.pem \
   -CA subca1.cert.pem \
   -CAcreateserial \
   -out server1.cert.pem

Verify

openssl x509 -noout -text -in server1.cert.pem
verify -CAfile ca-chain.cert.pem server1.cert.pem

Client Cert

(At server side) Create a client keystore with private key and certificate

openssl genrsa -out client.key 4096

openssl req -x509 -new -nodes -key client.key \ 
-subj "/C=SG/ST=Singapore/L=Singapore/O=Company/OU=Department/CN=Root CA" \
-sha256 -days 3650 -out client.crt

or

keytool -genkey -keyalg RSA -alias client -keystore client.keystore

Create a CSR

openssl req -new -sha256 -key 

or

keytool -certreq -alias client -keystore client.keystore -file client_certrequest.csr

Sign the request (with CA key+cert) and create client cert

openssl x509 -req -days 365 -sha512 -in client_certrequest.csr -CA cacert.pem -CAkey cakey.pem -CAcreateserial -out client_cert.pem

(At client side) Import the client certificate

keytool -import -trustcacerts -alias client -keystore ./<clientcerts>.keystore -file client_cert.pem

Might be interesting

Network

nmap

nmap -v -sn 192.168.0.0/24

Shells

Notes on various shells.

zsh

Install ohmyzsh https://ohmyz.sh/

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  • Configuration
  • Plugins
  • Themes

bash

Customization

Fonts https://github.com/ryanoasis/nerd-fonts

pip3 install powerline-status

brew tap homebrew/cask-fonts
brew cask install font-hack-nerd-font

In vscode, settings.json

    "terminal.integrated.fontFamily": "'Hack Nerd Font'",
    "terminal.integrated.shell.osx": "/bin/zsh",

tmux

ctrl-b % split vertical ctrl-b " split horizontal

⌘↑ to scroll up

trigger copy mode bybind -n M-Up copy-mode

Backup Tools

  • restic - cross platform
  • BorgBackup - encrypted, deduplicating backup, limited Windows support

PDF Tools

  • Tabula - extract data from PDF tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment