Skip to content

Instantly share code, notes, and snippets.

View ulve's full-sized avatar

Olov Johansson ulve

  • Future Ordering
  • Umeå
View GitHub Profile
@ulve
ulve / du.ps1
Last active July 17, 2023 06:28
du-h in powershell
param([string]$Directory)
get-childitem $Directory |
% { $f = $_ ;
get-childitem -r $_.FullName |
measure-object -property length -sum |
select @{Name="Namn";Expression={$f}},@{Name="Sum (Mb)"; Expression={"{0:N1}" -f ($_.sum / 1MB)}}}
@ulve
ulve / phoenixprodstart.sh
Created February 2, 2016 20:16
Run phoenix in production mode
MIX_ENV=prod mix compile.protocols
MIX_ENV=prod PORT=4001 elixir -pa _build/prod/consolidated -S mix phoenix.server
@ulve
ulve / remoteobserver.sh
Created February 2, 2016 20:19
Connect to remote phoenix node with observer
# On the phoenix node
# if production mode
MIX_ENV=prod PORT=4001 elixir --name phoenix@127.0.0.1 --cookie 123 --erl "-kernel inet_dist_listen_min 9001 inet_dist_listen_m 9001" -pa _build/prod/consolidated -S mix phoenix.server
# if debug mode
elixir --name phoenix@127.0.0.1 --cookie 123 --erl "-kernel inet_dist_listen_min 9001 inet_dist_listen_m 9001" -S mix phoenix.server
# On the observing node
# Terminal 1, start SSH tunnel
ssh -N -L 9001:localhost:9001 -L 4369:localhost:4369 pi@192.168.1.31
@ulve
ulve / DSL.ts
Created May 9, 2018 07:01
Sample DSL with interpreter in TypeScript
type Program<T> = Read<T> | Write<T> | Done<T>;
interface Read<T> {
kind: "Read";
next: (data: T) => Program<T>;
}
interface Write<T> {
kind: "Write";
valToWrite: string;
@ulve
ulve / install_phoenix.sh
Last active February 1, 2021 19:21
Install Erlang/Elixir/Phoenix on a Raspberry Pi
#!/bin/bash
sudo apt-get update
sudo apt-get --assume-yes install wget
sudo apt-get --assume-yes install libssl-dev
sudo apt-get --assume-yes install ncurses-dev
sudo apt-get --assume-yes install m4
# erlang
wget http://erlang.org/download/otp_src_18.2.tar.gz
tar -xvzf otp_src_18.2.tar.gz
cd otp_src_18.2
;; container - An existing container at the sotrage account
;; blob-connection-string - Connectionstring for the strage account
;; This is used from environ to have different configurations
{:dev {:env {:container "<containerName>"
:blob-connection-string "DefaultEndpointsProtocol=https;AccountName=<name>;AccountKey=<key>;EndpointSuffix=core.windows.net"}}}
@ulve
ulve / catamorph.ts
Last active January 24, 2020 13:36
Typescript catamorphism
interface Book {
kind: "book";
price: Number;
title: String;
}
interface Chocolate {
kind: "chocolate";
taste: String;
price: Number;
<#
.SYNOPSIS
Query a CosmoDb.
.DESCRIPTION
This command will query a cosmos db and return the results as an object.
.PARAMETER EndPoint
The endpoint to the CosmosDb Account.
@ulve
ulve / Hopac api gateway.fsx
Created March 13, 2018 14:14
Using hopac as a api gateway in f#
#r "packages/Hopac/lib/net45/Hopac.dll"
#r "packages/Hopac/lib/net45/Hopac.Core.dll"
#r "packages/Hopac/lib/net45/Hopac.Platform.dll"
#r "packages/FSharp.Data/lib/net45/FSharp.Data.dll"
#r "packages/Http.fs/lib/net461/HttpFs.dll"
#r "packages/System.Net.Http/lib/net46/System.Net.Http.dll"
open Hopac
open Hopac.Infixes
open FSharp.Data
@ulve
ulve / x509topem.cs
Last active January 7, 2019 10:34
X509Certificate2 private key to PEM
public static string ExportPrivateKey(X509Certificate2 certificateWithPrivateKey)
{
var parameterList = RsaParametersToList(certificateWithPrivateKey.GetRSAPrivateKey().ExportParameters(true));
var parameterBytes = SerializeList(parameterList);
var base64 = Convert.ToBase64String(parameterBytes);
var builder = new StringBuilder();
builder.Append("-----BEGIN RSA PRIVATE KEY-----\n");
for (int i = 0; i < base64.Length; i += 64)