Skip to content

Instantly share code, notes, and snippets.

View john-raymon's full-sized avatar
🔮
Building

John Raymon john-raymon

🔮
Building
View GitHub Profile
@thomashartm
thomashartm / aws-sam-colima.md
Last active September 5, 2024 12:49
Enable AWS SAM local to run without Docker Desktop but Colima + Docker Daemon on MacOs

AWS SAM local commands without Docker Desktop

AWS SAM local commands check for the existance of DOCKER_HOST. If the variable is not present, it will fail with the following error message

Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?

Replace it with Colima

Point DOCKER_HOST to unix socket of the Docker Daemon.

@dfkaye
dfkaye / k-values.js
Last active February 18, 2022 16:02
K is a null-safe, NaN-safe, primitive-safe, object key value function for generating array diffs and intersections.
// 17 feb 2022
// Answer to Jamon Holmgren's challenge tweet
// https://twitter.com/jamonholmgren/status/1494385356925390853
// K is a null-safe, NaN-safe, primitive-safe, object key value function for
// generating array diffs and intersections.
// Changelog:
// Started with reduce, then filter/includes, then saw Jamon's follow-up tweet regarding
const fs = require("fs");
// "4\n1\n2\n5\n3"
const input = fs.readFileSync(0).toString();
// [4, 1, 2, 5, 3]
const lines = input.split("\n").map((n) => parseInt(n, 10));
const T = parseInt(lines[0], 10);
@pratikagashe
pratikagashe / timezoneConvert.js
Created May 4, 2020 10:07
Converting the Date into different time zone with DST check
const d = new Date()
// convert to msec since Jan 1 1970
const localTime = d.getTime()
// obtain local UTC offset and convert to msec
const localOffset = d.getTimezoneOffset() * 60 * 1000
// obtain UTC time in msec
const utcTime = localTime + localOffset
@vkarpov15
vkarpov15 / socketreporter.js
Created June 29, 2019 15:57
Example of reporting on progress using an async generator function and websockets
const WebSocket = require('ws');
// Core solver logic, stubbed out for example
async function* slow() {
yield 'starting...';
await new Promise(resolve => setTimeout(resolve, 10 * 1000));
// Use `yield` to report on progress
yield 'loading data...';
await new Promise(resolve => setTimeout(resolve, 10 * 1000));
@nataliemarleny
nataliemarleny / sizeOfStringInUrl.sh
Created April 7, 2019 11:50
Script to evaluate the percentage of the size of a pattern in the JavaScript files of a given url
#!/usr/bin/env bash
set -eu -o pipefail
# Script expects these binaries to be present:
# - wget
# - node
# Tested on Mac.
# Example:
#
# bash sizeOfStringInUrl.sh nextjs.org "\bcreateElement\b"
@joeytwiddle
joeytwiddle / async-await-forEach-alternatives.md
Last active September 18, 2024 22:40
Do not use forEach with async-await

Do not use forEach with async-await

TLDR: Use for...of instead of forEach() in asynchronous code.

For legacy browsers, use for...i or [].reduce()

To execute the promises in parallel, use Promise.all([].map(...))

The problem

@jofftiquez
jofftiquez / mock-http.js
Last active February 27, 2024 02:23
Mock HTTP request in javascript using promise and timeout.
const mock = (success, timeout = 1000) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if(success) {
resolve();
} else {
reject({message: 'Error'});
}
}, timeout);
});
@lukasvan3l
lukasvan3l / rendercard.js
Created April 17, 2017 06:33
Fabric.js + Opentype.js for pixelperfect valentine cards
const canvas = fabric.createCanvasForNode(width, height);
canvas.contextCache.constructor.prototype.getFontSize = function getFontSize() {
return 1 * this.font.split('-')[1];
};
canvas.contextCache.constructor.prototype.getFontFamily = function getFontFamily() {
return this.font.split('-')[0]
};
@hackjutsu
hackjutsu / upstream.md
Last active December 11, 2023 07:44
[set upstream] What does '--set-upstream' do? #tags: git
git branch --set-upstream-to <remote-branch>
# example
git branch --set-upstream-to origin feature-branch

# show up which remote branch a local branch is tracking
git branch -vv

sets the default remote branch for the current local branch.