Skip to content

Instantly share code, notes, and snippets.

View ninjarobot's full-sized avatar

Dave Curylo ninjarobot

  • Microsoft @Azure
  • Atlanta, GA
View GitHub Profile
apt-get update && apt-get install -y gcc
mkbundle --simple --machine-config /etc/mono/4.5/machine.config --config /etc/mono/config -L /usr/lib/mono/4.5 --library /usr/lib/libmono-btls-shared.so -o paket paket.exe
@ninjarobot
ninjarobot / brew_install_nsd.sh
Created May 25, 2018 10:55
Installing nsd on macOS with brew
$ brew install nsd
==> Installing dependencies for nsd: openssl, libevent
==> Installing nsd dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2o_1.high_sierr
######################################################################## 100.0%
==> Pouring openssl-1.0.2o_1.high_sierra.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
@ninjarobot
ninjarobot / parsing_json.pl
Created July 6, 2018 20:04
Parsing a JSON string in SWI-Prolog
?- use_module(library(http/json_convert)).
true.
?- json:atom_json_term('{"foo":"bar"}',T, []), T=json(J), J.foo=Bar.
T = json([foo=bar]),
J = [foo=bar],
Bar = bar.
@ninjarobot
ninjarobot / processing-a-delimited-string.md
Last active July 19, 2018 18:33
Processing a delimited string
?- S = "the|little|brown|fox|lost|its|way", split_string(S,"|","",Strings), maplist(string_length,Strings,Lengths), list_to_set(Lengths,Set).
S = "the|little|brown|fox|lost|its|way",
Strings = ["the", "little", "brown", "fox", "lost", "its", "way"],
Lengths = [3, 6, 5, 3, 4, 3, 3],
Set = [3, 6, 5, 4].
@ninjarobot
ninjarobot / littlesuave.sh
Created August 22, 2018 13:35
Script to make a build a tiny running Suave server
#!/bin/bash
dotnet new console -n littleSuaveApp -lang F#;
cd littleSuaveApp;
dotnet add package suave;
awk '/open System/{print "open Suave"}; /0/{print " startWebServer { defaultConfig with bindings = [ HttpBinding.createSimple HTTP \"0.0.0.0\" 8080 ] } (Successful.OK \"Hello World!\")"}1' Program.fs > tmp.fs;
mv tmp.fs Program.fs;
dotnet publish -c Release;
@ninjarobot
ninjarobot / dotnet.yaml
Last active April 7, 2024 13:13
Ansible playbook to install the .NET Core SDK on an Ubuntu server.
---
- hosts: all
tasks:
- name: Download MS product repository
get_url:
url: https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
dest: /tmp/packages-microsoft-prod.deb
- name: Install MS product repository
apt: deb=/tmp/packages-microsoft-prod.deb
become: true
@ninjarobot
ninjarobot / ExampleTypedWebParts.md
Last active January 17, 2019 13:24
Composing web handlers with type safety in Suave or Giraffe

Type Safe Composition of HTTP Handlers in Suave and Giraffe

Suave and Giraffe are functional web frameworks that work based on composition of handlers. A handler is a function that accepts an HttpContext and returns an Async<HttpContext option>, fitting nicely into an HTTP server's protocol of accepting HTTP messages with a request and some metadata, then returning a message with that metadata and a response. This makes the WebPart in Suave, for example.

While the frameworks themselves only allow you to put a WebPart into the processing pipeline, it is entirely up to you how you compose functions together to get that WebPart. When you compose WebPart A and WebPart B (or HttpHandler A and HttpHandler B), you are using the a compose operator - >=>. Take a look at the function:

let compose (first : 'a -> Async<'b option>) (second : 'b -> Async
@ninjarobot
ninjarobot / system.drawing.colors.pdf
Created February 6, 2019 13:06
PDF Generated by F#
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ninjarobot
ninjarobot / strace-netcore.md
Last active May 24, 2022 19:22
Trace .NET Core Applications on Linux with `strace`

Trace .NET Core Applications on Linux with strace

Troubleshooting a running application can be difficult, usually it starts around checking log output and then following through the likely code paths to get an idea of where a failure may occur. In a development environment, you might attach a debugger a step through source, but troubleshooting isn't always that convenient. There are several helpful tools that can assist, but one that gives the most comprehensive view of a running application is strace. With strace you are able to see all of the system calls an application makes to get a detailed understanding of what is going on "under the hood" in order to troubleshoot an issue.

Take a simple "hello world" F# application, the kind you get from dotnet new console -lang F# -n strace-sample". Build it with dotnet build and then launch it with strace to get a trace of all the system calls in a file called trace.log(adjusting for your build output path if on a different framework vers

@ninjarobot
ninjarobot / RoadToFSharp.md
Last active June 2, 2020 09:21
How I ended up as an F# developer.

My Road to F#

I came from the OOP world, most of my professional work was in Java or C#. The languages were similar, and I could use them interchangably as I built software in each of them for several years. With enough experience in both, I was comfortable with either ecosystem and could generally be productive in either. Sometimes the job required one or the other. Sometimes the target OS constrained my choice to Java, which frustrated me a bit, because the languages were so similar, why would the runtime try to restrict a choice? I enjoyed writing server applications on Unix in college, and Linux afterwards, because the machines were so easy to configure compared to Windows machines that took a few hours to install and configure to get my software running. On Linux, I could type a handful of commands into a newly installed system and be up and running.

Sometime around 2005, Java had stagnated while C# was flourishing. They both released generics, but then C# came out with new features like