Skip to content

Instantly share code, notes, and snippets.

View andreabedini's full-sized avatar
☺️

Andrea Bedini andreabedini

☺️
View GitHub Profile
{-# LANGUAGE TemplateHaskell #-}
module NgxDistributionTest where
import NgxExport
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy.Char8 as C8L
import Data.Aeson
import Data.Maybe
@andreabedini
andreabedini / flake.nix
Last active February 21, 2024 04:54
Go to Nix with IFD
{
inputs.nixpkgs.url = "github:NixOs/nixpkgs/22.11";
outputs = { self, nixpkgs }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
inherit (pkgs) lib;
lines = txt:
(builtins.filter (line: line != "")
matchMaybe :: forall a. TomlBiMap a AnyValue -> Key -> TomlCodec (Maybe a)
matchMaybe Toml.BiMap {forward, backward} key = Toml.Codec input output
where
input :: Toml.TomlEnv (Maybe a)
input toml = case HashMap.lookup key (Toml.tomlPairs toml) of
Nothing -> pure Nothing
Just anyVal -> pure <$> Toml.whenLeftBiMapError key (backward anyVal) pure
output :: Maybe a -> Toml.TomlState (Maybe a)
@andreabedini
andreabedini / nix-to-oci.sh
Created April 6, 2023 07:46
Upload a nix closure to a container registry
#/usr/bin/bash
set -e
USAGE="Usage: $0 repository installables..."
if [ "$#" == "0" ]; then # If zero arguments were supplied,
echo "Error: no repository or installables provided."
echo "$USAGE" # display a help message
exit 1 # and return an error.
fi
{
inputs.nix.url = "github:NixOS/nix/2.13.2";
outputs = { self, nixpkgs, nix }: {
packages.x86_64-linux.default =
nix.packages.x86_64-linux.nix.overrideAttrs (oldAttrs: {
separateDebugInfo = false;
phases = [ "unpackPhase" "patchPhase" "autoreconfPhase" "configurePhase" "installPhase" ];
outputs = [ "out" ];
#!/usr/bin/env bash
SESSION_NAME="$USER@$HOST" # or whatever
echo "Requesting federation token"
TOKEN1=$(aws sts get-federation-token --name "$SESSION_NAME" --policy-arns arn=arn:aws:iam::aws:policy/AdministratorAccess --output json)
URL1=$(jq -r '.Credentials | {sessionId:.AccessKeyId,sessionKey:.SecretAccessKey,sessionToken:.SessionToken} | @uri "https://signin.aws.amazon.com/federation?Action=getSigninToken&SessionType=json&Session=\(.)"' <<< "$TOKEN1")
@andreabedini
andreabedini / plan-to-datalog.jq
Created December 15, 2022 08:18
plan-to-datalog.jq
#!/usr/bin/env -S jq -f -r
#
# This jq scripts transforms cabal's plan.json file into a series of fact that souffle can interpret.
#
# Example use
#
# $ ~/plan-to-datalog.jq <dist-newstyle/cache/plan.json >plan.dl
#
# Then create a file query.dl
#
@andreabedini
andreabedini / git
Created August 3, 2022 14:38
git wrapper to make cabal and hls cache git checkouts more efficiently
#!/usr/bin/env bash
# only subvert cabal
PARENT_COMMAND=$(ps -o comm= $PPID)
if [ "$PARENT_COMMAND" != "cabal" ]; then
exec /usr/bin/git "$@"
fi
echo "$PWD /usr/bin/git $*" >> ~/git-log
@andreabedini
andreabedini / gist:65ff9fa41ee1631769f5ea89c7c854c8
Last active September 22, 2021 03:54
R Graphics on the terminal with Kitty

base set up:

options(device = function(...) bitmap(file = "|kitty +kitten icat --stdin yes", ...))

with options (eg. anti-aliasing)

options(device = function(...) bitmap(file = "|kitty +kitten icat --stdin yes", taa = 2, gaa = 2, ...))

title: Function all the way down. Programming in λ calculus. author: Andrea Bedini ...

Hello

  • @andreabedini (GitHub ✅, Facebook ✗, Twitter ✗)
  • Data Scientist @Fortescue by day
  • Programming languages nerd