Skip to content

Instantly share code, notes, and snippets.

View changx03's full-sized avatar
🏠
Working from home

Luke Chang changx03

🏠
Working from home
  • The University of Auckland
  • Auckland
  • 19:32 (UTC +12:00)
View GitHub Profile
@changx03
changx03 / latex.gitignore
Created October 5, 2023 10:51
git ignore for LaTex
# Autogenerated LaTeX-related files
*.aux
*.toc
*.log
*.nav
*.vrb
*.snm
*.tuc
# (La)TeX:
# Lists:

Structure of most recent surveys on adversarial attacks and defenses

  • Only included surveys after 2020;
  • Surveys with low H-Index and fewer than 20 pages are excluded;

IEEE Communications Surveys & Tutorials

  • Double column
  • H-Index: 240
  • Country: US
@changx03
changx03 / kge_fb15k_237.py
Created August 21, 2023 01:17
PyTorch Geometric example for FB15K
import argparse
import os.path as osp
import torch
import torch.optim as optim
from torch_geometric.datasets import FB15k_237
from torch_geometric.nn import ComplEx, DistMult, RotatE, TransE
model_map = {
@changx03
changx03 / server_name.sh
Last active July 23, 2023 22:53
Access to CSML cluster
# Server 1:
ssh <UPI>@foscsmlprd01.its.auckland.ac.nz
# Server 2:
ssh <UPI>@foscsmlprd02.its.auckland.ac.nz
# Pssword: <UoA_PASSWORD>:<6_DIGITS_2FACTOR> eg, Pass1234:123456
# For Linux user, using GUI to tansfer files:
# Open `Files` browser, press ctrl+L
@changx03
changx03 / run_gpu_python.sh
Last active July 21, 2023 14:14
Instruction for executing Python code with a specific GPU and save console outputs and error to a log file
# Use `nvtop` or `nvidia-smi` to check avalible GPUs. Only allows the Python code to access a specific GPU:
# CUDA_VISIBLE_DEVICES=<GPU_INDEX>
# Redirect standard output to `main.log` and then redirect standard error to standard output:
# > main.log 2>&1
# Allows code to run in the bakcgounrd:
# &
CUDA_VISIBLE_DEVICES=0 python main.py > main.log 2>&1 &
@changx03
changx03 / torch_gpu_test.py
Created July 21, 2023 13:51
Testing for GPU availability
import torch
device = torch.device('cuda:0') if torch.cuda.is_available() else 'cpu'
print(f'Using: {device}')
print('GPU Memory Usage:')
print('Allocated:', round(torch.cuda.memory_allocated(0) / 1024**3, 1), 'GB')
print('Cached: ', round(torch.cuda.memory_reserved(0) / 1024**3, 1), 'GB')
# Run a trivial task
@changx03
changx03 / run_jupyer.sh
Last active July 23, 2023 22:59
Running Jupyter Lab on a remote server
# Instructions for connecting Jupyter Lab with the remove server
# SSH with port forward:
# Replace <PORT> with the port number you selected in the above step
# Replace <REMOTE_USER> with the remote server username
# Replace <REMOTE_HOST> with your remote server address
ssh -L 8080:localhost:<PORT> <REMOTE_USER>@<REMOTE_HOST>
####################################################################
# Replace <PORT> with your selected port number, e.g., 8080
@changx03
changx03 / change_cache_dir.sh
Last active September 26, 2023 00:24
Change Ubuntu cache directory on remove server
# These parameters are only apply in your current terminal.
# Run them again once you start a new terminal!
export XDG_CACHE_HOME=/data/<username>/.cache
export PIP_CACHE_DIR=/data/<username>/.cache
@changx03
changx03 / keychron_fn.sh
Created January 8, 2023 16:15
Set Keychron Linux Function Keys
#!/bin/bash
echo 0 | sudo tee /sys/module/hid_apple/parameters/fnmode
@changx03
changx03 / array_example.sh
Created July 14, 2022 02:24
Access an element from an array using index in bash
#!/bin/bash
# To access banana
DATA=("apple" "banana" "cherry")
IDX=1
echo ${DATA[$IDX]}