Skip to content

Instantly share code, notes, and snippets.

View haf's full-sized avatar
💹
currently succeeding...

Henrik Feldt haf

💹
currently succeeding...
View GitHub Profile
@haf
haf / index.html
Created May 20, 2017 12:14
Say whhhhaat? (With command-injection vulnerability included! But still awesome!)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Say something</title>
</head>
<body>
<form action="/" method="POST">
<fieldset for="to-say">
To say:
@haf
haf / LoggerEx.fs
Created April 28, 2017 20:12
Extensions for Logary's Facade logger for Hopac
module LoggerExtensions
open Hopac
/// Extensions to the Expecto logger for Hopac.
type Expecto.Logging.Logger with
/// Log Verbose with backpressure as a job
member x.verboseWithBPJ factory =
x.verboseWithBP factory |> Job.fromAsync
/// Log Debug with backpressure as a job
@haf
haf / DU-name.fs
Last active April 25, 2017 16:43
Question about finding the name of the case?
type DU =
| ACaseName
| BThereCake
let magic (q: Quotation<_>): string =
// smallest F# code in here?
open Expecto
let subject = magic <@ ACaseName @>
Expect.equal subject "ACaseName" "Should extract the NAME of the DU case"
@haf
haf / ThreadSafeDictionary.fs
Last active April 3, 2018 20:11
ThreadSafeDictionary with selective choice in Hopac
open Hopac
open Hopac.Infixes
/// A thread safe dictionary supports multiple-readers', multiple-writers'
/// access to a normal .Net dictionary.
type ThreadSafeDictionary<'K, 'V> =
private {
tryAddCh: Ch<'K * (unit -> 'V) * Ch<'V> * Promise<unit>>
tryAddSelectCh: Ch<'K * (unit -> 'V) * ('V -> obj) * Ch<obj> * Promise<unit>>
tryRemoveCh: Ch<'K * Ch<'V option> * Promise<unit>>
@haf
haf / Start.fs
Created March 11, 2017 20:40
Async start of Suave w/ Logary and Hopac
let startPublicWebApi s (logary : LogManager) esConn : Job<IAsyncDisposable> =
let webApi = createPublicWebApi s esConn
let cts = new CancellationTokenSource()
let webConfig =
{ defaultConfig with
cancellationToken = cts.Token
bindings = [ HttpBinding.createSimple HTTP "0.0.0.0" s.listenPort ]
}
LogaryFacadeAdapter.initialise<Suave.Logging.Logger> logary
@haf
haf / gist:ef50a926eb7506115b70ba7a7c10c3c6
Created February 17, 2017 23:09
PDFSharp OS X font resolver
module PDFSharp.OSX
open PdfSharp
open PdfSharp.Fonts
open PdfSharp.Pdf
open PdfSharp.Drawing
open System
open System.Drawing
open System.Drawing.Text
open System.Globalization
@haf
haf / consul-cluster.md
Created February 10, 2017 16:02
Getting a broken consul cluster up

Consul: 0.7.2

You may have crashed your cluster so that all Consul servers have been offline at some point. You may be running on Kubernetes. The default 96 hours didn't pass, so there was no reaping of Consul servers. Restarting it all doesn't work. You've read this issue five times over and nothing works. On top of it all, which makes it harder, you're running a StatefulSet on Kubernetes, so you need to do kubectl delete pods/consul-1 to make the container arguments (kubectl replace consul/consul.yml) bite. On top of this, if you kubectl exec -it consul-1 and then kill -9 5, Kubernetes goes into a crash loop with exponential backoff, eating into your time.

Sounds like a Friday pleasure, right?

The tools you have at your disposal are:

  • -bootstrap
  • kubectl replace consul/consul.yml
@haf
haf / gist:ed9adfbadade14ca86fa9683bfdc7d49
Created October 19, 2016 17:04
Shownotes redux/react
# What's redux?
- state + action -> reducer -> store -> connect (utils)(component) -> render
- reducers are scoped to action types
## redux's connect function
Responsible for mapping { state, dispatch } to props as first curried parameter. Second curried parameter is the component.
=> export default connect(mS, mD)(Comp);
@haf
haf / Find ip
Last active September 5, 2016 16:08
Make your OS X firewall mess with connections to js.stripe.com to test your async JavaScript
dig js.stripe.com