Skip to content

Instantly share code, notes, and snippets.

View m-esm's full-sized avatar
https://calendly.com/m-esm/coffee-chat

Mohsen Esmaeili m-esm

https://calendly.com/m-esm/coffee-chat
View GitHub Profile
@m-esm
m-esm / remove-old-snaps.sh
Created March 20, 2020 23:03
Removes older versions of Snap applications
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
echo "Current usage:";
du -h /var/lib/snapd/snaps
echo "";
set -eu
snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
@m-esm
m-esm / crypto-stream.js
Created February 6, 2020 23:34 — forked from chris-rock/crypto-stream.js
Encrypt and decrypt streams
// Part of https://github.com/chris-rock/node-crypto-examples
// Nodejs encryption of buffers
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'd6F3Efeq';
var fs = require('fs');
var zlib = require('zlib');
@m-esm
m-esm / event-loop-delay-check.js
Last active January 29, 2020 19:19
Check event loop health by checking it's delay
const interval = 1000;
const acceptableDelay = 3;
let lastCheck = 0;
(function checkEventLoop() {
const now = Date.now();
if (lastCheck)
if (now - lastCheck > interval + acceptableDelay) {
console.log('\x1b[31m', 'event loop delay', (now - lastCheck - interval) + 'ms', '\x1b[0m');
@m-esm
m-esm / tmux_cheatsheet.markdown
Created September 6, 2019 15:50 — forked from henrik/tmux_cheatsheet.markdown
tmux cheatsheet

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@m-esm
m-esm / Exporting VS Code extension list.txt
Created August 12, 2019 18:32
Exporting VS Code extension list
Manual - By script
In machine A,
UNIX:
code --list-extensions | xargs -L 1 echo code --install-extension
@m-esm
m-esm / backup-gits.sh
Last active July 25, 2019 19:10
backup github repositories ( users & orgs )
main_dir=~/Desktop/github-backups
github_users=(orgs/serendip-agency users/m-esm)
echo -e "\tBackup directory:$main_dir \n\n\tAccounts to backup:"
for a in ${github_users[@]}; do echo -e "\t\t${a}"; done
echo -e "\n\t$(mkdir $main_dir 2>&1)"
cd $main_dir
for user in ${github_users[@]}; do
repos=$(curl https://api.github.com/$user/repos --silent)
for row in $(echo "${repos}" | jq -r '.[] | @base64'); do
_jq() { echo ${row} | base64 --decode | jq -r ${1}; }
@m-esm
m-esm / bash-cheatsheet.sh
Last active July 11, 2019 11:52
bash shell cheatsheet
# inline if
echo "result: $(if [ $(pgrep -c "myApplication^C -eq 1 ]; then echo "true"; else echo "false"; fi)"
@m-esm
m-esm / LimitStream.js
Created June 29, 2019 10:08 — forked from 4poc/LimitStream.js
Node.js: LimitStream (Bandwidth limited Readable+Writable Stream)
var fs = require('fs'),
util = require('util'),
Stream = require('stream').Stream;
/**
* Create a bandwidth limited stream
*
* This is a read+writeable stream that can limit how fast it
* is written onto by emitting pause and resume events to
* maintain a specified bandwidth limit, that limit can
@m-esm
m-esm / memorySizeOfObject.js
Created April 13, 2019 09:20
calculate memory size of javascript object, it is not a accurate value!
function memorySizeOf(obj) {
var bytes = 0;
function sizeOf(obj) {
if(obj !== null && obj !== undefined) {
switch(typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
@m-esm
m-esm / convert_photos_to_pdf.sh
Created March 14, 2019 01:35
convert photos in directory to single pdf file
convert "*.{png,jpeg}" -quality 100 outfile.pdf