Skip to content

Instantly share code, notes, and snippets.

View anttispitkanen's full-sized avatar
🇺🇦
Stand with Ukraine

Antti Pitkänen anttispitkanen

🇺🇦
Stand with Ukraine
View GitHub Profile
@anttispitkanen
anttispitkanen / transactions.ts
Last active October 11, 2022 14:00
Transaction stuff with knex
declare const longApiCallThatTakesUpTo30seconds: () => Promise<any>
declare const sendEmailToCustomer: () => Promise<any>
declare const logSuccess: () => Promise<any>
/**
* A silly example of moving money from one account to another. The basic use
* case with no problems.
*/
export const myTransactionalDatabaseOperation = () => {
return knex.transaction(async (trx) => {
@anttispitkanen
anttispitkanen / README.md
Last active June 30, 2023 16:40
🇺🇦 Support Ukraine HTML link banners 🇺🇦

🇺🇦 Support Ukraine HTML link banners 🇺🇦

Ukraine needs all the help we can give in fighting the Russian dictator Vladimir Putin's war. See information and resources on trusted news sources, also a short summary here: https://github.com/anttispitkanen

As someone building or maintaining a website of any kind, a simple way to help is to add a banner to show support, raise awareness, and guide visitors towards actionable help.

Here are some ready made HTML tags that you can freely use, modify according to your desire, and drop on your site. They act as a clickable banner that links to the resource of your choice.

Customizing the look

@anttispitkanen
anttispitkanen / streamTest.ts
Created November 1, 2021 21:33
Testing filtering and transforming streams in Nodejs and TypeScript
import { pipeline, Readable, Transform, Writable } from "stream";
const makeFilter = <A>(filterFn: (x: A) => boolean) => {
return new Transform({
objectMode: true,
transform: (data: A, _, done) => {
try {
const willPass = filterFn(data);
return done(null, willPass ? data : null);
} catch (ex) {
const CANARY_THRESHOLD_PERCENT = parseInt(
process.env.CANARY_THRESHOLD_PERCENT || '0',
);
/**
* This function divides the traffic between Old Data API and New Data API
* based on the runtime configuration of CANARY_THRESHOLD_PERCENT.
*/
export const handleDataRequestWithCanaryTraffic = (
requestId: string,
const SHADOW_TRAFFIC_ENABLED = process.env.SHADOW_TRAFFIC_ENABLED === 'true';
/**
* This function includes the shadow traffic "side channel" in addition to
* the "main channel".
*/
export const handleDataRequestWithShadowTraffic = (
requestId: string,
animal: TAnimal,
): Promise<TDataApiData> => {
export const handleDataRequest = (requestId: string, animal: TAnimal): Promise<TDataApiData> =>
dataApiClient.getData(requestId, animal);
@anttispitkanen
anttispitkanen / test.js
Last active May 25, 2021 09:46
What happens to the first async function (waitAndReturn) invocation?
const waitAndReturn = (ms, msg) =>
new Promise(resolve => {
setTimeout(() => {
resolve(msg);
}, ms);
});
const foo = () => {
waitAndReturn(5000, 'First').then(msg => console.log(msg));
@anttispitkanen
anttispitkanen / App.js
Created February 25, 2019 17:33
Awesome react application, wanna invest?
import React, { Component } from "react";
import "./App.css";
const names = [
"Repe",
"Pera",
"Kartsa",
"Raipe",
"Simo",
"Jussi",