Skip to content

Instantly share code, notes, and snippets.

View dbrack's full-sized avatar

Dominik Brack dbrack

View GitHub Profile
#To install:
#
#In your git configuration (for instance, .git/config to do it at the project level), add:
#
#[merge "json_merge"]
# name = A custom merge driver for json files
# driver = coffee json_merge.coffee %O %A %B
# recursive = binary
#
#In your project's .gitattributes file, add something like:
@tejacques
tejacques / HOCBaseRender.tsx
Last active May 2, 2022 13:05
React Higher Order Components in TypeScript
import * as React from 'react';
import { Component } from 'react';
export default function HOCBaseRender<Props, State, ComponentState>(
Comp: new() => Component<Props & State, ComponentState>) {
return class HOCBase extends Component<Props, State> {
render() {
return <Comp {...this.props} {...this.state}/>;
}
}
@baumandm
baumandm / GIF-Screencast-OSX.md
Last active November 3, 2023 07:18 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to Animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime and ffmpeg.

Forked from https://gist.github.com/dergachev/4627207. Updated to use a palette to improve quality and skip gifsicle.

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@dbrack
dbrack / functor-definition.md
Last active July 19, 2017 13:26
Functors and higher order functions - definition

objects that implement map are functors. So, Array is a functor, and Array.filter is a higher order function

abstract

a functor is an object which acts as a container for a value, which then allows you to APPLY one or more functions to that value, and returns a new functor (in case of .map(), an Array) containing the transformed value.

See also here

// Demo: converting a thenable to a Promise
const fulfilledThenable = {
then(reaction) {
reaction('hello');
}
};
const promise = Promise.resolve(fulfilledThenable);
console.log(promise instanceof Promise); // true
promise.then(x => console.log(x)); // hello
@VictorTaelin
VictorTaelin / promise_monad.md
Last active May 10, 2024 04:22
async/await is just the do-notation of the Promise monad

async/await is just the do-notation of the Promise monad

CertSimple just wrote a blog post arguing ES2017's async/await was the best thing to happen with JavaScript. I wholeheartedly agree.

In short, one of the (few?) good things about JavaScript used to be how well it handled asynchronous requests. This was mostly thanks to its Scheme-inherited implementation of functions and closures. That, though, was also one of its worst faults, because it led to the "callback hell", an seemingly unavoidable pattern that made highly asynchronous JS code almost unreadable. Many solutions attempted to solve that, but most failed. Promises almost did it, but failed too. Finally, async/await is here and, combined with Promises, it solves the problem for good. On this post, I'll explain why that is the case and trace a link between promises, async/await, the do-notation and monads.

First, let's illustrate the 3 styles by implementing

dialog {
position: fixed;
top: 50%;
left: 50%;
right: auto;
padding: 30px;
transform: perspective(500px) translate(-50%, -50%);
background: linear-gradient(to bottom, #FFF, #F4F4F4) #FFF;
border: none;
border-radius: 3px;
#!/bin/sh
BOLD=$(tput BOLD)
NORMAL=$(tput sgr0)
RED='\033[0;31m'
LOCAL_SETTINGS_BASE=~/Library/Application\ Support/Code
LOCAL_SETTINGS="${LOCAL_SETTINGS_BASE}/User"
REMOTE_SETTINGS=~/Google\ Drive/App\ Sync/vscode/Settings
@swissmanu
swissmanu / functional.js
Last active December 7, 2017 14:55
Array juggling in JavaScript with functional programming approach
// precondition: xs is always an array
function head(xs) {
if (xs.length === 0) return null
return xs[0]
}
function tail(xs) {
return xs.slice(1)
}
@swissmanu
swissmanu / eventually.ts
Last active February 15, 2018 08:23
Typed eventually construct using TypeScript and Promises
// Example Usage:
eventually(20)(() => fetch('http://i.fail.often.com/data.json'))
.then(data => console.log(data))
.catch(e => console.log(e));
function eventually<T>(
giveUpAfterNumberOfRetries: number,
nextInterval: (numberOfRetries: number) => number = linearRetryInterval
) {