Skip to content

Instantly share code, notes, and snippets.

Avatar

Johann Chang changyuheng

View GitHub Profile
@changyuheng
changyuheng / keepawake.ps1
Last active Jul 21, 2022 — forked from jamesfreeman959/keepawake.ps1
A very simple PowerShell script to keep a Windows PC awake and make lync think the user is active on the keyboard
View keepawake.ps1
# Useful references:
#
# https://superuser.com/questions/992511/emulate-a-keyboard-button-via-the-command-line
# https://ss64.com/vb/sendkeys.html
# https://social.technet.microsoft.com/Forums/windowsserver/en-US/96b339e2-e9da-4802-a66d-be619aeb21ac/execute-function-one-time-in-every-10-mins-in-windows-powershell?forum=winserverpowershell
# https://learn-powershell.net/2013/02/08/powershell-and-events-object-events/
#
# Future enhancements - use events rather than an infinite loop
$wsh = New-Object -ComObject WScript.Shell
while (1) {
@changyuheng
changyuheng / swap-caps-lock-and-left-control.reg
Created Oct 4, 2021
Swap left control and caps lock on Windows
View swap-caps-lock-and-left-control.reg
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,3a,00,1d,00,00,00,00,00
; Refs:
; https://superuser.com/a/1381836
@changyuheng
changyuheng / multiprocessing-queue-manager-client.py
Last active Jul 20, 2021
Python multiprocessing server client inter-process communication (IPC) over Queue. https://stackoverflow.com/a/62608473/1592410
View multiprocessing-queue-manager-client.py
import multiprocessing
import multiprocessing.managers
import os
import sys
from typing import AnyStr, Union
class QueueManager(multiprocessing.managers.BaseManager):
def get_queue(self, ident: Union[AnyStr, int, type(None)] = None) -> multiprocessing.Queue:
@changyuheng
changyuheng / remap-mac-keyboard-modifier-keys-on-windows.reg
Last active Jul 7, 2021
Swap left command and left option keys, remap right command to right alt, remap right option to context menu on Windows
View remap-mac-keyboard-modifier-keys-on-windows.reg
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,05,00,00,00,5b,e0,38,00,38,00,5b,e0,38,e0,5c,e0,5d,e0,38,e0,00,00,00,00
; Refs:
; https://superuser.com/a/1202601/270174
; https://stackoverflow.com/questions/40777182/how-to-remap-the-menu-key-on-windows
@changyuheng
changyuheng / 20-noto-cjk.conf
Created Nov 15, 2014
.config/fontconfig/conf.d/20-noto-cjk.conf
View 20-noto-cjk.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="pattern">
<test name="lang">
<string>zh-tw</string>
</test>
<test name="family">
<string>sans-serif</string>
</test>
@changyuheng
changyuheng / fib.go
Last active Sep 10, 2019
[Interview] Please modify the program, so the Fibonacci sequence starts from 0 instead of 1.
View fib.go
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import "fmt"
@changyuheng
changyuheng / print-asterisk-triangle.py
Last active Aug 26, 2019
Print an asterisk triangle without for-loops
View print-asterisk-triangle.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import logging
import os
import sys
def parse_args() -> argparse.Namespace:
View bfs.py
# Ref. http://eddmann.com/posts/depth-first-search-and-breadth-first-search-in-python/
def bfs(graph, queue, visited=None):
if visited is None:
visited = set()
if not queue:
return
start = queue.pop(0)
yield start
View dfs.py
# Ref. http://eddmann.com/posts/depth-first-search-and-breadth-first-search-in-python/
def dfs(graph, start, visited=None):
if visited is None:
visited = set()
if start in visited:
return
yield start
visited.add(start)
View google-1.py
def solve(s: str, n: int, iseven: bool):
if n <= 0:
print(s)
return
i: int
for i in range(10) if iseven else range(9, -1, -1):
solve(s + chr(ord('0') + i), n - 1, i % 2 == 0 if iseven else i % 2 == 1)
solve('', int(input()), True)