Skip to content

Instantly share code, notes, and snippets.

@gregberns
gregberns / gist:b197a36e5a7e5cd0e9da965511b355cb
Created April 29, 2019 15:54
Managing Secrets - Notes from 2019-04-24 PHX DevOps meetup
Notes from 2019-04-24 PHX DevOps meetup
Managing Secrets
NoDramaDevOps.com Blog
Platform Identity
* Can give a VM a service account which has rights to access
* Use short term credentials to talk between services.
@gregberns
gregberns / gist:f5fac3df9d5790c03647e014a91fdbbd
Created April 18, 2019 22:37
Rust implementation for `partition` function for `Result`
fn partition<A,B>(list: Vec<Result<A,B>>) -> (Vec<A>, Vec<B>) {
let mut aa = vec!();
let mut bb = vec!();
for i in list {
match i {
Ok(a) => aa.push(a),
Err(b) => bb.push(b),
};
}
(aa, bb)
@gregberns
gregberns / UniVerse-Change-Data-Capture-File-Format.md
Last active December 28, 2019 06:53
UniVerse Change Data Capture File Format

UniVerse Change Data Capture File Format

Below is a proposed data format to send UniVerse database changes via file. It uses standard UNIX delimiters for new lines, and standard UniVerse characters to deliniate fields (ASCII code 254 (þ)) and data (ASCII code 253 (ý)).

Example:

src=cssþns=CONTRACTSþts_ms=1550549470126þuid=12345678þop=uþdata=ý_id=1234ýname=Bobýþ
src=cssþns=CONTRACTSþts_ms=1550549470126þuid=12345678þop=uþdata=ý_id=1234ýname=Simonýþ
@gregberns
gregberns / Lib.hs
Last active January 23, 2019 05:55
Attempt at running Hedgehog readme examples
module Lib
( someFunc
) where
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
interface Integer2Integer {
int apply(int n);
}
static int blah(Integer2Integer r) { return r.apply(99); }
class Plus10 : Integer2Integer { Integer2Integer { int apply(int n) { return n + 10; } }
Console.WriteLine(blah(new Plus())); // what does that print?
maybe even a type alias
type Integer2Integer = Int -> Int
blah r = r 99
@gregberns
gregberns / rust_ref-deref.md
Created December 29, 2018 18:24
Rust - ref/derefs explanation

Thanks to @user#0540 and @Globi#0117 on the #beginners discord

Question: Coming from JS/C#/Haskell and trying to understand the & and * a bit better. In this code snippet, the n in the lambda apparently can either be |&n| n%2==0 or |n| *n%2==0. Could some one explain this a bit better? I think its something to do with reference/defreferece, but still not comfortable with those ideas.

let arr: [u16; 5] = [1, 2, 3, 4, 5];
let mut iterator = arr.iter().filter(|&n| n%2==0);
@gregberns
gregberns / the-algebra-of-algebraic-data-types.md
Created December 13, 2018 05:57
The Algebra of Algebraic Data Types, Part 1, by Chris Taylor
@gregberns
gregberns / SlowImplementationOfRights.purs
Created December 13, 2018 03:49
An implementation of the Either 'rights' function that is slow
import Data.Array (snoc)
import Data.Either (Either(..))
rights :: forall a b. Array (Either a b) -> Array b
rights array =
let
f (Left _) accumulator = accumulator
f (Right value) accumulator = snoc accumulator value
in
foldr f [] array
@gregberns
gregberns / FastImplementationOfRights.purs
Created December 13, 2018 03:49
A implementation of the Either 'rights' and 'lefts' functions
import Data.Either (Either(..), either, hush)
import Data.Array (mapMaybe)
import Data.Maybe (Maybe(..))
rights :: forall a b. Array (Either a b) -> Array b
rights array = mapMaybe hush array
-- Also the Lefts implementation
lefts :: forall a b. Array (Either a b) -> Array a
lefts array = mapMaybe (either Just (const Nothing)) array
@gregberns
gregberns / STMonadUse.purs
Created December 13, 2018 03:18
An example of the ST Monad to append items to a mutable array
import Data.Array
import Data.Array.ST (empty, push, freeze)
import Data.Either (Either(..))
import Control.Monad.ST.Internal (ST, foreach)
-- Return Rights from an Array of Either's using the ST monad
rights :: forall a b. Array (Either a b) -> Array b
rights array =
let
-- This seems to be required because