This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Preprocess a dot file to support long edges and backward edges: | |
# | |
# Input Output | |
# | |
# a ----------> b a -> b | |
# a ---> b ---> c a -> b -> c | |
# a ----------- b a -- b | |
# a <--- b b -> a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git_stash_size() { | |
n=$( (git stash list 2> /dev/null || :) | wc -l ) | |
if [ $n -gt 0 ]; then | |
echo -n " +$n" | |
fi | |
} | |
git_branch() { | |
echo -n "$(git branch 2> /dev/null \ | |
| sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/')" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Some module defining an abstract type t that does not support the built-in | |
polymorphic comparison functions Pervasives.compare, (=), (<) etc. | |
Attempts to use polymorphic comparison on objects of type t | |
will raise an exception, except when comparing | |
the same object with Pervasives.compare. | |
This is a hack that may or may not work depending on the OCaml compiler | |
or its version. Use the provided test function to check that it behaves |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Interactive approach | |
-------------------- | |
You can copy-paste code into `utop`, provided you load the lwt.unix | |
package: | |
#use "topfind";; | |
#thread;; (* only needed in the plain `ocaml` toplevel, not in `utop`. *) | |
#require "lwt.unix";; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
f() { | |
echo "$x" | |
} | |
main() { | |
local x=42 | |
f | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
x=1 | |
f() { | |
echo "$x" | |
} | |
g() { | |
local x=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
x=0 | |
y=0 | |
read x <<EOF | |
1 | |
EOF | |
echo 1 | read y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# | |
# Run parallel commands and fail if any of them fails. | |
# | |
set -eu | |
pids=() | |
for x in 1 2 3; do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# | |
# Illustrate what happens when editing a script while it's running. | |
# | |
# This happens when saving the file in emacs, for example, but not with | |
# 'sed -i' because the latter deletes the old file before writing a new one. | |
# See https://unix.stackexchange.com/a/88572/46435 for an explanation. | |
# | |
set -eu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Created by Martin Jambon and placed in the Public Domain on June 1, 2019. | |
Print a tree or a DAG as tree, similarly to the 'tree' command. | |
*) | |
open Printf | |
let rec iter f = function | |
| [] -> () |