Skip to content

Instantly share code, notes, and snippets.

View hrishikeshs's full-sized avatar

Hrishikesh S hrishikeshs

View GitHub Profile
@hrishikeshs
hrishikeshs / gist:b566b1bb83e436836558ea92dcf85cb1
Created June 2, 2025 20:39
Command to direct npm run test's output to a file while stripping terminal escape sequences so test results can be analyzed later
npm run test 2>&1| sed -r "s/\x1B\[[0-9;]*[mK]//g" | tee test-results.txt
const getUpgradePromoBanner = (user: User) => {
if (user.getplanType() === 'premium') {
return 'PREMIUM_TO_PRO';
}
if (user.getPlanType() === 'free') {
return 'FREE_TO_PREMIUM';
}
...
}
const getUpgradePromoBanner = (user: User) => {
if (isPremiumUser(user)) {
return 'PREMIUM_TO_PRO';
}
if (isFree(user)) {
return 'FREE_TO_PREMIUM';
}
...
}
@hrishikeshs
hrishikeshs / user.ts
Last active June 25, 2024 04:29
abstraction-primitives
export type DateOfBirth = {
day: number;
month: number;
year: number;
};
export type User = {
firstName: string | undefined;
lastName: string | undefined;
dateOfBirth: DateOfBirth | undefined;
@hrishikeshs
hrishikeshs / node-typescript-esm.md
Created November 21, 2023 17:48 — forked from khalidx/node-typescript-esm.md
A Node + TypeScript + ts-node + ESM experience that works.

The experience of using Node.JS with TypeScript, ts-node, and ESM is horrible.

There are countless guides of how to integrate them, but none of them seem to work.

Here's what worked for me.

Just add the following files and run npm run dev. You'll be good to go!

package.json

@hrishikeshs
hrishikeshs / debounce-and-throttle.js
Created June 16, 2023 05:20
debounce and throttle implementations in plain english
/**
* It has somehow become very fashionable to ask candidates in frontend engineering interviews
* to implement lodash's _.debounce and _.throttle functions. Though the actual functions
* in both underscore and lodash took days to define, and refine, and the developers
* who implemented them were probably not under a 40 minute time limit.
*
* I have struggled with this myself when I interviewed at a few places last year. My
* approach towards preparing for these questions was to dive into the source code of
* lodash and underscore and understand what the functions were doing. Unfortunately,
* the source code for these functions is pretty complex (and the variable names are hard for me to follow,
@hrishikeshs
hrishikeshs / git-diff-deleted
Created March 22, 2022 13:23
git diff output that shows only the deleted lines from your diff.
#!/bin/bash
#
# Written by Hrishikesh S
#
# Filters the output of git diff by showing you only the lines that are deletions.
# It doesn't display additions.
#
# Put this anywhere on your $PATH (~/bin is recommended). Then git will see it
# and you'll be able to do `git diff-deleted`.
#
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@tracked myArray = [];
constructor() {
super(...arguments);
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}