Skip to content

Instantly share code, notes, and snippets.

View vsnikkil's full-sized avatar
🦜

Vesa Nikkilä vsnikkil

🦜
View GitHub Profile
@vsnikkil
vsnikkil / createReferenceNumbers.ts
Created September 2, 2021 16:23
Create reference numbers for invoicing. International or local (Finnish) RF format
export const createReferenceNumbers = (
baseStr: string = "000",
qty = 10,
international = false
): string[] => {
const baseNumber = BigInt(baseStr);
return Array.from({ length: qty }, (_value, idx) => {
const base = String(baseNumber + BigInt(idx));
const checksum: number =
// does not work on edge
((a, {b = 0, c = 3}) => { return a === 1 && b === 2 && c === 3; })(1, { b: 2 });
// works, surprisingly
((a, {b = 0, c = 3} = {}) => { return a === 1 && b === 2 && c === 3; })(1, { b: 2 });
// works
(({b = 0, c = 3}) => { return b === 2 && c === 3; })({ b: 2 });
// works
@vsnikkil
vsnikkil / immutable-tietoisku.md
Last active February 28, 2018 08:49
Immutable tietoisku

ImmutableJS

Immutable data cannot be changed once created, leading to much simpler application development, no defensive copying, and enabling advanced memoization and change detection techniques with simple logic. Persistent data presents a mutative API which does not update the data in-place, but instead always yields new updated data.

--- Immutable.js

Some concepts of functional programming

@vsnikkil
vsnikkil / try-me.js
Last active December 14, 2017 11:34
try-me
const a = (idx = 1, color = 'black') => { console.log(`%c ${ [...new Array(Math.round(50*(1+Math.sin(idx/10))))].map(() => '*').join('') }`, `color: ${color}`); setTimeout(() => a(idx+1, color), 20) }; a()
// Node
var x = idx => { console.log(''.padStart(Math.floor(process.stdout.columns / 2 * (1 + Math.sin(idx))), '*')); setTimeout(() => x((idx + 0.1) % (2 * Math.PI)), 20) }; x(0)
@vsnikkil
vsnikkil / .eslintrc.json
Created August 30, 2017 14:52
ESLint configuration
{
"env": {
"browser": true,
"node": true,
"es6": true,
"amd": true,
"jest/globals": true
},
"extends": "eslint:recommended",
"parserOptions": {
@vsnikkil
vsnikkil / gist:71b5b68124a7db56526c00105a72f7b8
Created September 11, 2016 18:34
webpack.conf.js example
const webpack = require('webpack')
module.exports = {
devtool: process.env.NODE_ENV === 'production' ? 'cheap-module-source-map' : 'eval',
module: {
loaders: [
{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel',
@vsnikkil
vsnikkil / Associations.js
Created May 2, 2016 20:43
Sequelize snippets
import User from './User'
import Session from './Session'
/* Associations */
User.hasMany(Session)
/* Hooks */
User.afterDestroy(async (user, options) => {
await Session.destroy({
where: { userId: user.id },