Skip to content

Instantly share code, notes, and snippets.

View francoisromain's full-sized avatar

François Romain francoisromain

View GitHub Profile
@joshwyatt
joshwyatt / how_to_make_a_script.md
Last active May 29, 2024 05:24
How to make scripts you can access globally from the terminal

How to make a globally available executable script in the scripting language of your choice

  • Locate the path to the interpreter for the language you are writing in with the which command.

      which node
      which python
      which bash
      which ruby
    
  • Add that path as an interpreter directive (using #!) on the first line of your script. For example if you want to write a node script and which node returned /usr/local/bin/node, the first line of your script should be:

@rrag
rrag / README.md
Last active March 19, 2024 16:11
Yet another tutorial and Cheat sheet to Functional programming

There are many tutorials and articles available online which explain functional programming. Examples show small functions, which are composed into others which again get composed. It is hard to imagine how it would all work, then come the analogies and then the math. While the math is necessary to understand it can be difficult to grasp initially. The analogies on the other hand, (at least for me) are not relatable. Some articles assume the reader knows the different terminologies of FP. Over all I felt it is not inviting to learn.

This introduction is for those who have had a tough time understanding those analogies, taken the plunge to functional programming but still have not been able to swim. This is yet another tutorial on functional programming

Terminology

Functions as first class citizens

Functions are first class means they are just like anyone else, or rather they are not special, they behave the same as say primitives or strings or objects.

@paulirish
paulirish / what-forces-layout.md
Last active June 11, 2024 07:58
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
function xyz_to_ρ (x, y, z) {
return Math.sqrt((x * x) + (y * y) + (z * z));
}
function zρ_to_θ (z, ρ) {
return Math.acos(z / ρ);
}
function yx_to_φ (y, x) {
return Math.atan(y / x);
@bastman
bastman / docker-cleanup-resources.md
Created March 31, 2016 05:55
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@artemgurzhii
artemgurzhii / EventEmitter.js
Last active February 26, 2019 15:21
Event Emitter
class EventEmitter {
constructor() {
this.events = {};
}
on(event, func) {
if(this.events[event]) {
this.events[event].push(func);
} else {
this.events[event] = [func];
@Rich-Harris
Rich-Harris / geojson.md
Last active May 6, 2024 05:08
A better GeoJSON

A better GeoJSON

GeoJSON is a widely-used format for encoding geographic data. It's flexible and human-readable, and because it's just JSON it's easy to integrate into web applications.

But it has some real warts, and if we wanted to we could certainly come up with a better format. After tweeting about my frustrations, I was asked to elaborate. Here goes:

Redundancy

GeoJSON geometries can be one of seven types: Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon and GeometryCollection.

<?php
$index = $_GET['data'];
//accessing database
$database = Array (
"SP500"=>2128.19,
"DOW"=>18150.44,
"NASDAQ"=>5194.41
@sixertoy
sixertoy / README.md
Last active April 23, 2023 22:35
ES6 Tips & Tricks

JavaScript Tips

Yarn/NPM

Reorder package.json

npx sort-package-json

Array

@wesbos
wesbos / async-await.js
Created February 22, 2017 14:02
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}