Skip to content

Instantly share code, notes, and snippets.

@runarorama
runarorama / day1.markdown
Last active December 8, 2019 12:42
Advent of Code (Unison Edition), day 1

Advent of Code 2019, in Unison

Spoilers for Advent of Code 2019 follow.

Day 1: The Tyranny of the Rocket Equation

Fuel required to launch a given module is based on its mass. Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2.

This describes a simple function. There seems to be an oversight in the problem statement that modules with very low mass have a negative fuel requirement. I'm going to assume that's not right, and that instead of integer subtraction, we want natural number subtraction (sometimes called "monus"). In Unison, we can use the Nat type instead of integers, so we don't have to consider negatives. The subtraction operation is called drop:

@ntreu14
ntreu14 / NonEmpty.fs
Last active November 15, 2019 18:21
Implementation of `NonEmpty` in F# with `map`, `concat` and `bind`.
type 'a NonEmpty = NonEmpty of 'a * 'a list
let inline (&|) head tail = NonEmpty (head, tail)
let inline (|&|) head = NonEmpty (head, [])
let toList = function NonEmpty (head, xs) -> head :: xs
let mapNonEmpty f = function
NonEmpty (head, xs) -> NonEmpty (f head, List.map f xs)
let bindNonEmpty (f: 'a -> 'b NonEmpty) = function
@CodyReichert
CodyReichert / react-es6-flow-emacs-configuration.md
Last active May 13, 2024 07:35
Configuring Emacs for react, es6, and flow

Configuring Emacs for react, es6, and flow

For a while, JSX and new es6 syntax had flaky support in emacs, but there's been huge work on a lot of packages. Using emacs for JavaScript with React, ES6, and Flow (or Typescript, etc) is really easy and powerful in Emacs these days.

This is how you can work on modern web development projects with full support for tooling like JSX, Flow types, live eslint errors, automatic prettier.js formatting, and more.

Set up web-mode

web-mode provides most of the underlying functionality, so a huge shout-out to the maintainer(s) there.

@rauchg
rauchg / README.md
Last active January 6, 2024 07:19
require-from-twitter
@mjgpy3
mjgpy3 / pattern-matching.js
Created March 7, 2016 18:25
Easy pattern matching in JavaScript
'use strict';
const buildMatcher = (cases) => (actual) =>
cases
.find((cse) => cse.matches(actual))
.result(actual);
const buildNextOn = (previousCases) => {
var build = (matchesPred, result) => {
const cases = previousCases.concat(
@naosim
naosim / Optional.js
Last active April 4, 2016 18:54
javascriptでOptional
var Optional = (value) => {
var isNull = value === null || value === undefined;
return {
filter:(action) => (isNull || !action(value)) ? Optional() : Optional(value),
map:(action) => isNull ? Optional() : Optional(action(value)),
isPresent:() => !isNull,
ifPresent:(action) => {
if(!isNull) action(value);
},
get:() => isNull ? null : value,
@mkanchwala
mkanchwala / Kafka MultiNode - MultiBroker Cluster.md
Last active July 2, 2022 10:44
Create Kafka Multi Node, Multi Broker Cluster
@jamessdixon
jamessdixon / gist:bffa8b1c2c3dc806dc41
Created December 17, 2014 11:13
DocumentDB walk-through using F#
#r "../packages/Microsoft.Azure.Documents.Client.0.9.1-preview/lib/net40/Microsoft.Azure.Documents.Client.dll"
#r "../packages/Newtonsoft.Json.4.5.11/lib/net40/Newtonsoft.Json.dll"
open System
open Microsoft.Azure.Documents
open Microsoft.Azure.Documents.Client
open Microsoft.Azure.Documents.Linq
let endpointUrl = "yourEndpoint"
@siliconbrain
siliconbrain / Either.cs
Last active May 8, 2018 03:03
Implemetation of Haskell's Either type in C#
/// <summary>
/// Interface definition of Either
/// </summary>
/// <typeparam name="Tl">type of the Left value</typeparam>
/// <typeparam name="Tr">type of the Right value</typeparam>
public interface IEither<out Tl, out Tr>
{
/// <summary>
/// Check the type of the value held and invoke the matching handler function
/// </summary>
@theburningmonk
theburningmonk / gist:1188378
Created September 2, 2011 10:57
Nancy self-hosting example
// a simple module to be hosted in the console app
public class MainModule : NancyModule
{
public MainModule()
{
Get["/"] = x => { return "Hello World"; };
}
}
static void Main(string[] args)