Skip to content

Instantly share code, notes, and snippets.

import { interval, Observable } from 'rxjs';
import { map, withLatestFrom } from 'rxjs/operators';
function addOne(n: number): number {
return (n + 1);
}
function toOdd(n: number): number {
return ((n * 2) + 1);
}
@yeswell
yeswell / sudo-nvm.sh
Created December 10, 2021 15:43
Apply NVM version of Node, NPM and NPX to /usr/bin for use 'sudo node'
SUDO_NVM__ROOT_DIR="/usr/bin"
function forbidsudonvm() {
if [[ "$#" -eq 0 ]]
then
forbidsudonvm node
forbidsudonvm npm
forbidsudonvm npx
return 0
@yeswell
yeswell / frogToRock.js
Created October 1, 2020 20:01
Placing the Mth frog on one of the N rocks. For N = (2**n) - 1.
function getRock(M, N) {
const number = 2 ** Math.floor(Math.log2(M));
const distance = Math.floor(1 + (N / number));
const shift = (1 / 2);
const index = M % number;
return (distance * (shift + index));
}
@yeswell
yeswell / package.json
Last active September 22, 2020 21:53
Empty package.json
{
"name": "",
"version": "",
"description": "",
"keywords": "",
"license": "",
"author": "",
"contibutors": "",
@yeswell
yeswell / symb.js
Created September 20, 2020 19:14
Symbol extension with description and variable data (for Node.js and all browsers)
function Symb(description = null, data = null) {
function state(data = null) {
state.data = data;
return state;
}
state.toString = () => {
return `Symb(${state.description}, ${state.data})`;
};
@yeswell
yeswell / arabic_to_roman.js
Created May 25, 2020 01:28
Convert number from Arabic system to Roman system
function to_roman(num)
{
const roman_digits = ['I', 'V', 'X', 'L', 'C', 'D', 'M'];
const count = Math.trunc(roman_digits.length / 2);
let den = Math.pow(10, count);
let dig = Math.trunc(num / den);
let roman_number = '';
@yeswell
yeswell / extend-proxy.js
Created May 19, 2020 23:39
A way to extend Proxy in JavaScript
class ExtendProxy {
constructor() {
const target = { /* ... */ };
const handler = { /* ... */ };
const proxy = new Proxy(target, handler);
Reflect.setPrototypeOf(proxy, ExtendProxy.prototype);
return proxy;
}
}
@yeswell
yeswell / archived.md
Last active May 17, 2020 19:32
Badge for README.md in archived repositories

⚠️ Archived. Now you can find the code here.


#include <iostream>
#include <fstream>
#include <string>
using namespace std;
function A(b, c) {
let callCounter = 0;
let cacheCounter = 0;
let cache = [];
const ackermann = (m, n) => {
callCounter += 1;
if (!cache[m]) {
cache[m] = [];
}