Skip to content

Instantly share code, notes, and snippets.

View guoqiao's full-sized avatar

Guo Qiao (Joe) guoqiao

  • Canonical
  • Auckland, New Zealand
  • X @guoqiao
View GitHub Profile
@guoqiao
guoqiao / CUDA-WSL.md
Last active May 3, 2024 04:43
Setup PyTorch with CUDA in WSL-Ubuntu on Windows 11

Setup PyTorch with CUDA in WSL-Ubuntu on Windows 11

On Windows 11:

  1. Download and install Nvidia GPU Driver for Windows: https://www.nvidia.com/download/index.aspx
  2. Download and install CUDA Toolkit for Windows: https://developer.nvidia.com/cuda-downloads

NOTE: Nvidia Official doc says, the GPU Driver includes "CUDA Support", which is very confusing. It doesn't mean CUDA is included in Driver. What included is only some support files, not CUDA itself. You still need to install CUDA separately.

@guoqiao
guoqiao / Tempermonkey_CSS.js
Created February 28, 2024 22:24
customize css with Tempermonkey
// ==UserScript==
// @name LinkedIn Improve
// @namespace http://tampermonkey.net/
// @version 2024-02-28
// @description try to take over the world!
// @author You
// @match https://www.linkedin.com/messaging/thread/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=linkedin.com
// @grant GM_addStyle
// ==/UserScript==
@guoqiao
guoqiao / python-path.md
Created January 20, 2023 10:56
python path ops
from pathlib import Path

FILE = Path(__file__).resolve()
NAME = FILE.stem
HERE = FILE.parent


@guoqiao
guoqiao / PostgreSQL.md
Created December 28, 2022 09:54
PostgreSQL cheatsheet

create db and user:

app=$1

dbuser=$app
dbname=$app

sudo su --login postgres << EOF

createuser --echo ${dbuser};
@guoqiao
guoqiao / Makefile.md
Last active October 27, 2022 21:58
Makefile cheatsheet example

include .env and use envvar:

in your .env:

foo=bar

in your Makefile:

include .env
@guoqiao
guoqiao / ffmpeg.md
Last active December 8, 2022 23:02
ffmpeg cheatsheet

usage syntax:

ffmpeg input(s) [codec options] output(s)

convert video format:

ffmpg -i input.mov -c copy output.mp4
@guoqiao
guoqiao / linux-shared-memory-shm-tmpfs.md
Last active October 18, 2022 21:14
Shared Memory/shm/tmpfs in Linux, Docker and Kubernetes

Linux

  • On Linux, tmpfs == shm == shared memory.
  • you can mount tmpfs to a dir, and use that dir as normal dir but super fast.
  • Default path is at /dev/shm/.

when you create a file there, it actually lives in memory. Thus, it will be super fast to read/write, and applications/processes can use it to communicate.

By default, the size limit of /dev/shm is half of your physical memory. E.g.: my linux PC has 32G mem:

@guoqiao
guoqiao / ubuntu-linux-mount-volume-cli.md
Last active September 2, 2022 06:13
mount AWS EC2 instance storage volume in cli on ubuntu/linux server

on AWS, you may see some instance types have instance storage attr with it. E.g.:

g4dn.xlarge	1	4	16	1 x 125 NVMe SSD --> Instance Storage in GB

This means, when you boot a instance with this type, you will have 2 volumes attached:

  • boot volume, default 8G, system installed on it
  • instance storage volume, 125G, or 116.4Gi, spare, not in use by default.
@guoqiao
guoqiao / s3_public_bucket.tf
Last active July 31, 2022 22:35
Use Terraform to create public AWS S3 bucket via policy and disable ACL
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "bucket" {
# change this to your own bucket name
bucket = "my-test-bucket"
# allow to destroy bucket even when not empty
force_destroy = true
}
@guoqiao
guoqiao / test_async_loop.yml
Created January 23, 2019 00:01
Ansible task loop in parallel with async mode
#!/usr/bin/env ansible-playbook
---
- hosts: localhost
gather_facts: no
tasks:
- name: sleep 10s
command: "sleep 10"
loop: "{{range(3)|list}}"
async: 11
poll: 0