Skip to content

Instantly share code, notes, and snippets.

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

amekusa amekusa

🏠
Working from home
View GitHub Profile
@amekusa
amekusa / External Command Overheads Comparison.lua
Last active January 30, 2025 13:21
Lua: External Command Overheads Comparison
-- git clone https://github.com/amekusa/humb.lua.git humb
local humb = require('humb')
local test = humb:new_test({
rpt = 1000,
digits = 4,
})
do
local os_execute = os.execute
@amekusa
amekusa / smart_indent.lua
Created December 22, 2024 19:37
A neovim function that smartly indents the current line
-- A neovim function that smartly indents the current line
-- By github.com/amekusa
-- Tested with neovim v0.10
--
-- # What it does
-- If the current line is empty,
-- copies the indentations of the previous or the next line. (The longer one is chosen)
--
-- If the current line is not empty,
-- simpy shift it to right.
@amekusa
amekusa / vimium-c.css
Last active November 17, 2024 21:35
Vimium C Settings
/* #ui */
.HM .LH {
/* hint box background */
background-color: #333d;
background-image: none;
/* hint box */
border: 1px solid DarkTurquoise;
border-radius: 4px;
box-shadow: -1px 2px 2px #0008;
:root {
--tridactyl-hintspan-bg: #333d !important;
--tridactyl-hintspan-font-family: "Georgia", monospace !important;
--tridactyl-hintspan-font-size: 13px !important;
--tridactyl-hintspan-font-weight: normal !important;
--tridactyl-hintspan-border-width: 1px !important;
--tridactyl-hintspan-border-style: solid !important;
}
span.TridactylHint {
@amekusa
amekusa / Remove comment lines and empty lines with Awk.md
Last active August 19, 2024 07:22
Removing comment lines & empty lines with Awk
awk '!/^([[:space:]]*#.*)?$/' testfile

testfile :

Beginning line
  Line starts with spaces
# Comment line
 # Comment line starts with spaces
@amekusa
amekusa / vimium.css
Last active March 12, 2024 22:12
My custom CSS for Vimium UI
div > .vimiumHintMarker {
/* linkhint boxes */
background: #333d;
border: 1px solid DarkTurquoise;
border-radius: 4px;
box-shadow: -1px 2px 2px #0008;
}
div > .vimiumHintMarker span {
/* linkhint text */
@amekusa
amekusa / escape.js
Last active November 19, 2023 08:07
Convert non-safe chars into HTML entities (JS)
/**
* Converts non-safe chars into HTML entities.
* @author amekusa
*/
function escape(str) {
if (!str) return '';
let map = {
'&': 'amp',
'"': 'quot',
"'": 'apos',
@amekusa
amekusa / deep-merge.js
Last active September 10, 2023 05:17
Deep Merge.js
/**
* Merges the 2nd object into the 1st object recursively (deep-merge). The 1st object will be modified.
* @param {object} x - The 1st object
* @param {object} y - The 2nd object
* @param {number} recurse=8 - Recurstion limit. Negative number means unlimited
* @return {object} The 1st object
* @author amekusa
*/
function merge(x, y, recurse = 8) {
if (recurse && x && y && typeof x == 'object' && typeof y == 'object' && !Array.isArray(x) && !Array.isArray(y)) {
if ! command -v realpath &> /dev/null; then
realpath() {
case "$1" in
/*) echo "$1" ;;
~/*) echo "$HOME/${1:2}" ;;
./*) echo "$PWD/${1:2}" ;;
~) echo "$HOME" ;;
.) echo "$PWD" ;;
*) echo "$PWD/$1" ;;
esac
@amekusa
amekusa / Iterate over key-value array.sh
Last active April 21, 2023 07:51
Iterate over key-value array in bash
arr=(
name="John Doe"
age=32
job="Software Engineer"
)
for each in "${arr[@]}"; do
key="${each%%=*}"
val="${each:$((${#key}+1))}"
echo "$key: $val"