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 / gist:6e81b846367345da6b4f93dbeb9c4b96
Created November 9, 2018 08:14
serendip WebSocket service usage example
import {
Server,
AuthService,
WebSocketService,
WebSocketInterface,
DbService
} from "serendip";
export class DashboardService {
static dependencies = ["AuthService", "DbService", "WebSocketService"];
@m-esm
m-esm / gist:ab650aa03f3492946af86b1b3f1b6b2f
Created December 4, 2018 17:56
Persian text definitions
# زمان
حالا - اکنون - هنوز - همیشه - وقتی - قبلا - بعدا - سرانجام - اغلب - روزانه - در پایان - در نهایت - در خاتمه - ابتدا - گاه - بلافاصله - اخیرا - اخیراً
# تکرار
دوباره - باز - برای اولین بار - بارها
# مقدار
بیشتر - خیلی - تا حدی - بسیار - کم
@m-esm
m-esm / nodejs-tcp-example.js
Created February 10, 2019 16:59 — forked from tedmiston/nodejs-tcp-example.js
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@m-esm
m-esm / run.js
Created February 22, 2019 11:35
Node.js sending and receiving file using only 'http' and 'fs' module (no framework)
var http = require("http");
var fs = require("fs");
var server = http.createServer().listen(3000);
server.on("request", function(req, res) {
if (req.method != "POST") return res.end();
var imageName = "received-" + Date.now() + ".jpg";
var writeStream = fs.createWriteStream(imageName);
req.pipe(writeStream);
@m-esm
m-esm / count.sh
Last active March 14, 2019 01:01
count total lines of code in a directory - linux bash
for type in ts css html less json; do
echo "total lines of .$type files";
lines=$(( find ./ -path './*/node_modules' -prune -o -name "*.$type" -print0 | xargs -0 cat ) | wc -l);
echo "$lines";
done;
# example output:
# total lines of .ts files
# 34377
# total lines of .css files
@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
@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 / 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 / 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 / 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}; }