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 / 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 / Main.java
Created August 14, 2017 11:15
GC scenario when producing a lot of large string buffers
public class Main {
private static String buildBigString (int numStrings) {
StringBuffer sb = new StringBuffer();
for(int i = 0; i < numStrings; i++) {
sb.append("12345678");
sb.append(",");
}
return sb.toString();
}
@ninjarobot
ninjarobot / currying.fs
Created August 11, 2017 21:19
F# currying example
let add2 num1 num2 =
num1 + num2
// The compiler will do this:
let addTwo num1 =
fun num2 ->
num1 + num2
// Both functions work the same, but the curried form accepts a single parameter and returns a function that accepts another parameter.
  • Unrecognized configuration section 'runtime' - this happens when machine.config isn't included. Use --machine-config /etc/mono/4.5/machine.config in addition to --config /etc/mono/config
  • Some libraries are under /usr/lib/mono/4.5/Facade - things like System.Threading.Task.Extensions.dll. If these are used, then be sure to include them.
@ninjarobot
ninjarobot / mkbundle-alpine-example.Dockerfile
Created June 19, 2017 17:41
A minimal Alpine image using a self-contained .NET executable built with mkbundle.
FROM alpine
RUN echo 'using System; \
namespace Program { \
public class MyClass { \
public static void Main(string[] args) { \
Console.WriteLine ("Hello from C#"); \
} \
} \
}' >> Program.cs
RUN apk add --virtual build-dependencies --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing --no-cache mono mono-dev musl-dev binutils gcc && \
@ninjarobot
ninjarobot / dotnetcore2.Dockerfile
Created May 10, 2017 12:58
Dockerfile for latest dotnetcore 2.0 runtime - based on Alpine
FROM frolvlad/alpine-glibc
RUN apk add --no-cache curl libstdc++ --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ \
&& curl -O https://dotnetcli.blob.core.windows.net/dotnet/master/Binaries/Latest/dotnet-linux-x64.latest.tar.gz \
&& mkdir -p /usr/share/dotnet \
&& tar -xzvf dotnet-linux-x64.latest.tar.gz -C /usr/share/dotnet \
&& rm dotnet-linux-x64.latest.tar.gz \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
@ninjarobot
ninjarobot / githubapi.pl
Created February 3, 2017 03:43
Retrieves some public repository information via SWI-Prolog.
:- module(githubapi, [list_repos/3]).
:- use_module(library(http/http_client)).
:- use_module(library(http/http_json)).
process_repo(J) :-
J = json(D),
format(
'~w \n\t~w \n\tlanguage: ~w \n\tclone url: ~w \n',
[D.name, D.description, D.language, D.clone_url]
# From debian, e.g. `docker run -it debian bash`
apt-get update
apt-get install -y ocaml-mingw-w64 gcc-mingw-w64
echo 'print_string "Hello world!\n";;' >> hello.ml
/usr/bin/i686-w64-mingw32-ocamlopt -o hello.exe hello.ml
UnixSignal.WaitAny ([|UnixSignal (Signum.SIGINT); UnixSignal (Signum.SIGTERM); UnixSignal (Signum.SIGQUIT)|], -1)