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
@ninjarobot
ninjarobot / Using_postgres_from_FSharp_with_driver.fs
Created September 26, 2017 13:50
Run a query against PostgreSQL with F# using the Npgsql driver
async {
use conn = new NpgsqlConnection (connectionString)
use cmd = conn.CreateCommand (CommandText="SELECT field1, field5 FROM some_table WHERE foo=:bar")
cmd.Parameters.AddWithValue ("bar", "baz) |> ignore
do! conn.OpenAsync () |> Async.AwaitTask // Automatically closed when disposed
use! reader = cmd.ExecuteReaderAsync() |> Async.AwaitTask
// Need a function to iterate through results
let rec readData results = async {
let! hasRecord = reader.ReadAsync () |> Async.AwaitTask
match hasRecord with
@ninjarobot
ninjarobot / regular_cleanup.sh
Created November 6, 2017 16:22
Clean up Ubuntu periodically
#!/bin/bash
sudo apt-get clean # removes cached packages
sudo apt autoremove --purge # removes old kernels
@ninjarobot
ninjarobot / LoadFromDynamicallyCompiledModule.fs
Created February 5, 2018 18:40
Example reading data from a dynamically compiled module.
// Works from .NET Core (netcoreapp2.0), just add nuget package FSharp.Compiler.Service
open System
open System.IO
open Microsoft.FSharp.Compiler.SourceCodeServices
let nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), ".nuget")
let systemRuntimePath = Path.Combine(nugetPath, "packages/System.Runtime/4.3.0/ref/netstandard1.5/System.Runtime.dll")
[<EntryPoint>]
@ninjarobot
ninjarobot / dotnet_sdk2_dev_env.sh
Last active April 11, 2018 03:10
Script to install a .NET Core 2.0 development environment with Mono as needed for Ionide.
# Sets up a development environment for Ubuntu 16.04.
sudo apt-get install -y curl
# Microsoft source
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
@ninjarobot
ninjarobot / pgsql_cidr_examples.md
Last active April 17, 2018 01:18
Examples of using the cidr type from Postgres
-- Increment addresses, with increment of octet
select inet '192.168.0.1' + 256;

-- Increment addresses starting with a network
select cidr '192.168.100.128/25' + 256;

-- Get a cidr network address from shorthand
select cidr '10.1.2';
@ninjarobot
ninjarobot / Suave-Logary.fs
Created May 2, 2018 12:04
Sample usage of Logary with Suave from @haf
type TraceLogger(name, minLevel) =
let logWithAck level fac =
if level < minLevel then async.Return () else
async {
let m = fac level
match m.value, level with
| Event event, _ when level >= LogLevel.Error ->
System.Diagnostics.Trace.TraceError(event, [||])
| Event event, _ when level = LogLevel.Warn ->
@ninjarobot
ninjarobot / paket-mkbundled-install.log
Last active May 8, 2018 17:07
Attempting a paket install with mkbundled paket
Paket version 5.156.7
found: /src/suaveapp/paket.dependencies
Parsing /src/suaveapp/paket.dependencies
Resolving packages for group Main:
0 packages in resolution.
1 requirements left
- Suave, 2.2.1 (from /src/suaveapp/paket.dependencies)
Trying to resolve Suave 2.2.1 (from /src/suaveapp/paket.dependencies)
Performance:
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 / 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].