Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / lineinfile
Created December 26, 2022 05:41
lineinfile, similar to the Ansible action, in Perl
#!/usr/bin/env -S perl -CSD
# Usage: lineinfile <regexp> <new_value> <file1> <file2> <file3> ...
use strict;
use warnings;
use utf8;
if (@ARGV < 3) {
die "Usage: $0 <regexp> <new_value> <file1> <file2> <file3> ..."

Keybase proof

I hereby claim:

  • I am kugland on github.
  • I am kugland (https://keybase.io/kugland) on keybase.
  • I have a public key whose fingerprint is 6A62 5E60 E3FF FCAE B3AA 50DC 1DA9 3817 80CD D833

To claim this, I am signing this object:

@kugland
kugland / sort-by-ext
Last active June 9, 2023 03:50
Sort input lines by extension
#!/usr/bin/env python3
# Copyright (C) 2023 Andre Kugland
# This script is released under the MIT License.
"""
sort-by-ext: Sort input lines by extension.
Usage: sort-by-ext [-0]