Skip to content

Instantly share code, notes, and snippets.

function buttonListener(event) {
console.log(this + ' clicked!');
console.log('this === currentTarget:', this === event.currentTarget);
console.log('this === target:', this === event.currentTarget);
}
const button = document.querySelector('#btn');
button.addEventListener('click', buttonListener);
@kaminski-tomasz
kaminski-tomasz / corona-cases.js
Created February 1, 2021 22:42
Node.js script that downloads COVID cases for all countries (confirmed/deaths/recovered) and transforms it to tabular form.
const superagent = require("superagent");
const ExcelJS = require('exceljs');
const CORONA_API = 'https://coronavirus-tracker-api.herokuapp.com';
/**
* @typedef {{
* id: number,
* name: string,
* }} Country

Rozdział 0 - Wprowadzenie

Połączenie z MongoDB (z kursu):

mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/aggregations?replicaSet=Cluster0-shard-0" \
    --authenticationDatabase admin \
    --ssl -u m121 -p aggregations --norc
@kaminski-tomasz
kaminski-tomasz / genetic-algorithm.js
Created October 17, 2021 20:22
Simple Genetic Algorithm in JavaScript
import { maxBy, minBy, sumBy } from "lodash-es";
export const Random = {
/** @returns {number} */
getRandom() {
return Math.random();
},
/**
* The maximum is exclusive and the minimum is inclusive
*
@kaminski-tomasz
kaminski-tomasz / genetic-algorithm.ts
Last active August 9, 2022 11:27
Genetic algorithm in TypeScript with linear fitness scaling; example problem solved is maximization of f(x) = x^10
/* Random utilities */
export class Random {
static getRandom() {
return Math.random();
}
static getRandomInt(min: number, max: number) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
@kaminski-tomasz
kaminski-tomasz / variations.spec.js
Created December 3, 2021 07:57
Implement iterative version of recursive algorithm using stack.
import {differenceWith, isEqual} from "lodash";
export type BitArray = (0 | 1)[];
/**
* Your task is to implement iterative version of recursive algorithm
* that generates all binary numbers (called "variations" here)
* in the form (0 | 1)[] for given length, but which aren't starting
* with given `ignoredPattern` (see FIXME below).
*
@kaminski-tomasz
kaminski-tomasz / counter.c
Created April 26, 2022 20:30
Arduino code for digital counter device with 4-digit 7-segment display
#define SEG_C 4
#define SEG_E 21
#define SEG_D 20
#define SEG_B 0
#define SEG_G 3
#define SEG_A 2
#define SEG_F 1
#define DISP_4 19
#define DISP_3 18