Skip to content

Instantly share code, notes, and snippets.

View liron-navon's full-sized avatar

Liron Navon liron-navon

  • Israel
View GitHub Profile
@liron-navon
liron-navon / code-signal-measure-tests.js
Last active October 14, 2021 08:26
Measure tests time in code signal
/**
* This script is used to run measurements on CodeSignal https://app.codesignal.com
* to use it simply open the dev tools, and paste in the console,
* it will automate the browser for you to run the tests and measure the times it took.
* be patient, there are measurements to prevent blocking from CodeSignal,
* and this script just automates the browser which means it cannot run tests in parallel
* so the tests will take a while, just run this and go grab a coffee.
*
* !!!CAUTION!!! this isn't an official script and might get you banned from CodeSignal
* even though there are measurements to try and prevent this, use caution.
@liron-navon
liron-navon / Debug an app with logcat.sh
Created July 3, 2019 10:01
how to debug a specific app with logcat
Adb shell # get into the phone's shell
> pm list packages # get the list of packages, skip if you know the package name
> pidof -s <package-name> # get the process ID of the package
> exit # exit the shell and go back to the pc shell
adb logcat --pid=<pid> # log only from a specific process ID
@liron-navon
liron-navon / yandex-translate.js
Last active January 19, 2022 23:15
A simple script to do a quick translation using yandex and cors anywhere
// if you want a demo, just throw it in the console
// it won't work in github's console since they use {"connect-src": "self"} header, you can however do it in google.com
// or almost any other website
//
// yandex translation api is free for up to 1 million characters a day 🤩
// you can set up a free key here: https://tech.yandex.com/translate/
// or just use this, since it's from a fake account it might get blocked in the near future
const KEY = 'trnsl.1.1.20190308T095934Z.95ae5cf4e28588ea.9d108fb6e768af347464925e4e98b91edb0013f5';
const FROM = 'nl'; // default source language
const TO = 'en'; // default target language
@liron-navon
liron-navon / jquery-es6.js
Last active January 27, 2019 13:26
A rebuild of JQuery with es6
// a simple utility function for normalizing return values
const returnValue = values => values.length === 1 ? values[0] : values;;
// a simple function to check existence
const exists = value => value !== undefined && value !== null;
const isString = value => typeof value === 'string';
const isArray = value => Array.isArray(value);
// This is the actual class to hold all of our classes
class ElementAbstraction {
constructor(htmlElements) {
@liron-navon
liron-navon / notification.js
Last active May 7, 2021 12:53
a simple example for a notification
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
function notify() {
new Notification("Hello world!");
}
// Let's check whether notification permissions have already been granted
@liron-navon
liron-navon / indexedb.js
Last active January 24, 2019 11:25
example of usage with indexedb
// the example:
if('indexedDB' in window) {
// open the database
openDB(window.indexedDB, 'todos-db')
// add some todos
.then(({ db }) => addTodo(db, 'my todo text 1'))
.then(({ db }) => addTodo(db, 'my todo text 2'))
// get all the todos
.then(({ db }) => getTodos(db))
.then(({ db, event }) => {
@liron-navon
liron-navon / index.js
Last active January 21, 2019 14:57
comparing node worker_threads with regular actions
const { Worker } = require("worker_threads");
const path = require("path");
const os = require("os");
const ora = require("ora");
// this is how we can get the count of cpu's the computer has,
// using a larger number may result in the app crushing
const cpuCount = os.cpus().length;
// create some big array
@liron-navon
liron-navon / sorter.js
Created January 19, 2019 14:26
Worker threads example
const { parentPort, workerData, isMainThread } = require("worker_threads");
// CPU consuming function (sorting a big array)
function sortBigArray(bigArray) {
return bigArray.sort((a, b) => a - b);
}
// check that the sorter was called as a worker thread
if (!isMainThread) {
// make sure we got an array of data
@liron-navon
liron-navon / index.js
Last active January 19, 2019 14:26
Worker threads example
const { Worker } = require("worker_threads");
const path = require("path");
// create some big array
const elements = 1000000;
const bigArray = Array(elements)
.fill()
.map(() => Math.random());
// we get the path of the script
@liron-navon
liron-navon / intercept-fetch.js
Last active January 16, 2019 10:15
A small utility to intercept fetch requests
const beforeHook = (...props) => {
console.log('before call')
return props;
};
const afterHook = (response) => {
console.log('after call')
return response;
};