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
// Convert a sorting expressions (e.g. "Outflow DESC; Date ASC; Category ASC") | |
// into a function that can be passed to Array.prototype.sort. | |
function compileSort(expr) { | |
if (expr === '') { | |
return function(x, y) { return 0; }; | |
} | |
return expr.split(/\s*;\s*/).reverse().reduce((acc, x) => { | |
const [k, dir] = x.split(/\s+/); | |
if (dir === 'ASC') { | |
return function(x, 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
apiVersion: batch/v1 | |
kind: Job | |
metadata: | |
name: foo-command | |
spec: | |
ttlSecondsAfterFinished: 60 | |
template: | |
spec: | |
containers: | |
- name: foo-command |
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
input: | |
label: ynab_api | |
generate: | |
mapping: root = "" | |
interval: '@every 5m' | |
processors: | |
- cache: | |
operator: get | |
resource: pagination | |
key: latest |
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
# Proof-of-concept caching with benthos: | |
# - read from cache (with default on first run) | |
# - log value | |
# - write random value to cache | |
# - repeat | |
input: | |
generate: | |
mapping: root = "" | |
processors: |
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
{ pkgs, ... }: | |
let | |
# Invoked on the developer's machine from the command line as: | |
# $ deploy supported.foo | |
# $ deploy supported.bar | |
deploy = pkgs.writeShellScriptBin "deploy" '' | |
set -euo pipefail | |
readonly SYSTEM="$1" | |
readonly SCRIPT=$(NIXPKGS_ALLOWED_UNSUPPORTED_SYSTEM=1 nix-build --show-trace --no-out-link --attr $SYSTEM.deploy $REPO_ROOT) |
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
let | |
localPkgs = import <nixpkgs> {}; | |
crossPkgs = import <nixpkgs> { crossSystem = "x86_64-linux"; }; | |
in | |
{ | |
foo = localPkgs.ripgrep; | |
bar = crossPkgs.ripgrep; | |
} |
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 nix-shell | |
#! nix-shell -i bash -p rsync | |
echo "Inside script" | |
which rsync | |
echo "Exiting..." |
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
""" | |
1. Write a library that transforms python data types into Nix data types. | |
""" | |
# This library would need to convert python data types such as integers, strings, booleans, lists, dictionaries, and tuples into the Nix data types of strings, booleans, lists, sets, and recursive values. The library should use functions to convert each type of data. | |
# For example, a function to convert a python integer to a Nix string would look like this: | |
def int_to_nix_string(x): | |
return f'"{x}"' |
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
""" | |
1. Define an immutable list type. | |
2. Create a library for manipulating the list. | |
""" | |
# Answer | |
# 1. Define an immutable list type | |
class ImmutableList: |
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
(defmacro >-> (&rest forms) | |
"Compose a new, point-free function by composing FORMS together." | |
(let ((sym (gensym))) | |
`(lambda (,sym) | |
(->> ,sym ,@forms)))) |