Skip to content

Instantly share code, notes, and snippets.

@Kmaschta
Kmaschta / retry.ts
Created October 22, 2024 09:12
Retry function in TypeScript
type Options = {
maxRetries?: number; // Maximum amount of retries before raising the error (default: 3)
silent?: boolean; // Minimize the error as warning when retrying the function (default: true)
wait?: number; // Wait time before each retry in milliseconds (default: 500ms)
exponentialBackoff?: boolean; // Wait longer every time we retry (default: false)
randomize?: boolean; // Wait a random amount of time before retrying, maximum double of the given time (default: null)
};
const waitMs = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
const getRandomInt = (max: number) => Math.floor(Math.random() * max);
@Kmaschta
Kmaschta / keybase.md
Created January 15, 2021 11:22
Keybase Proof

Keybase proof

I hereby claim:

  • I am kmaschta on github.
  • I am kmaschta (https://keybase.io/kmaschta) on keybase.
  • I have a public key ASCZaN5SJpgXVcd7XuqosiSCH_kN_xMilDHnwFZ4isGu6wo

To claim this, I am signing this object:

@Kmaschta
Kmaschta / Parse-International-Days.js
Created April 29, 2019 11:44
Parse International Days
// https://www.journee-mondiale.com/les-journees-mondiales.htm
(() => {
const links = {};
const articles = document.querySelectorAll('article');
articles.forEach((article, monthIndex) => {
const items = article.querySelectorAll('li');
items.forEach((li) => {
@Kmaschta
Kmaschta / generate-self-signed-certificate-with-custom-CA.md
Created January 9, 2019 14:43
How to generate a self-signed that is valid for your browser (by creating your custom certificate authority)

If you're using self-signed certificate for your web server on development, you might know the browser warning saying that your certificate isn't valid. If like me you had manually added an exception for this certificate error each time it showed up, this gist is for you.

Properly Configure OpenSSL with your DNS aliases

You'll have to create a self-signed certificate with a custom SubjectAltName.

  1. Find your openssl config. find /usr/lib -name openssl.cnf
### Keybase proof
I hereby claim:
* I am kmaschta on github.
* I am kmaschta (https://keybase.io/kmaschta) on keybase.
* I have a public key ASAvkWIvIk1a3VcepH9b0Rl9_wd2ECc7UaHwaUDbLtBuIwo
To claim this, I am signing this object:
@Kmaschta
Kmaschta / index.js
Created March 6, 2018 07:11
Apollo Memory Debug
require('isomorphic-fetch');
const express = require('express');
const { makeExecutableSchema } = require('graphql-tools');
const graphqlHTTP = require('express-graphql');
const books = [
{ title: "Harry Potter and the Sorcerer's stone", author: "J.K. Rowling" },
{ title: "Jurassic Park", author: "Michael Crichton" },
];
@Kmaschta
Kmaschta / index.js
Created February 12, 2018 12:48
Express-Winston Benchmark
const express = require('express');
const winston = require('winston');
const expressWinston = require('./express-winston');
const app = express();
const consoleFormatter = ({ level, meta: { req, res, responseTime, stack } }) => {
let msg = `${winston.config.colorize(level, level)} HTTP ${req.method} ${req.url}`;
if (res) {
@Kmaschta
Kmaschta / Makefile
Created December 12, 2017 16:49
Artifact deployment example
.PHONY: build
TAG ?=
SERVER ?= staging-server
install:
npm install
start:
node --require reify server.js
@Kmaschta
Kmaschta / setup-tests.js
Created October 27, 2017 09:40
Prevent unhandled Promise rejection errors
// Warn from unhandled promise rejection that can occurs without failing tests
// jest --setupFiles setup-tests.js
process.on('unhandledRejection', (error, promise) => {
console.error('Unhandled Rejection at:', promise, `\n${error.stack}`);
});
@Kmaschta
Kmaschta / wakatime_stats.py
Created May 5, 2017 15:21
Retrieve a maximum of Wakatime stat
#!/usr/bin/python
help = """Retrieve all the stats from WakaTime API
Usage:
wakatime_stats.py <token>
Options:
-h --help Show this very help message
See https://wakatime.com/developers