Skip to content

Instantly share code, notes, and snippets.

@ECHO OFF
REM -- Automates cygwin installation
SETLOCAL
REM -- Change to the directory of the executing batch file
CD %~dp0
REM -- Configure our paths
SET SITE=http://mirrors.kernel.org/sourceware/cygwin/
@tsangwpx
tsangwpx / README.md
Created January 30, 2018 17:11
Failed to run raid array

Situation

System failed to boot with messages:

  1. "Failed to run raid array"
  2. cache_check is missing/not found

uname -a output:
Linux hostname 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u1 (2017-06-18) x86_64 GNU/Linux

Reason

Some kernel modules and binary files were missing in the boot image. They are related to lvmcache if there are LVs backed by dm-cache.

@tsangwpx
tsangwpx / wsl-setup-openssh-server.sh
Created May 7, 2018 05:53
OpenSSH server on WSL
#!/bin/bash
# Reference: https://gist.github.com/dentechy/de2be62b55cfd234681921d5a8b6be11
# This script is used to automate the installation and configration of openssh-server on Windows Subsystem of Linux.
# The tested platform:
# Windows 10 version 1803
# Debian stretch on WSL
# Change the sshd port if needed
SSH_PORT=22
@tsangwpx
tsangwpx / wsl_cd.sh
Last active June 28, 2018 13:14
wsl_cd
function wsl_cd() {
# This function translate a windows path to unix path and change the current directory to the translated path
# This make working on WSL more convenient
local idx=0
local dir="$1"
local unix=""
# echo "$dir"
@tsangwpx
tsangwpx / mc.py
Last active September 17, 2018 17:49
MatchState
import re
class MatchStateMeta(type):
def __init__(cls, name, bases, ns, *, proxy_methods=(), proxy_properties=()):
super().__init__(name, bases, ns)
for name in proxy_methods:
ns[name].__qualname__ = '%s.%s' % (cls.__qualname__, ns[name].__name__)
@classmethod
@tsangwpx
tsangwpx / timeslot.py
Created January 10, 2019 08:36
Assigning items (students) randomly to bins (timeslots)
#!/usr/bin/python3
ids = """
11111111
22222222
33333333
44444444
55555555
66666666
77777777
@tsangwpx
tsangwpx / main.py
Created March 31, 2019 19:14
Logging with multiprocessing
"""
Logging with multiprocessing
LogRecord are sent back to the master process
License: MIT
Author: Aaron Tsang
"""
@tsangwpx
tsangwpx / python-import-error.md
Created April 2, 2019 05:32
CXXABI not found

Sometime Python environment is complicated. For example, python3 from Anaconda but package management with pipenv. Shared libraries were built with different configuration or technically RPATH in ELF.

This is an example:

import matplotlib.pyplot
import numba
ImportError                               Traceback (most recent call last)
@tsangwpx
tsangwpx / ghost-key-press-g.md
Last active September 19, 2019 20:56
ghost key press "g"

Situation

When I used remote desktop with earphones, there are ghost key press typing "g" periodically.

It turned out related to a process called RAVBg64.exe /SENDINPUT.

I am not sure what is happening. I was using Carbon X1C6 with software downloaded from Lenovo / Windows Update.

Update on 20/09/2019

The issue was fixed in Realtek Audio Rriver with the version 6.0.8777.1 [Link 3]

@tsangwpx
tsangwpx / boolean.md
Last active May 29, 2019 09:10
NumPy Boolean

See https://docs.python.org/3/library/operator.html for details

Negation (Logical)

not a True (bool) False (bool) True (bool_) False (bool_) 1 (uint8) 0 (uint8) 1.0 (float) 0.0 (float) 1.0 (float64) 0.0 (float64)
False (bool) True (bool) False (bool) True (bool) False (bool) True (bool) False (bool) True (bool) False (bool) True (bool)

Bitwise Inversion

~a True (bool) False (bool) True (bool_) False (bool_) 1 (uint8) 0 (uint8) 1.0 (float) 0.0 (float) 1.0 (float64) 0.0 (float64)
-2 (int) -1 (int) False (bool_) True (bool_) 254 (uint8) 255 (uint8)

Bitwise AND