Skip to content

Instantly share code, notes, and snippets.

@jozsefs
jozsefs / get-imdb-episodes-score.js
Last active September 30, 2022 17:57
Get imdb episodes score
// house of the dragon (use it on imdb.com from console)
fetch('https://www.imdb.com/title/tt11198330/episodes?season=1').then(r => r.text()).then(text => {
const html = document.createRange().createContextualFragment(text);
const episodes = [...html.querySelectorAll('.ipl-rating-star.small .ipl-rating-star__rating')].map((node, ep) => ({ep: ep + 1, rating: +node.innerHTML}));
console.log(JSON.stringify(episodes, null, 2));
})
@jozsefs
jozsefs / count-eslint-errors.js
Last active June 10, 2021 12:14
eslint collect errors warnings counted
// copy eslint output here replace ` to ' before copying to avoid js error
str = ``;
str.split(/\n/)
// get rules from the lines containing warning or error
.map(t => {
const match = t.match(/^\s+(\d+\:\d+).+\s+([0-9@_\/\-a-zA-Z]+)$/);
return match && match[2];
})
@jozsefs
jozsefs / etoro-portfolio-json-export.js
Created January 3, 2020 20:02
etoro portfolio json export
const data = [...document.querySelectorAll('.ui-table-row')].map(row => ({
market: row.querySelector('.table-first-name').innerText,
units: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-units]').innerText.split('\n')[0].replace(/,/g, ''),
avgOpen: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-open-rate]').innerText,
invested: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-invested]').innerText.slice(1).replace(/,/g, ''),
pl$: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-container-profit]').innerText.replace(/[<,$]/g, ''),
plPercent: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-gain]').innerText.replace(/[<,%]/g, ''),
value: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-equity]').innerText.replace(/[<,$]/g, '')
}));
@jozsefs
jozsefs / formatDuration.js
Last active March 16, 2018 09:21
formatDuration.js
const LABELS = ['year', 'day', 'hour', 'minute', 'second'];
function formatDuration (seconds) {
if (seconds === 0) return 'now';
let minutes = seconds / 60 >> 0;
let hours = minutes > 59 ? minutes / 60 >> 0 : 0;
let days = hours > 23 ? hours / 24 >> 0 : 0;
const years = days > 364 ? days / 365 >> 0 : 0
@jozsefs
jozsefs / duolingo-how-many-lessons-left.js
Created March 10, 2018 21:13
duolingo-how-many-lessons-left.js
$$('._2TMjc').map(item => item.innerText).reduce((acc, next) => acc + +next.match(/\/(\d*)/)[1], 0)
@jozsefs
jozsefs / molecules-to-atoms.js
Last active July 19, 2019 07:53
molecules-to-atoms.js
// codewars exercise
const str = 'As2{Be4C5[BCo3(CO2)3]2}4Cu5';
function parseMolecule(formula) {
const BRACKET_OPENER_REGEXP = /\[|\{|\(/;
const BRACKET_CLOSER_REGEXP = /\]|\}|\)/;
const VALID_ATOM_REGEXP = /^[A-Z][a-z]?$/;
const MULTIPLIER_REGEXP = /^\d+/;
function createGroup(parent = {}) {
@jozsefs
jozsefs / multi-minesweeper-server.js
Created November 24, 2017 12:47
multi-minesweeper-server
// server.js
const io = require('socket.io')(1234);
const Board = require('./board');
const game = new Board({size: 15, mineChance: 0.3});
const PLAYER_PREFIX = 'p-';
const players = {};
const cellsToReveal = [];
let counter = 0;
@jozsefs
jozsefs / iter.js
Created October 20, 2017 18:11 — forked from ForbesLindesay/iter.js
Push iterator
const Queue = require('then-queue'); // async queue that doesn't care what order you call push and pop.
const queue = new Queue();
// push sends to the first waiting `pop` if available, otherwise it acts as a buffer
listenToNewMessages(message => queue.push(message));
async function* MessagesGenerator() {
try {
while (true) {
@jozsefs
jozsefs / unique.js
Created October 6, 2017 09:18
find unique number in array with pairs present
[1,2,2,1,3,3,4,5,5,0,0,6,7,6,7].reduce((acc, next) => acc ^ next, 0);
@jozsefs
jozsefs / search.sh
Created October 1, 2017 15:41
grep awk search csv
head -1000 some.csv | awk -F";" '{print $1}' | grep keyword