Skip to content

Instantly share code, notes, and snippets.

View rake7h's full-sized avatar
😀

Rakesh rake7h

😀
View GitHub Profile
@rake7h
rake7h / brew.sh
Created March 28, 2024 04:13
install brew in M3
// install commond line tools if not install already
$ xcode-select --install
// download homebrew install script and run
$ curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
$ /bin/bash install.sh
// set brew path to ~/.zshrc
export PATH=/opt/homebrew/bin:$PATH
@rake7h
rake7h / memo.js
Last active October 6, 2023 11:47
// Write a Memorize function.
function memorize(fun) {
// memorize the fun output
}
function sum(a, b) {
console.log('run')
return a+b;
}
https://www.developerway.com/posts/webpack-and-yarn-magic-against-duplicates-in-bundles
https://nitayneeman.com/posts/catching-up-with-package-lockfile-changes-in-npm-v7/
const requestHeaders = Object.fromEntries(req.headers.entries())
% This rule will enforce that all packages must have a "BSD-2-Clause" license field
gen_enforced_field(WorkspaceCwd, 'license', 'BSD-2-Clause').
% Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, null, 'devDependencies') :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'devDependencies'),
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'dependencies').
% Enforces 'publishConfig.access' is set to public for public workspaces while removing it from private workspaces
gen_enforced_field(WorkspaceCwd, 'publishConfig.access', 'public') :-
import { createProgram, CompilerOptions } from "typescript";
interface GenerateTypeDefination {
files: string[];
}
const generateTypeDefination = ({ files }: GenerateTypeDefination): void => {
function compile(fileNames: string[], options: CompilerOptions): void {
// Prepare and emit the d.ts files
const program = createProgram(fileNames, options);
#!/usr/bin/env node
require('esbuild-register/dist/node').register();
require('./cli.ts');
@rake7h
rake7h / async-await-forEach-alternatives.md
Created February 28, 2023 05:17 — forked from joeytwiddle/async-await-forEach-alternatives.md
Do not use forEach with async-await

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do:

@rake7h
rake7h / date-utils.js
Last active February 4, 2023 17:49
date-utils.js
// date to epoc
const epoc = new Date("2016/3/17").valueOf()
// epoc to data
const formatter = new Intl.DateTimeFormat("en-GB");
console.log(formatter.format(epoc));
const stream = require('stream')
const cache = new Map() // you might wanna use an lru here
function createCacheStream (url) {
const buf = []
return stream.Transform({
transform: function (data, enc, cb) {
buffer.push(data)
cb(null, data)
},