Skip to content

Instantly share code, notes, and snippets.

View mengzhuo's full-sized avatar

Meng Zhuo mengzhuo

View GitHub Profile
@mengzhuo
mengzhuo / toggle-touchpad
Created October 30, 2013 05:38
Toggle TouchPad on Linux with synclient, works/Tested on Ubuntu
#!/bin/sh
synclient TouchpadOff=$((`synclient -l | grep TouchpadOff | awk '{print $3}'`==0))
@mengzhuo
mengzhuo / hash_djb2.py
Created March 9, 2015 07:40
DJB2 Hash in Python
#!/usr/bin/env python
# encoding: utf-8
def hash_djb2(s):
hash = 5381
for x in s:
hash = (( hash << 5) + hash) + ord(x)
return hash & 0xFFFFFFFF
@mengzhuo
mengzhuo / README.md
Last active July 16, 2022 01:55 — forked from djfdyuruiry/README.md
WSL 2 - Enabling systemd

Enable systemd in WSL 2

This guide will enable systemd to run as normal under WSL 2. This will enable services like microk8s, docker and many more to just work during a WSL session. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2.

  • To enable systemd under WSL we require a tool called systemd-genie

  • Copy the contents of install-sg.sh to a new file /tmp/install-sg.sh:

    cd /tmp
@mengzhuo
mengzhuo / gist:424ba2d79afa1bcb5bbb57255587db2c
Created July 12, 2022 11:02
EKS node group create failed
Jul 12 07:35:45 ip-10-0-27-129.us-west-2.compute.internal kubelet[20691]: I0712 07:35:45.353944 20691 aws.go:1264] Get AWS region from metadata client
Jul 12 07:35:45 ip-10-0-27-129.us-west-2.compute.internal kubelet[20691]: I0712 07:35:45.354071 20691 aws.go:1309] Zone not specified in configuration file; querying AWS metadata service
Jul 12 07:35:45 ip-10-0-27-129.us-west-2.compute.internal kubelet[20691]: I0712 07:35:45.356846 20691 aws.go:1349] Building AWS cloudprovider
Jul 12 07:35:45 ip-10-0-27-129.us-west-2.compute.internal kubelet[20691]: E0712 07:35:45.670856 20691 server.go:294] "Failed to run kubelet" err="failed to run Kubelet: could not init cloud provider \"aws\": error finding instance i-xxxxxxxxxxxxxx: \"error listing AWS instances: \\\"RequestError: send request failed\\\\ncaused by: Post \\\\\\\"https://ec2.us-west-2.amazonaws.com/\\\\\\\": dial tcp: lookup ec2.us-west-2.amazonaws.com on 10.0.0.2:53: no such host\\\"\""
Jul 12 07:35:45 ip-10-0-27-129.us-west-2.compute.internal syste
Install required packages
sudo pkg install opensbi u-boot-qemu-riscv64 qemu
Note: emulators/qemu-devel also works.
Download FreeBSD/RISC-V virtual machine image
fetch https://download.freebsd.org/ftp/snapshots/VM-IMAGES/14.0-CURRENT/riscv64/Latest/FreeBSD-14.0-CURRENT-riscv-riscv64.raw.xz
xz --decompress FreeBSD-14.0-CURRENT-riscv-riscv64.raw.xz
Optionally, extend the image using truncate(1). The root filesystem will grow to fill the free space upon first boot.
@mengzhuo
mengzhuo / checker.py
Created July 16, 2014 05:32
Python Port conflict checker
def check_port_conflict(port, show_logging=True):
"""Check whether Shadowsock bind port conflicted with services
registered in services database from Linux /etc/services
If conflicted, show logging warning and return tuple that conflicted
else, return None
:port: int bind port (TCP/UDP)
:returns: None/tuple that conflicted
"""
<hudson.util.DescribableList>
<hudson.node__monitors.ArchitectureMonitor>
false
</hudson.node__monitors.ArchitectureMonitor>
<hudson.node__monitors.ClockMonitor>
false
</hudson.node__monitors.ClockMonitor>
<hudson.node__monitors.DiskSpaceMonitor>
false
1GB
@mengzhuo
mengzhuo / singleton.py
Created June 8, 2015 06:50
Python 单例(singleton) 方式比拼
#!/usr/bin/env python
# encoding: utf-8
class Singleton(type):
def __init__(cls, name, bases, dict):
super(Singleton, cls).__init__(name, bases, dict)
cls.instance = None
def __call__(cls,*args,**kw):
if cls.instance is None:
@mengzhuo
mengzhuo / conf.py
Created September 2, 2014 13:47
configure module (reloadable)
#!/usr/bin/env python
# encoding: utf-8
import os
from ConfigParser import SafeConfigParser
PREFIX = 'ZTY'
setting = SafeConfigParser()
setting.read(['/etc/zty-site.conf',
'~/zty-site.conf'])
#!/usr/bin/env python
# encoding: utf-8
import gc
from pprint import pprint
import weakref
gc.set_debug(gc.DEBUG_LEAK)
class ExpensiveObject(object):