Skip to content

Instantly share code, notes, and snippets.

@liyu1981
liyu1981 / cb_provision_web.py
Created November 7, 2023 03:08
provision_web
import datetime
import pathlib
import sys
import threading
import re
import subprocess
from pathlib import Path
from zipfile import ZipFile, ZIP_DEFLATED
from bottle import request, route, run, static_file
@liyu1981
liyu1981 / make_animate_train.py
Last active April 12, 2023 08:54
A simple function to animate the training process in google colab with PyTorch
# Usage:
# just copy this function into your google colab notebook, then use it
# a working example can be seen in this demo notebook:
# https://colab.research.google.com/drive/19Ni0EfOExQmTcrFZh3Z6DxsOM25KULqN?usp=sharing
import matplotlib.pyplot as plt
from matplotlib import animation, rc
def make_animate_train(train_step_fn, animate_setup_fn):
"""
@liyu1981
liyu1981 / consoleColors.js
Created October 1, 2022 06:05 — forked from abritinthebay/consoleColors.js
The various escape codes you can use to color output to StdOut from Node JS
// Colors reference
// You can use the following as so:
// console.log(colorCode, data);
// console.log(`${colorCode}some colorful text string${resetCode} rest of string in normal color`);
//
// ... and so on.
export const reset = "\x1b[0m"
export const bright = "\x1b[1m"
export const dim = "\x1b[2m"
@liyu1981
liyu1981 / .zshrc
Last active May 1, 2020 01:36
My Zsh backup & install
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel9k/powerlevel9k"
. ~/.zshtheme
ENABLE_CORRECTION="true"
COMPLETION_WAITING_DOTS="true"
plugins=(
'use strict';
class Abstract {
// A static abstract method.
static foo() {
if (this === Abstract) {
// Error Type 2. Abstract methods can not be called directly.
throw new TypeError("Can not call static abstract method foo.");
} else if (this.foo === Abstract.foo) {
// Error Type 3. The child has not implemented this method.
throw new TypeError("Please implement static abstract method foo.");
@liyu1981
liyu1981 / workchat-update.sh
Created March 12, 2019 00:11
update script for nativefier-workchat
#!/bin/bash
echo "create new version of nativefier-wrokchat"
nativefier -i ./workplace.png https://fb.workplace.com -n nativefier-workchat
if [ -d "/Applications/nativefier-workchat.app" ]; then
echo "backup..."
mv /Applications/nativefier-workchat.app ~/Desktop/nativefier-workchat-backup.app
echo "done => ~/Desktop"
fi
@liyu1981
liyu1981 / ttfb.sh
Created July 8, 2018 13:57 — forked from sandeepraju/ttfb.sh
curl command to check the time to first byte
#!/bin/bash
# file: ttfb.sh
# curl command to check the time to first byte
# ** usage **
# 1. ./ttfb.sh "https://google.com"
# 2. seq 10 | xargs -Iz ./ttfb.sh "https://google.com"
curl -o /dev/null \
-H 'Cache-Control: no-cache' \
-s \
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@liyu1981
liyu1981 / fix_virtualenv
Created October 18, 2017 05:13 — forked from tevino/fix_virtualenv
Fix python virtualenv after python update
#!/usr/bin/env bash
ENV_PATH="$(dirname "$(dirname "$(which pip)")")"
SYSTEM_VIRTUALENV="$(which -a virtualenv|tail -1)"
echo "Ensure the root of current virtualenv:"
echo " $ENV_PATH"
read -p "‼️ Say no if you are not sure (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "♻️ Removing old symbolic links......"
@liyu1981
liyu1981 / scm-prompt.sh
Created August 9, 2017 01:12
a script to show scm-prompt in bash, support both git and hg
# Determines the "branch" of the current repo and emits it.
# For use in generating the prompt.
# This is portable to both zsh and bash and works in both
# git and mercurial repos and aims to avoid invoking the
# command line utilities for speed of prompt updates
# To use from zsh:
# NOTE! the single quotes are important; if you use double quotes
# then the prompt won't change when you chdir or checkout different
# branches!