This file contains hidden or 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
# Usage Examples: | |
# wsl-msg hello world | |
# ./some_script && wsl-msg "Task Done" | |
wsl-msg() { | |
tput bel | |
# C:\Windows\System32\msg.exe from Windows 10 Pro | |
msg.exe '*' /V /W "$@" | |
} |
This file contains hidden or 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 | |
# Calls Windows' Sublime Text from WSL2 | |
# | |
# Usage: subl [arguments] [files] Edit the given files | |
# or: subl [arguments] [directories] Open the given directories | |
# or: subl [arguments] -- [files] Edit files that may start with '-' | |
# or: subl [arguments] - Edit stdin | |
# or: subl [arguments] - >out Edit stdin and write the edit to stdout | |
# |
This file contains hidden or 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
#pragma once | |
#define sizeof_as_compiler_error(type) struct sizeof__##type##__is* (*sizeof__##type)[sizeof(type)] = -1; |
This file contains hidden or 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 | |
set -eu | |
USAGE="\nUSAGE: $0 -i INPUT_C_CXX_FILE -o OUTPUT_C_CXX_FILE [ -c G++_COMPILER ]\n" | |
INPUT_FILE='' | |
OUTPUT_FILE='' | |
COMPILER='g++' | |
while [[ "$#" -gt 0 ]] ; do |
This file contains hidden or 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
# https://unix.stackexchange.com/a/37182/140618 | |
shopt -s autocd |
This file contains hidden or 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
#pragma once | |
// Dereference a pointer only if it is not null | |
#define ifnotnull(p) for (auto* p__ = p; p__ != nullptr; p__ = nullptr) (*p__) |
This file contains hidden or 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
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
This file contains hidden or 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 | |
set -eux | |
# From | |
# * Generating list of manually installed packages and querying individual packages | |
# * https://askubuntu.com/a/492343/543097 | |
# Tested on Ubuntu 18.04 | |
comm -23 <(apt-mark showmanual | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u) |
This file contains hidden or 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
#pragma once | |
#include <cstdint> | |
#include <exception> | |
#include <type_traits> | |
#include <utility> | |
// Usage | |
// ON_SCOPE_EXIT <callable> ; | |
// ON_SCOPE_EXIT_FAIL <callable> ; |
This file contains hidden or 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
# https://stackoverflow.com/a/2615112/865719 | |
# https://stackoverflow.com/a/7826789/865719 | |
# https://stackoverflow.com/q/2764051/865719 | |
# echo -n 'Hello' | tohex | |
# tohex INPUT_FILE | |
function tohex() { hexdump -ve '1/1 "%.2x"' "$@" ; } | |
function todec() { hexdump -ve '1/1 "%.3d"' "$@" ; } | |
function tobin() { | |
xxd -b "$@" | cut -d" " -f2-7 | tr -d ' ' | tr -d '\n' |
NewerOlder