Skip to content

Instantly share code, notes, and snippets.

@aminmarashi
aminmarashi / cost-of-semis.ts
Last active January 15, 2023 11:06
Calculate how much money are you spending annually on semicolons
/**
* what's the average typing speed characters per minute? 200
* Assuming the average code length is about 80 characters
* That means developers will type `;` three times in a minute
* Let's calculate the time spent on typing semicolons per minute
*/
const timeSpentSemiPerMin = 3 / 200
/**
* Software developers get paid on average USD 120K in the US
@aminmarashi
aminmarashi / worker.js
Last active February 17, 2022 09:58
fruitionsite.js
const PAGE_TO_SLUG = {};
const slugs = [];
const pages = [];
Object.keys(SLUG_TO_PAGE).forEach(slug => {
const page = SLUG_TO_PAGE[slug];
slugs.push(slug);
pages.push(page);
PAGE_TO_SLUG[page] = slug;
});
@aminmarashi
aminmarashi / docker_ecs.sh
Created November 25, 2021 07:42
Manually apply docker ECS up with cloudformation templates
#!/bin/bash
if [ -z $2 ]; then
echo "Usage: $0 [up|down] [stack name]"
exit 1
fi
if [ $1 == 'up' ]; then
aws cloudformation create-stack --stack-name $2 --capabilities=CAPABILITY_IAM --template-body file://<(docker compose convert)
elif [ $1 == 'down' ]; then
aws cloudformation delete-stack --stack-name $2
else
@aminmarashi
aminmarashi / say.sh
Last active April 28, 2021 03:12
Read whatever is copied to clipboard (text-to-speech or tts) using nothing but cvlc and curl
#!/bin/bash
## Needs cvlc and curl installed
if ! (which cvlc >/dev/null && which curl >/dev/null); then
echo 'Please make sure cvlc and curl are installed and added to the execution path'
exit 1;
fi
say() {
echo "$@" | tr . "\n" | tr \; "\n" | tr : "\n" | tr , "\n" | \
@aminmarashi
aminmarashi / download-slack-emojis.js
Created April 28, 2021 02:46
Download custom Slack emojis
/*
* Go to: https://[your workspace].slack.com/customize/emoji
* And open console, then paste the code:
* The loop will stop once it reaches the end of list of emojis
* then it prints the object containing the emojis, you can
* access the object in your console too, it is called "out"
*/
count = 0;
out = {};
@aminmarashi
aminmarashi / customTakeEvery.js
Last active May 25, 2017 01:00
non-standard takeEvery that passes payload instead of action to the saga
import { fork, takeEvery } from 'redux-saga/effects';
function* intermediateGen(saga, ...args) {
yield fork(saga, ...args.slice(0, -1), args.slice(-1)[0].payload);
}
export default function customTakeEvery(pattern, saga, ...args) {
return takeEvery(pattern, intermediateGen, saga, ...args);
}
@aminmarashi
aminmarashi / greetings-to-redux.md
Last active April 1, 2019 19:06
Greetings to Redux

Is Redux related to React?

"From the very beginning, we need to stress that Redux has no relation to React. You can write Redux apps with React, Angular, Ember, jQuery, or vanilla JavaScript." -- Redux docs

Why do we need redux?

You probably need redux (or any alternatives) if:

  • Your application is becomming big and you have to be constantly worried about race-conditions
  • If you want to do TDD, and you want to write tests for each and every piece of your code
  • You're worried about scalability of your architecture
@aminmarashi
aminmarashi / convert.sh
Created April 19, 2017 03:02
Convert require to import using prettier
#!/bin/bash
find . -name '*.js' -exec gsed -i "s/const \(.*\) = require(\(.*\))\.\(.*\);/import { \3 as \1 } from \2;/g" '{}' ';'
prettier-eslint --write '**/*.js'
find . -name '*.js' -exec gsed -i "s/const \(.*\) = require(\(.*\));/import \1 from \2;/g" '{}' ';'