Skip to content

Instantly share code, notes, and snippets.

View james-ni's full-sized avatar

James Ni james-ni

  • Melbourne, Australia
View GitHub Profile
@james-ni
james-ni / ec2bootstrap.sh
Last active January 2, 2020 11:14
EC2 Bootstrap script
#!/bin/bash
yum update -y
yum install httpd -y
service httpd start
chkconfig httpd on
cd /var/www/html
echo "<html><h1>Hello! Welcome To My Webpage @ $HOSTNAME</h1></html>" > index.html
@james-ni
james-ni / ssh_jumpbox.sh
Created December 14, 2019 11:51
Connect to a private server through SSH jump box
ssh -fN -L 8888:10.1.2.151:80 ec2-user@52.62.11.59 -i PRIVATEKEY.pem
curl -i localhost:8888
@james-ni
james-ni / DecryptDbeaver.java
Created April 14, 2020 23:08
retrieve password stored in DBeaver
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.*;
@james-ni
james-ni / git-alias.sh
Created May 15, 2020 12:54 — forked from Bojole/git-alias.sh
Git Aliases
git config --global alias.a "! git add . && git status"
git config --global alias.aa "! git add . && git add -u . && git status"
git config --global alias.ac "! git add . && git commit"
git config --global alias.acm "! git add . && git commit -m"
git config --global alias.alias "! git config --list | grep 'alias\.' | sed 's/alias\.\([^=]*\)=\(.*\)/\1\ => \2/' | sort"
git config --global alias.au "! git add -u . && git status"
git config --global alias.c "commit"
git config --global alias.ca "commit --amend"
git config --global alias.cm "commit -m"
git config --global alias.co checkout
function pyvenv_enable () {
ENV_NAME=$(basename $PWD)
VENV_DIR="${HOME}/.venv/${ENV_NAME}"
if [ ! -d "${VENV_DIR}" ]; then
python3 -m venv ${VENV_DIR}
echo "Created venv: ${VENV_DIR}"
source ${VENV_DIR}/bin/activate
pip3 install --upgrade pip setuptools-scm
else
source ${VENV_DIR}/bin/activate
@james-ni
james-ni / admin.py
Created March 16, 2021 10:06 — forked from herbps10/admin.py
Setting up SQLAlchemy with Application Factory pattern and Blueprints
from flask import current_app, Blueprint, render_template
from database import db_session
from model import Product
admin = Blueprint('admin', __name__, url_prefix='/admin')
@admin.route('/')
def index():
product = db_session.query(Product).first()
@james-ni
james-ni / .ideavimrc
Created May 27, 2021 04:40
Setup Vim Easy motion
g:EasyMotion_override_acejump = 0
map <space> <Plug>(easymotion-bd-w)
set easymotion
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.implicitly_wait(10) # not a good practice; just for demo purpose
driver.get("http://localhost:3000")
# Landing page
login_button = driver.find_element(By.NAME, "login")
login_button.click()
const { test, expect } = require('@playwright/test');
test('basic test', async ({ page }) => {
await page.goto('http://localhost:3000');
await page.click('[name=login]');
await page.fill('[name=email]', '<EMAIL>');
await page.fill('[name=password]', '<PASSWORD>');
await page.click('[name=submit]');
@james-ni
james-ni / minikube_on_lan.md
Last active November 12, 2022 12:26
Kubernetes cluster on LAN

start minikube using hyperv driver

  • assign 4 cpus
  • enable ingress
minikube start --profile hello-world --cpus 4 --vm-driver hyperv --hyperv-virtual-switch "thinkpad-k8s" --addons=ingress --embed-certs

to enable metric server