Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
python -c '
import sys
x = sys.stdin.readlines()
try:
print(x[0].decode("utf-8"))
except Exception as e:
print(repr(e.object))
' <<< $'\xed'
11 bash: 2
8 dash: 0
3 dash: 3
10 jsh: 0
1 jsh: 3
11 ksh: 3
11 mksh: 0
11 zsh: 2
@dualbus
dualbus / README
Last active November 26, 2020 17:48
How to detach processes from bash properly.
Relevant section from ''man bash'', SIGNALS:
> The shell exits by default upon receipt of a SIGHUP. Before exiting, an interactive shell resends the SIGHUP to all jobs,
> running or stopped. Stopped jobs are sent SIGCONT to ensure that they receive the SIGHUP. To prevent the shell from send‐
> ing the signal to a particular job, it should be removed from the jobs table with the disown builtin (see SHELL BUILTIN
> COMMANDS below) or marked to not receive SIGHUP using disown -h.
>
> If the huponexit shell option has been set with shopt, bash sends a SIGHUP to all jobs when an interactive login shell
> exits.
#!/bin/sh
ip -o addr \
| awk '
$2 ~ /:$/ {
i=$2;
sub(/:$/,"",i);
status[i]=$9
}
$3 == "inet" {
// Input jobs
var jobs = [
{'hash': 'abc', 'initial': 0, 'final': 99},
{'hash': 'abc', 'initial': 100, 'final': 199},
{'hash': 'abc', 'initial': 200, 'final': 299},
...,
];
// Task definition
var task = function(description) {
#!/usr/bin/env python
from zipfile import ZipFile
from os import walk
from os.path import isfile, isdir, join
class Zipper(object):
_class = ZipFile
def __init__(self, zip_file, recurse=False):
self._zip = self._class(zip_file, 'w')
@dualbus
dualbus / ini
Created November 20, 2013 00:48
INI file parser in bash
#!/bin/bash
shopt -s extglob
function isValidIdentifier {
typeset identifier=$1 identifierPattern='+([[:alpha:]_])+([[:alnum:]_])'
$ js wat.js
2
0
11
0
11
0
1
1
1
package main
import (
"os"
"strconv"
)
func fibonacci(n int) uint64 {
if n > 0 {
return fibonacci(n - 1) * uint64(n);
#!/usr/bin/awk -f
function sqlite_escape(v) {
gsub(/'/, "''", v);
return v;
}
function process_line(_F, _NF) {
print "1:", _F[1];
print "second to last:", _F[_NF - 1];