Skip to content

Instantly share code, notes, and snippets.

@kugland
kugland / escape_str.zsh
Last active June 9, 2022 01:47
Escape strings in Zsh
typeset -A escape_map
escape_map[_\\]='\\'
for code escape (
0 C@ 1 Ca 2 Cb 3 Cc 4 Cd 5 Ce 6 Cf 7 a
8 b 9 t 10 n 11 v 12 f 13 r 14 Cn 15 Co
16 Cp 17 Cq 18 Cr 19 Cs 20 Ct 21 Cu 22 Cv 23 Cw
24 Cx 25 Cy 26 Cz 27 e 28 'C\\' 29 'C]' 30 'C^' 31 C_
) {
@kugland
kugland / termbin
Created January 28, 2022 16:29
Create pastes on termbin.com
#!/bin/sh
while getopts "h" option; do
case "$option" in
h)
echo "termbin - Create pastes on termbin.com"
echo
echo "Usage: termbin [OPTIONS] [FILE] [FILE] ..."
echo
echo "Options:"
@kugland
kugland / urlencode
Last active January 28, 2022 06:34
urlencode / urldecode as a shell script
#!/bin/sh
SCRIPT_NAME="$(basename "$0")"
if [ "$SCRIPT_NAME" != "urlencode" ] && [ "$SCRIPT_NAME" != "urldecode" ]; then
echo 'Please run this script as "urlencode" or "urldecode"'
exit 1
fi
if [ $# -lt 1 ]; then
@kugland
kugland / get_script_vars.php
Created January 28, 2022 01:35
Get all variables from a PHP script
<?php
//
// Get all variables from a PHP script.
//
// Warning: This is probably not a good idea security-wise.
//
// Usage:
//
// Let's say you have a script called 'test.php', which contains the following:
@kugland
kugland / unicodedata
Last active January 17, 2022 02:17
Python script to get data from unicode character (from lib unicodedata)
#!/usr/bin/env python3
import re
import sys
import argparse
import unicodedata
if len(sys.argv) == 1:
sys.argv.append('-h')
@kugland
kugland / printable.rs
Last active June 7, 2022 13:15
Filter only printable characters from stdin. Like strings(1), but supporting UTF-8.
use std::io::{Read, Write, stdin, stdout};
enum State {
Normal,
Utf8(
/// total number of bytes in the sequence
usize,
/// number of bytes left to read
usize,
/// code point (accumulated)
@kugland
kugland / toggle-yakuake
Created December 31, 2021 22:46
Toggle yakuake’s window; if it’s not running, start it and then show the window. (So you don’t have to reopen it manually in case you accidentally closed it.)
#!/bin/bash
# Toggle yakuake's window; if it's not running, start it and then show the window.
# (So you don't have to reopen it manually in case you accidentally closed it.)
#
# To use this script, install it to /usr/local/bin/toggle-yakuake, then disable
# yakuake's global shortcut, and create a global shortcut pointing to this script.
#
# Written by André Kugland
@kugland
kugland / avr_reflect_u64.c
Last active March 21, 2021 10:01
Bit reflect for uint64_t hand-optimized for size for AVR processors. https://godbolt.org/z/qjn8rb
#include <inttypes.h>
typedef union {
uint64_t u64;
uint8_t u8[8];
} uint64_union;
__attribute__((optimize("Os"))) // Avoid loop unrolling.
void reflect_u64(uint64_t* value)
{
@kugland
kugland / remove-baloo.hook
Created December 3, 2020 07:58
Pacman Hook: Make sure baloo executables are links to /bin/true
# /usr/share/libalpm/hooks/remove-baloo.hook
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
// ==UserScript==
// @name Dicionário Analógico Aulete (correções)
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Corrige alguns problemas na página do dicionário analógico Aulete.
// @author You
// @match http://*.aulete.com.br/analogico/*
// @match https://*.aulete.com.br/analogico/*
// @grant none
// ==/UserScript==