Skip to content

Instantly share code, notes, and snippets.

@tnguven
tnguven / convertCurrency.ts
Created April 5, 2022 12:19
Currency conversion algorithm with Depth First Search algorithm
const currencies = [
['USD', 'EUR', 0.89],
['EUR', 'CHF', 1.03],
['CAD', 'USD', 0.79],
['GBP', 'USD', 1.34],
['AUD', 'HKF', 5.68],
['GBP', 'CAD', 1.7],
['JPY', 'CAD', 0.011],
['GBP', 'JPY', 154.28],
] as [CurrencyType, CurrencyType, number][];
@tnguven
tnguven / stateMachine.js
Last active May 8, 2021 21:14
State machine
const machine = {
initial: 'inactive',
states: {
inactive: {
on: {
TOGGLE: 'active',
}
},
active: {
on: {
@tnguven
tnguven / Makefile
Created March 14, 2019 10:46
Makefile
LAUNCH_FILE="{ \"version\": \"0.2.0\", \"configurations\": [] }"
install-tooling:
sudo npm install -g selenium-standalone@6.15.3
sudo selenium-standalone install
create-launch-file:
echo ${LAUNCH_FILE} > .vscode/launch.json
setup: install-tooling create-launch-file
@tnguven
tnguven / .gitignore_global
Created January 14, 2019 09:33
Global gitignore file
# Developer
.prettierrc
.env
# Jetbrains
# User-specific stuff
.idea/
# CMake
@tnguven
tnguven / memoryUsageTemplate.js
Last active January 14, 2019 09:38
process.memoryUsage() template
const byteToMb = byte => (byte / 1024) / 1024;
const { rss, heapTotal, heapUsed, external } = process.memoryUsage()
console.log({
rss: `${byteToMb(rss)}mb`,
heapTotal: `${byteToMb(heapTotal)}mb`,
heapUsed: `${byteToMb(heapUsed)}mb`,
external: `${byteToMb(external)}mb`
})
@tnguven
tnguven / rxjs-diagrams.md
Created October 5, 2018 09:34 — forked from PCreations/rxjs-diagrams.md
Super Intuitive Interactive Diagrams to learn combining RxJS sequences by Max NgWizard K
@tnguven
tnguven / filterarray.js
Last active March 12, 2018 14:17
Array of object manipulation example
function filterByLetters(options, filter) {
if (filter) {
let data = [...options];
let restData = [...options];
const filterIsNum = parseInt(filter);
let result = [];
// filter with number
if (filterIsNum) {
const filtered = data
function letThemReduce(count) {
let bigData = [];
for (let i = 0; i < count; i++) {
bigData[i] = i;
}
console.log('Data count:', bigData.length);
// ///////////////////////////////////////////////////////////////////// FILTER MAP START HERE
console.time('map');
@tnguven
tnguven / 1-sleep-es7.js
Created May 26, 2017 13:00 — forked from danharper/1-sleep-es7.js
ES7's async/await syntax.
// ES7, async/await
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
}
(async () => {
console.log('a');
await sleep(1000);
console.log('b');
})()