Skip to content

Instantly share code, notes, and snippets.

View kiennq's full-sized avatar
🏠
Working from home

kiennq

🏠
Working from home
View GitHub Profile
@kiennq
kiennq / clip_content.ps1
Created November 22, 2023 06:50
Get Clipboard content in via WinRT API as powershell script
Add-Type -AssemblyName System.Runtime.WindowsRuntime
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
function Await($WinRtTask, $ResultType) {
$asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
$netTask = $asTask.Invoke($null, @($WinRtTask))
$netTask.Wait(-1) | Out-Null
$netTask.Result
}
$null = [Windows.ApplicationModel.DataTransfer.Clipboard, Windows.ApplicationModel.DataTransfer, ContentType=WindowsRuntime]
@kiennq
kiennq / windows_setup.ps1
Created September 10, 2022 13:18
Windows Env Setup template
# install scoop for other packages
# Need to use job since scoop installer can just {exit 1}
Start-Job -ScriptBlock {
Invoke-WebRequest -useb 'get.scoop.sh' | Invoke-Expression -ErrorAction SilentlyContinue
} | Wait-Job | Receive-Job
if (!(Get-Command 'git' -ErrorAction SilentlyContinue))
{
scoop install git
}
@kiennq
kiennq / .gitignore
Last active June 18, 2024 22:26
Enable `Mermaid diagrams` on github wiki and markdown files
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
@kiennq
kiennq / build_emacs.sh
Last active January 29, 2023 20:32
Build emacs-snapshot on Ubuntu 18.04
git clone --single-branch --depth=1 https://github.com/emacs-mirror/emacs.git
cd emacs/
sudo apt install -y autoconf make gcc texinfo libxpm-dev \
libjpeg-dev libgif-dev libtiff-dev libpng-dev libgnutls28-dev \
libncurses5-dev libjansson-dev libharfbuzz-dev
./autogen.sh
./configure --with-json --with-modules --with-harfbuzz --with-compress-install \
--with-threads --with-included-regex --with-zlib --with-cairo --without-rsvg\
--without-sound --without-imagemagick --without-toolkit-scroll-bars \
--without-gpm --without-dbus --without-makeinfo --without-pop \
@kiennq
kiennq / emacs-async-config.el
Last active November 30, 2019 04:34
Limit number of async processes ever created at a time
(use-package async
:ensure t
:defer 5
:init
(setq async-bytecomp-allowed-packages '(all))
:config
;; async compiling package
(async-bytecomp-package-mode t)
(dired-async-mode 1)
;; limit number of async processes
#!python
import random
def rnd04():
return random.randint(0,4);
def rnd03():
rnd = rnd04()
while rnd > 3: