Skip to content

Instantly share code, notes, and snippets.

View cloudhan's full-sized avatar

cloudhan

  • 04:53 (UTC +08:00)
View GitHub Profile
@cloudhan
cloudhan / profile.ps1
Last active May 1, 2023 16:15
PowerShell Profile Script.
# Set-ExecutionPolicy Bypass -Scope CurrentUser # to further speedup powershell startup
$PROFILE_DIR = Split-Path -Path $PROFILE.CurrentUserAllHosts -Parent
$OLD = $PROFILE
$PROFILE = Join-Path $PROFILE_DIR "profile.ps1"
$PROFILE | Add-Member -NotePropertyName AllUsersAllHosts -NotePropertyValue $OLD.AllUsersAllHosts
$PROFILE | Add-Member -NotePropertyName AllUsersCurrentHost -NotePropertyValue $OLD.AllUsersCurrentHost
$PROFILE | Add-Member -NotePropertyName CurrentUserAllHosts -NotePropertyValue $PROFILE.ToString()
$PROFILE | Add-Member -NotePropertyName CurrentUserCurrentHost -NotePropertyValue $PROFILE.ToString()
Clear-Variable OLD
@cloudhan
cloudhan / settings.json
Last active November 19, 2022 04:17
Microsoft Terminal configuration
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions": [],
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"initialCols": 140,
"initialRows": 30,
"profiles":
{
"defaults":
@cloudhan
cloudhan / upgrade-nvidia-driver.sh
Last active August 7, 2019 08:58
Upgrade old nvidia driver
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
set -ev
echo -e "${GREEN}Downloading and installing nvidia repo${NC}"
wget http://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_10.0.130-1_amd64.deb
@cloudhan
cloudhan / http-server.py
Created October 9, 2019 10:22
Multi-threaded Http Server
#!/usr/bin/env python
try:
# Python 2.x
from SocketServer import ThreadingMixIn
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
except ImportError:
# Python 3.x
from socketserver import ThreadingMixIn
@cloudhan
cloudhan / single_thread.py
Last active March 6, 2020 09:45
Call this function before starting any sub-process, before importing any native library.
import os
import sys
def set_single_thread_envs():
"""Better to set single thread for multi-process environment.
We need to do this before all import call"""
try:
import mkl
@cloudhan
cloudhan / nvidia-driver-fix.sh
Created December 9, 2019 07:13
Weird `Failed to initialize NVML: Driver/library version mismatch`
#!/bin/bash
set -ev
# find the currently installed kernel module version
dkms status
# output example:
# bbswitch, 0.8, 4.9.70-040970-generic, x86_64: installed
# nvidia-418, 418.87.01, 4.9.70-040970-generic, x86_64: installed
@cloudhan
cloudhan / unbuffer_stdio.py
Last active March 24, 2020 06:41
make stdout unbuffered
class Unbuffered(object):
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def writelines(self, datas):
self.stream.writelines(datas)
/*************************************************************************
* Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
*
* See LICENSE.txt for license information
************************************************************************/
#include <arpa/inet.h>
#include <errno.h>
#include <ifaddrs.h>
#include <net/if.h>
@cloudhan
cloudhan / dynamic_mixin.py
Created September 8, 2020 03:04
dynamic mixin
def extend_instance(obj, cls):
"""Apply mixins to a class instance after creation"""
base_cls = obj.__class__
base_cls_name = obj.__class__.__name__
obj.__class__ = type(base_cls_name, (cls, base_cls), {})
@cloudhan
cloudhan / build.sh
Last active September 12, 2020 14:07
semi-auto port deb package from one distro to another.
#!/bin/bash
EMAIL=noreply@github.com
if [[ -z "$2" ]]
then
PPA_NUM="1"
else
PPA_NUM="$2"
fi