Skip to content

Instantly share code, notes, and snippets.

View njlr's full-sized avatar
🌏
F# ing

njlr njlr

🌏
F# ing
View GitHub Profile
open System
open System.Globalization
let parseIsoDateTime (s : string) =
let dt = DateTime.Parse(s, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind)
assert (dt.Kind = DateTimeKind.Utc)
dt
let dt = parseIsoDateTime "2023-05-18T15:43:14.673Z"
type Circle<'t when 't : (static member Zero : 't)
and 't : (static member One : 't)
and 't : (static member (+) : 't * 't -> 't)
and 't : (static member (-) : 't * 't -> 't)
and 't : (static member (*) : 't * 't -> 't)
and 't : (static member (/) : 't * 't -> 't)
and 't : (static member (~-) : 't -> 't)
and 't : (static member op_Explicit : float -> 't) > =
{
Radius : 't
@njlr
njlr / Stateful.fs
Created August 31, 2021 20:24
State monad in F#
[<Struct>]
type Stateful<'state, 'result> =
Stateful of ('state -> 'state * 'result)
type Delayed<'state, 'result> = unit -> Stateful<'state, 'result>
module State =
let update f =
Stateful (fun state -> f state, ())
Without do-notation With do-notation
Lazy - Haskell
Strict C++ Where the Magic Happens

5 Minutes to Buck

0. What tools will I need?

🚨 This tutorial was written with Linux in mind. Windows and macOS users, please refer to Facebook's setup instructions.

You will need GCC / Clang, a text editor and Buck.

You probably have the first two, so here's how to install Buck for Linux:

  1. Open your User settings
  2. Add an language mapping from "BUCK" to "python" like so:
{
  "files.associations": {
    "BUCK": "python"
  }
}

Encapsulation in Java ☕

Today we are going to learn about encapsulation using Java!

OK! Let's write a vector class...

public class Vector2 {
    public float x;
 public float y;

Keybase proof

I hereby claim:

  • I am njlr on github.
  • I am njlr (https://keybase.io/njlr) on keybase.
  • I have a public key whose fingerprint is 8834 ACBB 3C42 089C 172B 5A1D C218 387C AD0C 52FE

To claim this, I am signing this object:

// There is an optimization opportunity when using a currying-style in JavaScript.
// For example, this...
export const and = x => y => x && !!y;
// Might become...
export const and = x => {
if (x) {
return y => !!y;
}
// try-catch style
//
// Advantages:
// 1. Familiar to OOP developers
// 2. Explicit error-handling code not required
// 3. Works well with async-await syntax
//
// Disadvantages:
// 1. Inefficient
// 2. Explicit error-handling code not required