Skip to content

Instantly share code, notes, and snippets.

@denmerc
denmerc / postgres-cheatsheet.md
Created August 28, 2018 18:40 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@denmerc
denmerc / PaketDependencyManagementMadeEasy.fsx
Created June 10, 2018 17:29 — forked from realvictorprm/PaketDependencyManagementMadeEasy.fsx
A must have for your script file to ease spreading a small proof of concept with dependencies!
open System
open System.IO
open System.Diagnostics
let downloadDependencies deps =
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
if not (File.Exists "paket.exe") then
async {
let url = "http://fsprojects.github.io/Paket/stable"
@denmerc
denmerc / WebApp.fs
Created May 25, 2018 04:21 — forked from ane/WebApp.fs
Simple DTO passing in F# using Suave.
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
open Suave
open Suave.Json
open Suave.Types
open Suave.Types.Methods
open Suave.Utils
open Suave.Http
open Suave.Http.Authentication
open Suave.Http.Writers
@denmerc
denmerc / asyncWorkflow.fs
Last active March 6, 2018 04:10 — forked from mausch/gist:3188428
Async exception handling in F#
open System
open System.Net
// exception handling in async using Async.Catch
let fetchAsync (name, url:string) =
async {
let uri = new System.Uri(url)
let webClient = new WebClient()
let! html = Async.Catch (webClient.AsyncDownloadString(uri))
match html with
@denmerc
denmerc / Dockerfile
Created January 12, 2018 20:06 — forked from lenadroid/Dockerfile
Example F# Job template for Kubernetes
FROM fsharp
COPY . .
RUN mono ./.paket/paket.bootstrapper.exe
RUN mono ./.paket/paket.exe restore
RUN mono .paket/paket.exe install
@denmerc
denmerc / exampleElastic.fsx
Created August 18, 2017 16:57 — forked from MartinBodocky/exampleElastic.fsx
ElasticSearch and F#
#r "../packages/Elasticsearch.Net.2.0.4/lib/net46/Elasticsearch.Net.dll"
#r "../packages/NEST.2.0.4/lib/net46/Nest.dll"
#r "../packages/Newtonsoft.Json.8.0.2/lib/net45/Newtonsoft.Json.dll"
open System
open System.Linq
open Nest
module Utils =
open Microsoft.FSharp.Quotations
@denmerc
denmerc / elasticsearch.fsx
Created August 17, 2017 05:19 — forked from mjul/elasticsearch.fsx
Elasticsearch in F# example
// paket add nuget NEST
#I "../../packages"
#r "Elasticsearch.Net/lib/net46/Elasticsearch.Net.dll"
#r "NEST/lib/net46/Nest.dll"
open System
//open Elasticsearch.Net
open Nest
@denmerc
denmerc / Dapper.fs
Created July 16, 2017 00:32 — forked from vbfox/Dapper.fs
Minimal dapper in F#
module DapperFSharp =
open System.Data.SqlClient
open System.Dynamic
open System.Collections.Generic
open Dapper
let dapperQuery<'Result> (query:string) (connection:SqlConnection) =
connection.Query<'Result>(query)
let dapperParametrizedQuery<'Result> (query:string) (param:obj) (connection:SqlConnection) : 'Result seq =
@denmerc
denmerc / redis-complete.fs
Created July 15, 2017 21:55 — forked from mlusiak/redis-complete.fs
Putting it all together - get data, save to redis, read back, chart
#if INTERACTIVE
#r "bin/Debug/FSharp.Data.dll"
#r "bin/Debug/FSharp.Charting.dll"
#r "bin/Debug/ServiceStack.Common.dll"
#r "bin/Debug/ServiceStack.Interfaces.dll"
#r "bin/Debug/ServiceStack.Text.dll"
#r "bin/Debug/ServiceStack.Redis.dll"
#load "../packages/FSharp.Charting.0.90.5/FSharp.Charting.fsx"
#endif
open System.IO
@denmerc
denmerc / WebSocketServer.fs
Created January 9, 2017 18:58 — forked from AndrewNewcomb/WebSocketServer.fs
OLD from 2010 ... Updated example of using F# MailboxProcessor against an HTML5 WebSocket (in Google Chrome)
// Example of using F# MailboxProcessor against an HTML5 WebSocket (in Google Chrome)
// taken from http://v2matveev.blogspot.com/2010/04/mailboxprocessors-practical-application.html
// and then modified to work with the revised WebSocket protocol that includes a set of challenge bytes.
// The main changes are in the handshake function.
// Have a look at the http://nugget.codeplex.com for example WebSocket code in C#, on which I based the
// challenge processing code.
open System
open System.IO
open System.Linq