This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Useful for specifing new WSL file path to save by vscode | |
function winpath() { | |
file_path=$(wslpath -a "$1") # Absolute path (full path) | |
file_basename=$(basename "${file_path}") | |
file_dirname=$(dirname "${file_path}") | |
if [ "$#" -eq 0 ]; then | |
wslpath -w . | |
elif [ "$#" -eq 1 ]; then | |
# Also works for new files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if false | |
g++ $0 && ./a.out | |
exit | |
#endif | |
// Modified code that demonstrates a code with multi-level return | |
#include <stdio.h> | |
void print_enter(const char* function_name) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if false | |
x86_64-w64-mingw32-g++ $0 -lole32 -static && ./a.exe | |
exit | |
#endif | |
// Above code makes it run as script | |
#include <cstdio> | |
#include <iostream> | |
#include <Windows.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example applications | |
# * Use with Windows Clock UWP app (the alarm volume depends on system sound volume, you might want to maximize it) | |
# * Avoids accidental unmute by setting sound volume to the lowest level | |
function Toggle-Volume { | |
if ( [audio]::Volume -ne 0 ) { | |
# Minimize-Volume | |
[audio]::Volume = 0 | |
} else { | |
# Maximize-Volume | |
[audio]::Volume = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Right click to dispose | |
# Load necessary .NET assembly | |
Add-Type -AssemblyName System.Windows.Forms | |
# Define the functions for Get-Brightness, Set-Brightness, and Toggle-Brightness | |
function Get-Brightness { | |
# Create CIM Session | |
$namespaceName = "root/wmi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example applications: | |
# * Improves privacy by dimming screen to lowest brightness immediately | |
# * Extend battery life by toggling screen brightness (as a faster alternative to sleep/wake that doesn't locks the computer) | |
# ** Reduces carbon footprint | |
# Written in Powershell Core | |
# Load necessary .NET assembly | |
Add-Type -AssemblyName System.Windows.Forms | |
# Define the functions for Get-Brightness, Set-Brightness, and Toggle-Brightness |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import webview | |
def set_title(): | |
window = webview.windows[0] | |
result = window.evaluate_js('document.title') | |
window.set_title(result) | |
if __name__ == '__main__': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
def parse_args(): | |
usage = 'kwarg-nargs.py [-h] [pos_args ...] [-dict_args [value] ... ] ...' | |
parser = argparse.ArgumentParser(add_help=False) | |
parser.add_argument('pos_args', nargs='*') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if 0 | |
gcc -x c++ "$0" | |
if [ $? -eq 0 ]; then | |
./a.out "$@" | |
fi | |
exit | |
clang -x c++ "$0" | |
if [ $? -eq 0 ]; then | |
./a.out "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess | |
import sys | |
bash_script = ''' | |
echo "$0" | |
echo "$@" | |
a=3 | |
<<<$a cat | |
''' |
NewerOlder