Skip to content

Instantly share code, notes, and snippets.

Avatar

Raphael Rafatpanah persianturtle

View GitHub Profile
@MarcelCutts
MarcelCutts / terrible_fetch.ml
Created Sep 18, 2017
A super hacky attempt to get async fetching working on button press.
View terrible_fetch.ml
open Bs_fetch;
let sj json :list string => Json.Decode.(json |> list string);
type remoteData 'e 'a =
| NotAsked
| Loading
| Failure 'e
| Success 'a;
@busypeoples
busypeoples / PhantomTypeReasonML.md
Last active Nov 28, 2020
Phantom types in ReasonML
View PhantomTypeReasonML.md

Phantom types in ReasonML

Introduction

"A phantom type is a parametrised type whose parameters do not all appear on the right-hand side of its definition..." Haskell Wiki, PhantomType

The following write-up is intended as an introduction into using phantom types in ReasonML.

Taking a look at the above definition from the Haskell wiki, it states that phantom types are parametrised types where not all parameters appear on the right-hand side. Let's try to see if we can implement a similar example as in said wiki.

@busypeoples
busypeoples / README.md
Last active Sep 19, 2019
Making Impossible States Impossible in ReasonML
View README.md

Making Impossible States Impossible in ReasonML

Introduction

If you have already seen Richard Feldman's talk entitled "Making Impossible States Impossible" or have read "Designing with types: Making illegal states unrepresentable" then you can skip the explanations and just head straight to the Reason examples.

This post is intended to display how to model your Reason Application to prevent creating impossible states. The benefits of being able to design a feature in this way include avoiding having to deal with complex test scenarios regarding defined business rules and a clear documentation of what is possible just by looking at the type definition. Long story short, let's see how this all works by implementing an example.

Requirements

@ryan-senn
ryan-senn / LoginMsg.elm
Last active Dec 31, 2019
Update nesting
View LoginMsg.elm
module Modules.Auth.Login.Msg exposing (..)
import Http exposing (Error)
import Types exposing (User)
type LoginMsg
= LoginUpdateEmail String
| LoginUpdatePassword String
@kavitshah8
kavitshah8 / bind.js
Last active Jul 9, 2019
Frequently Asked Javascript Interview Questions
View bind.js
Function.prototype.bind1 = function (scope) {
let fn = this
let prefixArgs = Array.prototype.slice.call(arguments, 1)
return function() {
let suffixArgs = Array.prototype.slice.call(arguments)
let args = prefixArgs.concat(suffixArgs)
return fn.apply(scope, args)
}
}
@zcaceres
zcaceres / Eyeballing-This.md
Last active Jan 17, 2021
Understanding Binding and 'this' in Javascript by zach.dev
View Eyeballing-This.md

How to Eyeball Your ‘This’ Context in Javascript

by zach.dev

The early programmer struggles with the Javascript keyword this. But understanding your this context is easier than it seems.

This is all about where a function is invoked. Often, early programmers worry about where the function was declared. Perhaps the function was declared in a specific file or a particular object. Surely this changes it's this!

Nope.

View javascript-trim-svg-whitespace.js
function trimSvgWhitespace() {
// get all SVG objects in the DOM
var svgs = document.getElementsByTagName("svg");
// go through each one and add a viewbox that ensures all children are visible
for (var i=0, l=svgs.length; i<l; i++) {
var svg = svgs[i],
box = svg.getBBox(), // <- get the visual boundary required to view all children
View report-asp.net-vs-node.js-for-backend-comparison.md

Comparison of ASP.NET and Node.js for Backend Programming

We will compare ASP.NET and Node.js for backend programming.
Source codes from examples.

Updates

This document was published on 21.09.2015 for a freelance employer. Some changes since then (14.02.2016):

  1. Koa.js no longer uses co-routines, it has switched to Babel's async/await. yield and await are used almost in the same way, so I see no point to rewrite the examples.
@jaydenseric
jaydenseric / ffmpeg-web-video-guide.md
Last active Jan 24, 2021
A quick guide to using FFmpeg to create cross-device web videos.
View ffmpeg-web-video-guide.md

Video conversion with FFmpeg

Install

On mac:

  1. Download the latest release.
  2. Extract the binary and place it in /usr/local/bin.

Command basics