Skip to content

Instantly share code, notes, and snippets.

View d0peCode's full-sized avatar
🎯
Focusing

Borys Tymiński d0peCode

🎯
Focusing
  • Warsaw
View GitHub Profile
class charactersCounter {
constructor(input) {
this.inputArr = input.split('');
this.availableLetters = [...new Set(this.inputArr)];
this.mostPopular = {
letter: '',
amount: 0
}
}
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
setTimeout(() => console.log('1200ms elapsed'), 1200);
const foo = () => {
let intervalId;
const intervalFunction = async() => {
clearInterval(intervalId); //clear so it will not execute again after 100ms
console.log('interval executed');
await sleep(120); //some long action
const sleep = require('./utilities/sleep');
const mySetInterval = (callback, ms, ...args) => {
let token = {
cancelled: false
};
let id = setInterval((...args) => {
callback(token, ...args);
}, ms, ...args);
return function cancel() {
const getPixels = require("get-pixels");
//1px only black https://i.imgur.com/dStJ1Og.png
//2px only black https://i.imgur.com/5z46WVp.png
//88x62px only black https://i.imgur.com/ZtGMUh9.png
//88x62px black and red https://i.imgur.com/67IZCaD.png
//220x297px black and red https://i.imgur.com/KTNnJGF.jpg
function check(uintArr) {
let r = uintArr[0], g = uintArr[1], b = uintArr[2], a = uintArr[3];
for (let i = 0, l = uintArr.length; i < l; i += 4) {
const getPixels = require("get-pixels");
//1px only black https://i.imgur.com/dStJ1Og.png
//2px only black https://i.imgur.com/5z46WVp.png
//88x62px only black https://i.imgur.com/ZtGMUh9.png
//88x62px black and red https://i.imgur.com/67IZCaD.png
//220x297px black and red https://i.imgur.com/KTNnJGF.jpg
//3000x4000px black with red dot(1px) https://i.imgur.com/JiHtQuR.jpg
getPixels("https://i.imgur.com/JiHtQuR.jpg", function(err, ndarray) {
...
"plugins": [
[
"@electron-forge/plugin-webpack",
{
"mainConfig": "./webpack.main.config.js",
"renderer": {
"config": "./webpack.renderer.config.js",
"entryPoints": [
{
// #bluebird, #bluebird-retry, #bluebird-cancellation, #eventBus
const Promise = require('bluebird');
const retry = require('bluebird-retry');
const eventBus = require('js-event-bus')();
Promise.config({warnings: true, longStackTraces: true, cancellation: true, monitoring: true});
//promise child function
const child = () => {
return new Promise((resolve, reject, onCancel) => {
@d0peCode
d0peCode / await-promise-cancel.js
Last active June 4, 2019 15:04
It's node API with /test route. In order to run it you need to get both files, install package.json dependiecies and run cURL / Postman request GET to localhost:5000/test
// this is simple 1 file 1 route app;
// #bluebird, #bluebird-retry, #bluebird-cancellation, #eventBus
// use bluebird retry for 4s; after 1.5s through eventBus invoke bluebird-cancellation which should stop bluebird-retry as well
const express = require('express');
const app = express();
const path = require('path');
const bodyParser = require('body-parser');
app.use(bodyParser.json());
// this is simple 1 file 1 route,
// app with cancellation of promise with bluebird library
//
// canellation of promise which have interval also stopping interval with onCancel
const express = require('express');
const app = express();
const path = require('path');
const bodyParser = require('body-parser');
const Promise = require('bluebird');
'use strict'
const chalk = require('chalk')
const electron = require('electron')
const path = require('path')
const { say } = require('cfonts')
const { spawn } = require('child_process')
const webpack = require('webpack')
const WebpackDevServer = require('webpack-dev-server')
const webpackHotMiddleware = require('webpack-hot-middleware')