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 / 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 )
@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 / 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 / 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 / lazy-load-puppeteer.js
Created May 14, 2020 11:18 — forked from mcspx/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 / puppeteer.js
Created May 19, 2020 20:55 — forked from rcarmo/puppeteer.js
Trying to get a single-page PDF screenshot out of puppeteer
const puppeteer = require('puppeteer');
function sleep(ms){
return new Promise(resolve=>{
setTimeout(resolve,ms)
})
}
(async() => {
@yhafri
yhafri / tsunami.MD
Created June 15, 2020 22:08 — forked from AllenEllis/tsunami.MD
Faster UDP file transfers using tsunami

I recently had to move about 3TB of video footage between residential gigabit fiber connections. The fastest speed I could get was around ~150Mbps through Dropbox and other cloud providers, so I opted for a more direct answer.

After using Resilio Sync to buffer the files onto an Ubuntu Virtual Machine, I installed Tsunami. Using this I was able to get 600Mbps with no tuning, between a server in Los Angeles to my residential connection in Pittsburgh.

tsunami

What it does:

  • Very fast file transfers because it's UDP based

What it does not:

  • Support the ability to transfer more than one file [1]
// use it like so:
// auto l = co_away LM.lock(co_await this_coro{}, resource_type, resource_id);
// auto l = co_await LM.shared_lock(resource_type, resource_id);
//
// this_coro{} is a statub; using the await_transform() facilities of promise_type{}
// facilites zero-cost access to the current coroutine handle; which is
// used for exclusive locks, e.g
/*
struct this_coro final {
//
#!/bin/bash
# This builds a self-contained archive for access to abseil containers+hashes
mkdir /tmp/BUILDYARD
cd /tmp/BUILDYARD
git clone --depth 1 https://github.com/abseil/abseil-cpp.git
cd abseil-cpp
mkdir build
cd build
cmake .. -DABSL_RUN_TESTS=ON -DABSL_USE_GOOGLETEST_HEAD=ON -DCMAKE_CXX_STANDARD=17
cmake --build . --target all
@yhafri
yhafri / Trinity intro.md
Created June 21, 2020 09:40 — forked from markpapadakis/Trinity intro.md
Trinity Intro

Trinity is a modern C++ information-retrieval library for building queries, indexing documents and other content, running queries and scoring documents matching them. It facilitates the development of search engines and other systems and applications that depend on that functionality, and has been designed with simplicity, performance, modularity, extensibility, and elegance in mind.

This is the initial release and as such, new features and API extensions may come in later releases. It has been under development for 2 weeks, and will be updated frequently with improvements, enhancements and fixes to any potential issues reported.

It's named after Trinity in the Matrix movies, and it's also about the Trinity of (query, index, search) that are the core functions supported by the library.


Trinity makes it easy to index documents and access all documents that match a query. It solves the recall problem and everything else about it, and it gives