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
@miladvafaeifard
miladvafaeifard / fp-either-monad.js
Created September 21, 2023 16:51 — forked from mrosata/fp-either-monad.js
Functional JavaScript Monad Classes - (Maybe Just Nothing) - (Either Left Right) (IOMonad) and my type checking utils
import is from './is-util';
/**
* Either Monad class (from Functional Programming in JavaScript)
*/
class Either {
constructor(value) {
this._value = value;
}
get value () {
@miladvafaeifard
miladvafaeifard / app.hs
Created September 16, 2023 13:46
My first HasKell learning
main :: IO ()
main = do
print(map doubleIt [1, 2, 3])
doubleIt :: Int -> Int
doubleIt x = x * 2
@miladvafaeifard
miladvafaeifard / enumberator-yield.md
Created August 31, 2023 21:31
Enumerator with the "yield" keyword in C#

In C#, an Enumerator with the "yield" keyword is used to create an iterator method that simplifies the process of iterating over a collection of elements. The "yield" keyword allows you to define an iterator method by repeatedly yielding (returning) individual elements from the collection without explicitly creating an entire collection in memory. This approach is particularly useful for large or dynamically generated data sets, as it improves efficiency and memory usage.

By using "yield," you can create a custom iterator method that produces values one at a time, on-demand, while abstracting away the complexity of managing an explicit enumerator. This results in cleaner and more readable code for iterating through collections or sequences.

using System;
using System.Linq;
using System.Collections.Generic;

public class Program
In bash shell scripting, the if statement supports the following options for testing conditions:
-a: Tests if a file exists.
-b: Tests if a file exists and is a block special file.
-c: Tests if a file exists and is a character special file.
-d: Tests if a file exists and is a directory.
-e: Tests if a file exists (same as -a).
-f: Tests if a file exists and is a regular file.
-g: Tests if a file has its setgid bit set.
-h: Tests if a file is a symbolic link (same as -L).
@miladvafaeifard
miladvafaeifard / transform-uppercase-request.js
Created October 31, 2022 22:22
transform uppercase in request
import http from "node:http";
import fs from "node:fs";
import { Transform } from "node:stream";
function upperCaseTransform() {
return new Transform({
transform(chunk, encoding, next) {
this.push(chunk.toString().toUpperCase());
next();
},
@miladvafaeifard
miladvafaeifard / generator-random-min-max.js
Created June 27, 2022 21:09
Generator a random in between min and max
function generateRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
@miladvafaeifard
miladvafaeifard / gist:da77f2433d2c4134753404f5c66e30c6
Created December 28, 2021 21:42
How to install Java JDK Java Development Kit on mac.
How to install Java JDK Java Development Kit on mac.
In Mac OS or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home, just export $JAVA_HOME in file ~/. bash_profile or ~/.profile.
Find out where is JDK 14.
$ /usr/libexec/java_home -v14
/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home
$ vim .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
@miladvafaeifard
miladvafaeifard / phcopy
Created November 9, 2021 21:44
clipboard on ubuntu
# touch phcopy then mv this file to /usr/local/bin with chmod -R 755
clip.exe
@miladvafaeifard
miladvafaeifard / helpers.js
Created November 8, 2021 22:07
How to cancel an HTTP request in Node.js
import fetch from 'node-fetch';
import { setTimeout } from "node:timers/promises";
const cancelRequest = new AbortController();
const cancelTimeout = new AbortController();
export async function timeout(delay) {
try {
await setTimeout(delay, undefined, { signal: cancelTimeout.signal });
cancelRequest.abort();
@miladvafaeifard
miladvafaeifard / node_instal.sh
Created October 22, 2021 09:13
install node on wsl
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
echo 'export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.profile
source ~/.profile
nvm -v