Skip to content

Instantly share code, notes, and snippets.

#!/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];
@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/bash
trap 'rm -rf "$tempdir"' EXIT
tempdir=$(mktemp -d)
cd "$tempdir" || exit 1
printf '%s\n' \
'(return 2>/dev/null); echo $?' \
> bash_return
#!/bin/bash
save=$(bind -p; bind -X)
function clean-up {
bind -r '\C-i'
bind -f /dev/stdin <<< "$save"
}
trap 'clean-up' RETURN
function write-options {
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Arrays;
import java.io.FileNotFoundException;
import java.io.IOException;
public class A {
public static int solution(int N) {
int[] seen;
int i;
#!/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