Skip to content

Instantly share code, notes, and snippets.

View filippomangione's full-sized avatar

Filippo Mangione filippomangione

  • Boolean Careers
  • Milano
View GitHub Profile

Cheat sheet: Arrays

JavaScript Arrays are a very flexible data structure and used as lists, stacks, queues, tuples (e.g. pairs), etc. Some

Using Arrays

Creating Arrays, reading and writing elements:

@vinzdef
vinzdef / index.js
Created August 6, 2019 11:18
Fork Process in Cluster
const server = require('./server.js')
const numCPUs = require('os').cpus().length
const cluster = require('cluster')
function makeCluster() {
return new Promise((resolve, reject) => {
if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++) {
cluster.fork()
}
@eneko
eneko / list-of-curl-options.txt
Last active April 25, 2024 12:21
List of `curl` options
$ curl --help
Usage: curl [options...] <url>
--abstract-unix-socket <path> Connect via abstract Unix domain socket
--alt-svc <file name> Enable alt-svc with this cache file
--anyauth Pick any authentication method
-a, --append Append to target file when uploading
--basic Use HTTP Basic Authentication
--cacert <file> CA certificate to verify peer against
--capath <dir> CA directory to verify peer against
-E, --cert <certificate[:password]> Client certificate file and password
@sandeepraju
sandeepraju / ttfb.sh
Created July 20, 2016 21:17
curl command to check the time to first byte
#!/bin/bash
# file: ttfb.sh
# curl command to check the time to first byte
# ** usage **
# 1. ./ttfb.sh "https://google.com"
# 2. seq 10 | xargs -Iz ./ttfb.sh "https://google.com"
curl -o /dev/null \
-H 'Cache-Control: no-cache' \
-s \
@lastguest
lastguest / asyncLoadCSS.js
Created October 8, 2015 10:53
[JavaScript] asyncLoadCSS
function asyncLoadCSS (css_href) {
var css_link = function () {
var h = document.getElementsByTagName('head')[0]
var l = document.createElement('link')
l.rel = 'stylesheet'
l.href = css_href
h.parentNode.insertBefore(l, h)
}, RAF = requestAnimationFrame || mozRequestAnimationFrame
|| webkitRequestAnimationFrame || msRequestAnimationFrame
if (RAF) RAF(css_link); else window.addEventListener('load', css_link)
@paulirish
paulirish / what-forces-layout.md
Last active April 27, 2024 23:37
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
@kopiro
kopiro / youtube-nginx.conf
Created April 30, 2015 14:55
Youtube Thumb server with NGINX
server {
server_name youtube.flerovio.dev;
location @404 {
return 302 /sq$request_uri;
}
error_page 404 = @404;
location ~ /sq/(.+) {
@sebmarkbage
sebmarkbage / Enhance.js
Last active January 31, 2024 18:33
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@ericelliott
ericelliott / essential-javascript-links.md
Last active April 22, 2024 10:15
Essential JavaScript Links
@kopiro
kopiro / cookie-fast.html
Last active August 29, 2015 14:11
Cookie in a fast way