Skip to content

Instantly share code, notes, and snippets.

View farskid's full-sized avatar
🎯
Focusing

Farzad Yousefzadeh farskid

🎯
Focusing
View GitHub Profile
@farskid
farskid / concurrent.js
Last active May 21, 2019 19:11
Concurrent, Parallel and Sequential operations using Javascript Promise.
async function concurrent() {
const fetchA = A.fetch();
const fetchB = B.fetch();
const responseA = await fetchA;
const responseB = await fetchB;
return {a: responseA, b: responseB};
}
@farskid
farskid / readme.md
Created November 27, 2018 11:02 — forked from dominictarr/readme.md
statement on event-stream compromise

Hey everyone - this is not just a one off thing, there are likely to be many other modules in your dependency trees that are now a burden to their authors. I didn't create this code for altruistic motivations, I created it for fun. I was learning, and learning is fun. I gave it away because it was easy to do so, and because sharing helps learning too. I think most of the small modules on npm were created for reasons like this. However, that was a long time ago. I've since moved on from this module and moved on from that thing too and in the process of moving on from that as well. I've written way better modules than this, the internet just hasn't fully caught up.

@broros

otherwise why would he hand over a popular package to a stranger?

If it's not fun anymore, you get literally nothing from maintaining a popular package.

One time, I was working as a dishwasher in a restu

@farskid
farskid / pdf-viewer.js
Created November 22, 2018 12:39
PDF reader in javascript
async function pdfViewer(pdfSrc) {
let blob = await fetch(pdfSrc);
blob = fetched.blob();
const url = URL.createObjectURL(blob);
return <object data={url} type="application/pdf"></object>
}
const os = require("os");
// install this custom module!!
const babar = require("babar");
function calculateFreeMemPercentage() {
return Number(((os.freemem * 100) / os.totalmem).toFixed(2));
}
function printChart(points) {
console.log(
@farskid
farskid / create_github_tag.sh
Created October 16, 2018 03:49 — forked from cliffparnitzky/create_github_tag.sh
Simple way to create a tag via git shell and push it to repo
# creat a tag (more infos at: http://git-scm.com/book/de/ch2-12.html)
git tag -a 1.0.0 -m "Version 1.0.0"
git push origin 1.0.0
git tag -a 1.0.0.alpha1 -m "Version 1.0.0 alpha1"
git push origin 1.0.0.alpha1
# delete a tag
git tag -d 1.0.0
git push origin :refs/tags/1.0.0
@farskid
farskid / memoize.js
Created July 5, 2018 12:30
Memoize functions in Javascript
function memoize(fn) {
let cache = {};
function memoizedFunc (...args) {
const hash = JSON.stringify(args);
if (cahce.hasOwnProperty(hash)) {
return cache[hash];
}
@farskid
farskid / sort.js
Created January 29, 2018 22:41
Sort object keys alphabetically
function sortObjKeysAlphabetically(obj) {
return Object.keys(obj).sort((a,b) => a > b).reduce((result, key) => {
result[key] = obj[key];
return result;
}, {});
}
@farskid
farskid / by-iframe.js
Created January 16, 2018 20:39
Find out global variables added by scripts on a website
/*
Method1: Create an iframe and compare it's window object with website's window
*/
const iframe = document.createElement('iframe');
document.body.append(iframe);
const virgin = Object.keys(iframe.contentWindow);
const current = Object.keys(window);
const added = current.filter(key => !virgin.includes(key));
@farskid
farskid / anagram.js
Created December 24, 2017 03:25
Number of deletions needed to make two random strings, anagrams of each other in Javascript
function anagrams(a, b) {
var freqA = charFreq(a);
var freqB = charFreq(b);
var deletions = 0;
getChars().forEach(char => {
deletions += Math.max(freqA[char], freqB[char]) - Math.min(freqA[char], freqB[char]);
});
return deletions;