Skip to content

Instantly share code, notes, and snippets.

View huwan's full-sized avatar

Hu Wan huwan

  • City University of Hong Kong
  • 08:20 (UTC +08:00)
View GitHub Profile
@huwan
huwan / new empty git branch.md
Created February 27, 2024 06:06 — forked from ozh/new empty git branch.md
Create a new empty branch in Git
$ git checkout --orphan NEWBRANCH
$ git rm -rf .

--orphan creates a new branch, but it starts without any commit. After running the above command you are on a new branch "NEWBRANCH", and the first commit you create from this state will start a new history without any ancestry.

You can then start adding files and commit them and they will live in their own branch. If you take a look at the log, you will see that it is isolated from the original log.

@huwan
huwan / fly.toml
Created April 15, 2023 03:34 — forked from frostming/fly.toml
A Fly.io config file for OpenCat™ for Team that can be deployed directly
# fly.toml file generated for still-snowflake-6351 on 2023-03-30T09:53:40+08:00
kill_signal = "SIGINT"
kill_timeout = 5
primary_region = "sin"
processes = []
[build]
image = "bayedev/opencatd"
TARGET ?= a.out
SRC_DIRS ?= .
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c')
OBJS := $(addsuffix .o,$(basename $(SRCS)))
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d -not -path '*/.*')
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
@huwan
huwan / cs_network_portal.sh
Last active March 29, 2022 15:25
Log in CityU CS Network Portal
#!/bin/bash
# Log in CityU CS Network Captive Portal
#
# Copyright (c) 2017-2022, WAN Hu <hu.wan@my.cityu.edu.hk>
#
# Enter your CityU EID (without "-c") and PASSWORD
EID=foo
PASSWORD=bar
# from colorprint import succ, fail, info
from termcolor import colored, cprint
DEBUG = True
def succ(string):
if DEBUG:
cprint(string, 'green')
else:
print(string)
@huwan
huwan / install-gpu.sh
Created September 14, 2019 02:25
Install NVIDIA driver and CUDA toolkit (Ubuntu 18.04 + CUDA 10.0)
#! /bin/bash
# from https://www.tensorflow.org/install/gpu
# Add NVIDIA package repositories
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo apt-get update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
@huwan
huwan / thesis.sublime-project
Last active May 13, 2019 07:38
Sublime Text 3 project definition for LaTeX project
{
"folders":[
{
"path":".",
"name":"thesis",
"file_exclude_patterns":[
"*.blg",
"*.bbl",
"*.aux",
"*.log",
@huwan
huwan / .bashrc
Created April 14, 2019 13:06
BASH configuration
# https://unix.stackexchange.com/a/368927
prompt_command() {
# initialize the timestamp, if it isn't already
_bashrc_timestamp=${_bashrc_timestamp:-$(stat -c %Y "$HOME/.bashrc")}
# if it's been modified, test and load it
if [[ $(stat -c %Y "$HOME/.bashrc") -gt $_bashrc_timestamp ]]
then
# only load it if `-n` succeeds ...
if $BASH -n "$HOME/.bashrc" >& /dev/null
then
@huwan
huwan / tmpname.h
Created April 14, 2019 08:12
tmpname
#ifndef TMP_NAME_H
#define TMP_NAME_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <sys/time.h>
#include <string.h>
@huwan
huwan / benchmark_time.c
Last active May 14, 2020 02:50
Calculates average time required to get the current time from the system in nanoseconds (from pmem/pmdk)
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define NSECPSEC 1000000000
/*
* benchmark_time.c -- benchmark_time module definitions