Skip to content

Instantly share code, notes, and snippets.

View dzek69's full-sized avatar
💭
Doing stuff.

Jacek Nowacki dzek69

💭
Doing stuff.
View GitHub Profile
@dzek69
dzek69 / gist:6f02ca65e1a2ae2b798faa47fe71621d
Created March 18, 2021 11:34
Save / restore all localStorage
const save = () => JSON.stringify(Object.keys(localStorage).reduce((acc, curr) => { acc[curr] = localStorage.getItem(curr); return acc; }, {}));
// Usage in console:
copy(save());
// new console
o = CTRL+V
restore(o);
const clean = () => { Object.keys(localStorage).forEach(k => localStorage.removeItem(k)); return true };
When building an adnroid app, you might stumble upon this error:
`Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE...`. Here's how to fix it:
That's because the app you're trying to test was already installed on the device and the signatures are different now, so it's complaining. The full error will look like something like this:
`Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.example signatures do not match the previously installed version; ignoring!`
You can see that the package ID is `com.example`, well, simply run this command:
new Promise((resolve) => {
console.log("inside");
resolve()
}).then(() => { console.log("then") });
console.log("outside");
const u = (item) => {
console.log(isNaN(item.name) === false);
console.log(item.name !== item.name);
}
@dzek69
dzek69 / promise.js
Created July 16, 2017 19:41
promise test
const log = (text) => {
if (text instanceof Error) {
text = "ERROR: " + text.message;
}
document.querySelector("#log").textContent += "\n" + JSON.stringify(text, null, 4);
}
const randomTime = () => Math.round(Math.random() * 1000);
const notNull = item => item !== null;
@dzek69
dzek69 / index-clock.js
Created July 16, 2017 18:55
Clock items
const React = require("react");
const { render } = require("react-dom");
const root = document.querySelector("#r");
// const log = (text) => {
// document.querySelector("#log").textContent += "\n" + text;
// }
// const heavyCalc = () => {
@dzek69
dzek69 / index.js
Last active July 16, 2017 18:18
React keys
const React = require("react");
const { render } = require("react-dom");
const root = document.querySelector("#r");
const itemA = {
key: "A",
name: "Item A",
};
const itemB = {
@dzek69
dzek69 / spread.js
Created February 10, 2017 23:24
equally spreads number into array with n integer elements, equally filling unevens
export default (number, parts) => {
if (!parts) {
return [];
}
let left = number;
const result = [];
const fullMin = Math.floor(number / parts);
var measure = function(fn, iterations, timeout) {
iterations || (iterations = 10000);
timeout || (timeout = 5000);
var i, end, total;
var timeoutMsg = "";
var start = performance.now();
for (i = 0; i < iterations; i++) {
fn();
end = performance.now();