Skip to content

Instantly share code, notes, and snippets.

View agumonkey's full-sized avatar

gum agumonkey

  • NONE
  • Dark side of the moon @ ['tkf8-2-1', 'ay21-3', '3263-827']
View GitHub Profile
@tavisrudd
tavisrudd / Lazy infinite streams in Bash
Last active May 23, 2017 14:30
Lazy, infinite recursive sequences in Bash (like in Haskell, if you squint). The result is ugly but interesting.
Lazy, infinite recursive sequences in Bash (like in Haskell, if you squint).
I was inspired by the beautiful Haskell zipWith implementation of the Fibonacci sequence `fibs = 0 : 1 : zipWith (+) fibs (tail fibs)`
to find an equivalent in bash using 'coroutines' and recursive pipes.
My original experiments were https://twitter.com/tavisrudd/status/367164339716751360
"fun w/ recursive pipes: e=echo;mkfifo fib;{ $e 0 1 1 >fib &};{ while read i j k; do $e $i >&2; $e $j $k $(($j+$k));sleep .4; done;}<fib>fib"
and https://twitter.com/tavisrudd/status/367142071489937408
"o=ouro;b=boros;mkfifo $o$b;e=echo; { $e $o > $o$b & }; { while read s;do $e $s>&2;case $s in $o)$e $b;;*)$e $o; esac; done; }<$o$b >$o$b"
(defun remote-shell-fav-hosts-get ()
"My hook to the remote-shell processes in order to connect to
my OpenStack controller, and create a hashtable of host names as
the keys, and IP addresses as the values."
(interactive)
;; Run nova list command remotely on this host system, and put the
;; results in a temp buffer:
(let* ((undercloud-controller "10.98.1.145")
(default-directory (format "/ssh:%s:" undercloud-controller))
@gmorpheme
gmorpheme / eval.clj
Created March 1, 2014 17:27
Lisp in Small Pieces of Clojure - chapter one
(ns ^{:doc "Evaluator from ch1 of lisp in small pieces. Warning:
NON-IDIOMATIC clojure!"}
lisp.chapter1.eval
(:refer-clojure :exclude [extend]))
(defn wrong [& msgs]
(throw (RuntimeException. (apply str msgs))))
;; -- runtime support, environments are represented as a seq of pairs,
;; -- stored in an atom. Non-idiomatic but faithful to the book.
#lang racket
;; A solver for the following puzzle:
;; Given 5 integers a, b, c, d, and e,
;; find an expression that combines a, b, c, and d with arithmetic operations (+, -, *, and /) to get e.
(require srfi/1)
(define ops '(+ - * /))
@swlaschin
swlaschin / type-dependency-graph.fsx
Last active March 4, 2021 19:24
This script analyzes the dependencies between top level types in a .NET Assembly. It is then used to compare the dependency relationships in some F# projects with those in some C# projects.
(*
This script analyzes the dependencies between top level types in a .NET Assembly.
It is then used to compare the dependency relationships in some F# projects with those in some C# projects.
Note that no attempt has been made to optimize the code yet!
REQUIRES:
* Mono.Cecil for code analysis
From http://www.mono-project.com/Cecil#Download
@aztek
aztek / Functor.v
Created June 11, 2012 17:11
Coq Functor type class with statically checked functor laws
Require Import Coq.Program.Basics.
Require Import Coq.Program.Syntax.
Require Import Coq.Init.Datatypes.
Require Import Coq.Unicode.Utf8.
Open Local Scope program_scope.
Open Local Scope list_scope.
Open Local Scope type_scope.
Class Functor (φ : Type → Type) := {
@floriandejonckheere
floriandejonckheere / 40_iso.cfg
Created September 29, 2015 07:50
GRUB entry for booting Arch Linux ISO
# This entry boots an Antergos (Arch) Linux ISO straight from disk.
# LVM is not supported because the lvm module is not loaded in Antergos initrd
menuentry "Antergos Minimal ISO 2015-09-13" {
insmod part_gpt
insmod lvm
insmod loopback
set root=(hd0,0)
set isofile=/antergos.iso
search --no-floppy --file ${isofile} --set
@heppu
heppu / ARCH_INSTALL.MD
Last active February 27, 2022 17:01
Installing Arch with GPT, dm-crypt, LUKS, LVM and systemd-boot

Create bootable USB

dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx status=progress oflag=sync

Boot from USB and set prepare system

loadkeys <your-keymap>
@pathikrit
pathikrit / NQueen.scala
Last active January 19, 2023 21:30
O(n!) solution to the n-Queen puzzle (https://en.wikipedia.org/wiki/Eight_queens_puzzle)
/**
* Solves the n-Queen puzzle in O(n!)
* Let p[r] be the column of the queen on the rth row (must be exactly 1 queen per row)
* There also must be exactly 1 queen per column and hence p must be a permuation of (0 until n)
* There must be n distinct (col + diag) and n distinct (col - diag) for each queen (else bishop attacks)
* @return returns a Iterator of solutions
* Each solution is an array p of length n such that p[i] is the column of the queen on the ith row
*/
def nQueens(n: Int): Iterator[Seq[Int]] =
(0 until n)
@CAFxX
CAFxX / persistent_pipes_linux.md
Last active January 4, 2024 04:32
Persistent pipes/circular buffers for Linux

📂 Persistent "pipes" in Linux

In a project I'm working on I ran into the requirement of having some sort of persistent FIFO buffer or pipe in Linux, i.e. something file-like that could accept writes from a process and persist it to disk until a second process reads (and acknowledges) it. The persistence should be both across process restarts as well as OS restarts.

AFAICT unfortunately in the Linux world such a primitive does not exist (named pipes/FIFOs do not persist