Skip to content

Instantly share code, notes, and snippets.

View luciopaiva's full-sized avatar
🐌
I may be slow to respond

Lucio Paiva luciopaiva

🐌
I may be slow to respond
View GitHub Profile
@luciopaiva
luciopaiva / example.js
Last active May 4, 2018 01:39
Javascript: range() and range2d()
// will print numbers from 0 to 19
for (const x of range(20)) {
console.info(x);
}
// will print
// 0 0
// 1 0
// 0 1
// 1 1
@luciopaiva
luciopaiva / .banner
Last active May 7, 2018 16:03
Helpful bash additions
_ _
| | (_)
| |_ _ ___ _ ___
| | | | |/ __| |/ _ \
| | |_| | (__| | (_) |
|_|\__,_|\___|_|\___/
@luciopaiva
luciopaiva / _Full-socketio-client-and-server-example.md
Last active April 27, 2024 04:09
Full socket.io client and server example

Full socket.io client and server example

Last updated: 2021-02-21, tested with socket.io v3.1.1

This is the simplest implementation you will find for a client/server WebSockets architecture using socket.io.

To see a full explanation, read my answer on SO here: https://stackoverflow.com/a/24232050/778272.

If you're looking for examples using frameworks, check these links:

@luciopaiva
luciopaiva / index.css
Last active May 3, 2021 07:08
Read/write CSS variable in Javascript
:root {
--app-width: 1000px;
--some-calculation: calc(var(--app-width) + 1);
}
@luciopaiva
luciopaiva / wait-for-dom-content-loaded.js
Last active July 24, 2017 02:50
Javascript snippet to asynchronously detect when DOM is loaded
class SampleApp() {
constructor () {
this.pageLoadingPromise = null;
}
waitForDomContentLoaded() {
if (!this.pageLoadingPromise) {
// this is the first time; prepare the promise
this.pageLoadingPromise = new Promise(resolve => {
@luciopaiva
luciopaiva / Storing data in HTML elements.md
Last active June 3, 2017 23:46
Storing data in HTML elements

See this jsPerf test.

The most performant way to store data related to a certain element is to use a Map. Besides being the fastest, it also allows you to store arbitraty data. Using dataset and data-* attributes only allow for string values.