Skip to content

Instantly share code, notes, and snippets.

View miladvafaeifard's full-sized avatar
🤟
always looking simple solutions

Milad Vafaeifard miladvafaeifard

🤟
always looking simple solutions
View GitHub Profile
#!/bin/bash
# --------------------------------
<< 'user-option-prompting'
while getopts "s:e:w:" option; do
case "${option}" in
w) WS=${OPTARG};;
s) SUBSCRIPTION=${OPTARG};;
e) EXCLUDE=${OPTARG};;
@miladvafaeifard
miladvafaeifard / index.mjs
Created December 7, 2020 22:03
nodejs Zip pipeline
import * as fs from 'fs';
import * as zlib from 'zlib';
const file = process.argv[2]; // node index.mjs <file>
fs.createReadStream(file)
.pipe(zlib.createGzip())
.on('data', () => process.stdout.write('.'))
.pipe(fs.createWriteStream('fileZipped.gz'))
.on('finish', () => console.log('done'));
@miladvafaeifard
miladvafaeifard / nodejs-transform.mjs
Created December 7, 2020 21:45
Transform streams in Nodejs system
import { Transform } from 'stream';
const upperCaseTransform = new Transform({
transform(chunk, encoding, next) {
this.push(chunk.toString().toUpperCase());
next();
}
});
process.stdin.pipe(upperCaseTransform).pipe(process.stdout);
@miladvafaeifard
miladvafaeifard / index.html
Last active December 22, 2019 22:48
Exercises: funtional programming, RamdaJs lib,
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="https://frontendmasters.com/assets/resources/functionaljs/pointfree.browser.js"></script>
<script src="https://frontendmasters.com/assets/resources/functionaljs/data.maybe.umd.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.8.0/ramda.min.js"></script>
</head>
@miladvafaeifard
miladvafaeifard / tsconfig.ts
Created October 9, 2019 09:49
typescript config for Angular
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
@miladvafaeifard
miladvafaeifard / generatorFun.ts
Created August 28, 2019 12:39
auto increment in generator fun and setInterval
const appDiv: HTMLElement = document.getElementById('app');
function* autoIncrement(){
let num = 0;
while (num < 11) {
yield num++;
}
}
@miladvafaeifard
miladvafaeifard / TS-Proptypes.tsx
Last active August 24, 2019 19:50
Typescript referring React proptypes
import * as React from "react";
import { render } from "react-dom";
import * as PropTypes from "prop-types";
const userPropTypes = {
name: PropTypes.string.isRequired,
className: PropTypes.string
};
const userDefaultProps = {
@miladvafaeifard
miladvafaeifard / skipping-requests.js
Created June 3, 2019 09:17
Skipping requests in rxjs and Angular, if we enter a white-space, the request gets made again requests run as soon as the model gets changed if the user types something before the request has finished, the request keeps running
import {
debounceTime,
distinctUntilChanged, filter,
map,
switchMap
} from 'rxjs/operators';
//...
this.searchResult$ = this.queries$.pipe(
map((query: string) => query ? query.trim() : ''),
import { Component, OnInit, QueryList, ViewChildren, ElementRef} from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
@ViewChildren('foo') list: QueryList<ElementRef>;
@miladvafaeifard
miladvafaeifard / uranus_compose_functional_programming.js
Last active February 12, 2019 15:53
compose and pipe functionalities
const uranus = {};
const trace = label => value => {
console.log(`${ label }: $ { value }`);
return value;
}
Object.defineProperty(uranus, 'compose', {
value: (...fns) => value => fns.reduceRight((g,f) => f(g), value),
configurable: false