Skip to content

Instantly share code, notes, and snippets.

View yhafri's full-sized avatar

Younès HAFRI yhafri

  • Switzerland
View GitHub Profile
@yhafri
yhafri / lazy-load-puppeteer.js
Created May 14, 2020 11:17 — forked from schnerd/lazy-load-puppeteer.js
Lazy-loading content in Puppeteer
function wait (ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms));
}
export default async function capture(browser, url) {
// Load the specified page
const page = await browser.newPage();
await page.goto(url, {waitUntil: 'load'});
// Get the height of the rendered page
@yhafri
yhafri / ss.erl
Created April 19, 2020 22:35 — forked from jadeallenx/ss.erl
Self Stabilizing Systems in Spite of Distributed Control
%% @doc
%% This Erlang module implements the ideas illustrated in Edsger Dijkstra's
%% famous paper "Self Stabilizing Systems in Spite of Distributed Control"
%% http://courses.csail.mit.edu/6.852/05/papers/p643-Dijkstra.pdf
%% @end
-module(ss).
-export([stop/1, show/1, start/1]).
-define(DELAY, 1000).
-define(THRESHOLD, 0.90).
@yhafri
yhafri / discussion.md
Created April 19, 2020 22:34 — forked from jadeallenx/discussion.md
When does terminate/2 get called in a gen_server?

When does terminate/2 get called in a gen_server?

This is what the [official documentation][1] says about the terminate/2 callback for a gen_server:

This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.

Reason is a term denoting the stop reason and State is the internal state of the gen_server.

Reason depends on why the gen_server is terminating. If it is because another callback function has returned a stop tuple {stop,..}, Reason will have the value specified in that tuple. If it is due to a failure, Reason is the error reason.

@yhafri
yhafri / gist:250bed1966eb3771bbdbd4c3f5d3d47e
Created April 14, 2020 23:28 — forked from zliuva/gist:1084476
A minimal Mach-o x64 executable for OS X
; A minimal Mach-o x64 executable for OS X (also see below Mountain Lion version)
;
; $ nasm -f bin -o tiny_hello tiny_hello.s
; $ chmod +x tiny_hello
; $ ./tiny_hello
; Hello World!
; $
; c.f.
; http://osxbook.com/blog/2009/03/15/crafting-a-tiny-mach-o-executable/ ( the original tiny mach-o executable )