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 / 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 / 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 / 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 / gist:ab650aa03f3492946af86b1b3f1b6b2f
Created December 4, 2018 17:56
Persian text definitions
# زمان
حالا - اکنون - هنوز - همیشه - وقتی - قبلا - بعدا - سرانجام - اغلب - روزانه - در پایان - در نهایت - در خاتمه - ابتدا - گاه - بلافاصله - اخیرا - اخیراً
# تکرار
دوباره - باز - برای اولین بار - بارها
# مقدار
بیشتر - خیلی - تا حدی - بسیار - کم
@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"];