Skip to content

Instantly share code, notes, and snippets.

@codemile
codemile / Button.tsx
Created July 19, 2021 12:20
Basic example of a Button component in ReactJs.
import {ButtonHTMLAttributes, forwardRef} from 'react';
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
primary?: boolean;
}
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({className, primary, children, ...props}, ref) => {
return (
<button
@codemile
codemile / useClickOutside.tsx
Last active December 30, 2021 20:12
Hook that adds a click listener outside of an element.
import {DependencyList, useCallback, useEffect, useRef} from 'react';
export const useClickOutside = <T extends (...args: any[]) => any>(
cb: T,
dep: DependencyList
) => {
const ref = useRef<HTMLElement>(null);
// eslint-disable-next-line react-hooks/exhaustive-deps
const callback = useCallback(cb, dep);
@codemile
codemile / useDraggable.tsx
Created July 6, 2021 12:21
Hook that makes a DOM element draggable.
import {
MouseEventHandler,
RefObject,
useCallback,
useEffect,
useRef,
useState
} from 'react';
export type DraggableHandler = (coords: [number, number]) => void;

Cheat sheet: JavaScript Array methods

Deriving a new Array from an existing Array:

['■','●','▲'].slice(1, 3)           ['●','▲']
['■','●','■'].filter(x => x==='■')  ['■','■']
    ['▲','●'].map(x => x+x)         ['▲▲','●●']
    ['▲','●'].flatMap(x => [x,x])   ['▲','▲','●','●']
@nishantrpai
nishantrpai / audio.md
Last active June 3, 2021 13:44
Fix Audio Output Issues For Ubuntu

Fix Audio Output Issues For Ubuntu

Note: Play a song before and after the process to understand the difference.

  • sudo cp /etc/pulse/daemon.conf /etc/pulse/daemon.conf.backup
  • sudo nano /etc/pulse/daemon.conf

Change key values

default-sample-format = float32ne
@codemile
codemile / useLogger.tsx
Created April 21, 2021 12:52
A simple logging hook for React
import {useMemo} from 'react';
/**
* Prevents React.DOM from replacing methods inside hooks.
*/
const ref = {
log: console.log,
error: console.error,
debug: console.debug
};
@codemile
codemile / strings.ts
Created April 20, 2021 20:05
Some handy string functions written in TypeScript
/**
* "document_id" -> "document id"
* "documentId" -> "document id"
*/
export const toSpaces = (str: string): string =>
str && str
.replace(/[-_]/g, ' ')
.replace(/([A-Z])/g, ' $1');
/**
@prologic
prologic / LearnGoIn5mins.md
Last active March 23, 2026 03:33
Learn Go in ~5mins
@alexandernl
alexandernl / gist:8090a79a7af4197c5f5571e8cc8c05b8
Created November 11, 2020 12:28
Convert daily New York Times frontpage to jpg
<?php
// set the output-file
$outputfile = "/var/www/nyt/nyt.jpg";
// set path to todays NYT frontpage
$pathToPdf="https://static01.nyt.com/images/".date('Y')."/".date('m')."/".date('d')."/nytfrontpage/scan.pdf";
// check if there is any today
$file_headers = @get_headers($pathToPdf);

What Hiring Should Look Like

This is definitely not the first time I've written about this topic, but I haven't written formally about it in quite awhile. So I want to revisit why I think technical-position interviewing is so poorly designed, and lay out what I think would be a better process.

I'm just one guy, with a bunch of strong opinions and a bunch of flaws. So take these suggestions with a grain of salt. I'm sure there's a lot of talented, passionate folks with other thoughts, and some are probably a lot more interesting and useful than my own.

But at the same time, I hope you'll set aside the assumptions and status quo of how interviewing is always done. Just because you were hired a certain way, and even if you liked it, doesn't mean that it's a good interview process to repeat.

If you're happy with the way technical interviewing currently works at your company, fine. Just stop, don't read any further. I'm not going to spend any effort trying to convince you otherwise.