Skip to content

Instantly share code, notes, and snippets.

$ function map () { while read -r VAR; do eval "$@"; done }
$ seq 5 | map echo '{{{$VAR}}}'
{{{1}}}
{{{2}}}
{{{3}}}
{{{4}}}
{{{5}}}
#!/bin/bash
# Usage:
#
# nit-parallel [cosmos-running-instances args ...] -- [parallel args ...]
#
# e.g.
#
# ### No piped input: run command on all hosts
# nit-parallel -e test pm-nitro-test-1 -- hostname
@HakimCassimallyBBC
HakimCassimallyBBC / scratch.clj
Created July 25, 2017 11:37
FSM programme flow, allowing pure single-stepping through a branching pipeline
(ns scratch.scratch
(:gen-class))
(defn effect? [[k f]]
(= \! (last (name k))))
(defn if? [[k f]]
(= :if k))
(defn step [model fsm]
@HakimCassimallyBBC
HakimCassimallyBBC / foo.clj
Created October 24, 2017 15:20
clojure zipper attributes?
(defn nodes-to-bequeath [parent]
(xml-> (zipper/xml-zip parent)
zipper/children
#(if (get-in % [:attrs ::pm/inherit]) % nil)))
$('tr.memberships__table-row')
.filter( function () { return $(this).find('td.memberships__td-user-status--active').length })
.map( function () { return $(this).find('td.memberships__td-user').get(0).title })
.get()
.sort()
.join("\n")
@HakimCassimallyBBC
HakimCassimallyBBC / num.py
Created November 10, 2020 09:30
Rather "un-pythonic" FP-ish (but with explicit array access) snippet, discovered in an algorithm book
import functools
def roman_to_integer(s: str) -> int:
T = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}
return functools.reduce(
lambda val, i: val + (-T[s[i]] if T[s[i]] < T[s[i+1]] else T[s[i]]),
reversed(range(len(s)-1)), T[s[-1]])