Skip to content

Instantly share code, notes, and snippets.

View ceving's full-sized avatar
💭
Ejaculating

ceving

💭
Ejaculating
View GitHub Profile
@ceving
ceving / .emacs
Last active September 8, 2016 15:40
Dot Emacs Snippets
(defun msg (arg)
(message (format "%S" arg)))
(server-start)
(blink-cursor-mode 0)
(tool-bar-mode -1)
(setq column-number-mode t)
(show-paren-mode 1)
(setq-default blink-matching-paren nil)
@ceving
ceving / annex
Created September 13, 2016 09:11
Annex one or more files.
#! /bin/bash
set -eu
annex ()
{
local option
local OPTARG
local OPTIND
local recursive=
local user=${SUDO_UID:-$(id -ru)}
@ceving
ceving / sortable.js
Created October 12, 2016 15:24
Very basic and simple table sorter in plain JavaScript
// Sort the rows of a table body by the given column.
function sorttable (table, column) {
var trs = [];
var tbody = table.querySelector ('tbody');
for (var tr of tbody.querySelectorAll ('tr')) {
trs.push(tr.cloneNode(true));
tbody.removeChild(tr);
}
trs.sort(function(r1 ,r2) {
var c1 = r1.querySelectorAll('td').item(column).innerText;
@ceving
ceving / fix-ansible-output
Last active January 30, 2017 16:36
Fix Ansible to talk JSON
#! /bin/bash
##
## This converts the output of the `ansible` command into valid JSON,
## which can be processed by `jq`.
##
echo \[
sed 's/^\(.*\) | \(.*\) => {/{\n "hostname": "\1",\n "result": "\2",/' |
sed '$ ! s/^}/},/'
echo \]
@ceving
ceving / fac-fib-cps.scm
Created January 5, 2017 14:26
Factorial and Fibonacci in continuation passing style.
;; Convert a CPS function into a normal function by passing a
;; function, which returns just the argument, as a continuation to the
;; CPS function.
(define (ret x) x)
(define (cps f/k) (lambda (x) (f/k x ret)))
;; Some test values.
(define digits (list 0 1 2 3 4 5 6 7 8 9))
;; Factorial
@ceving
ceving / maze-parser.scm
Last active January 6, 2017 14:19
Basic parsing combinators
;; The following code uses two function types: `parsers` and `continuations`. The `parser` functions
;; require three arguments: `input`, `continue` and `backtrack`. The `continuation` functions
;; require just one argument `input`. The argument `input` is the list of input tokens to parse.
;; The arguments `continue` and `backtrack` are continuations. The continuation `continue` is
;; followed, when the tried parsing solution up the to current point is correct, which means that it
;; is not sure but it might lead to a overall success. And `backtrack` is used, if a missmatch has
;; been found, which means that an alternative parsing solution must be tried. The process is
;; similar to finding the way out of a maze.
;; Throw an error, if the assertion fails.
@ceving
ceving / ansible-inventory.el
Created January 12, 2017 16:54
Tweak Ansible's host inventory.
(defun expand-character (expansion c)
(if (null expansion)
(list (list c))
(mapcar (lambda (item)
(cons c item)) ;; This reverses the string.
expansion)))
(defun expand-sequence (expansion p q)
(apply #'append
(mapcar (lambda (c)
@ceving
ceving / regexp.pl
Last active January 13, 2017 12:08
Execute a regular expression on a list of strings
#! /usr/bin/perl
my $rs = shift;
my $rx = qr/$rs/;
for (@ARGV) {
exit 1 unless /$rx/;
}
@ceving
ceving / home.sh
Last active January 21, 2017 11:34
Customize HOME directory
#! /usr/bin/env bash
set -eu
cat <<EOF > "$HOME"/.bashrc
[ -z "$PS1" ] && return
shopt -s histappend
shopt -s checkwinsize
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
alias ll='ls -l'
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
@ceving
ceving / fossil-timeline-addel
Last active January 23, 2017 10:20
Display added and deleted files in a Fossil repository.
#! /bin/bash
##
## Display added and deleted files in a Fossil repository.
##
set -eu
prev_id=
fossil timeline -n 0 "$@" |
sed -n 's/^..:..:.. \[\([0-9a-f]*\)\] .*/\1/p' |
while read id; do
if [ "$prev_id" ]; then