Skip to content

Instantly share code, notes, and snippets.

View farskid's full-sized avatar
🎯
Focusing

Farzad Yousefzadeh farskid

🎯
Focusing
View GitHub Profile
@farskid
farskid / parse_dotenv.bash
Created August 19, 2019 08:45 — forked from judy2k/parse_dotenv.bash
Parse a .env (dotenv) file directly using BASH
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)
@farskid
farskid / machine.js
Last active September 12, 2019 14:44
HSLZone logic using Finite state machines and Reactive statecharts
const zoneMachine = Machine(
{
id: "zoneMachine",
initial: "preparing",
context: { error: undefined, zone: undefined },
states: {
preparing: {
invoke: {
src: "detectLocationSupport",
id: "detectLocationSupport",
@farskid
farskid / .bashrc
Last active February 25, 2021 11:18
Mac settings and extensions (Read `Notes.md` before using any of files)
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
function fuzzy_open() {
code $(fd $1)
}
@farskid
farskid / machine.js
Last active November 1, 2019 19:06
Modeling Netflix login form using statecharts
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
function validatePassword(password) {
return password.length >= 5 && password.length < 60;
}
@farskid
farskid / machine.js
Created November 2, 2019 08:48
Generated by XState Viz: https://xstate.js.org/viz, single input model
Machine({
initial: "ready",
context: {
value: ""
},
states: {
updating: {
entry: "updateInputValue",
on: {
'': [
@farskid
farskid / index.js
Last active November 15, 2019 09:33
Speaking statecharts
const statechart2 = {
id: "zoneMachine",
initial: "preparing",
context: {
error: undefined,
zone: undefined
},
states: {
preparing: {
invoke: {
@farskid
farskid / bash.sh
Created January 11, 2020 17:32
Watch Youtube videos while working, on Mac OS, in Pic-on-Pic mode
npx ytdl --print-url [YTB_URL] | npx open-pip-cli
@farskid
farskid / listVariables.js
Created January 17, 2020 15:03
List all global variables (custom props added to window object)
const iframeEl = document.createElement('iframe');
document.body.appendChild(iframeEl);
console.log(Object.keys(window).filter(key => !(key in iframeEl.contentWindow)));
@farskid
farskid / index.txt
Last active February 4, 2020 13:16
Useful git tips, aliases and configs
# Set upstream automatically on `git push`
`git config --global push.default current`
## The reference to the last branch is saved into `-` in git.
# Checkout to the previous branch
`git checkout -`
# Merge into the last branch
`git merge -`
@farskid
farskid / quick-argument-parser.js
Created March 16, 2020 11:13 — forked from binoculars/quick-argument-parser.js
Node.js quick CLI arguments parser for key-value pair arguments
/**
* Takes arguments in the form of --arg-name value and puts them into an object (argMap).
* Argument keys begin with double hyphens and additional hyphens are converted to camelCase.
*
* E.g. `node quick-argument-parser.js --test-arg1 'value1' --test-arg2 'value2'` will create argMap with the value:
* ```
* {
* testArg1: 'value1',
* testArg2: 'value2'
* }