Skip to content

Instantly share code, notes, and snippets.

View JestVA's full-sized avatar
YANK

Dorin Dumitrascuta JestVA

YANK
View GitHub Profile
@nolanlawson
nolanlawson / protips.js
Last active August 22, 2024 14:19
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
@gaearon
gaearon / slim-redux.js
Last active May 5, 2024 15:14
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
@luciopaiva
luciopaiva / _Full-socketio-client-and-server-example.md
Last active August 20, 2024 05:17
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:

@jevakallio
jevakallio / readme.md
Last active July 18, 2022 11:02
React SSR, SSG, SPA - History & Colour

SSR History & Colour

  • Three React approaches
    • SPA Single Page Applications
    • SSR Server Side Rendering
    • SSG Static Site Generation

    • SPA - Single Page Applications :: fat client, API
      • Send plain javascript that does on everything on client
      • SEO nightmare
  • Google Crawler is starting to execute JavaScript
public static boolean isElementPresentSorted(int[] m, int elem) {
// BINARY SEARCH
int first = 0, last = m.length - 1;
while (first <= last) {
int middle = first + (last - first) / 2;
if (m[middle] == elem) {
return true;
} else if (m[middle] < elem) {
first = middle + 1;
} else {