Skip to content

Instantly share code, notes, and snippets.

View anthowen's full-sized avatar
🏠
Working from home

anthowen

🏠
Working from home
View GitHub Profile

Keybase proof

I hereby claim:

  • I am anthowen on github.
  • I am anthowen (https://keybase.io/anthowen) on keybase.
  • I have a public key ASAmE0avnfMrHgBJsztetVeYwduvdAJAEVOgvKoLlVCxswo

To claim this, I am signing this object:

@anthowen
anthowen / vscExtensions.md
Last active June 23, 2020 13:53
Favorite VSCExtensions
@anthowen
anthowen / Gemfile
Created June 25, 2020 12:03 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@anthowen
anthowen / useOutsideClick.ts
Last active September 20, 2022 09:49
useOutsideClick (TypeScript) - a custom react hook that handles outside click event of certain area. It also ignores click event on browser's scrollbar.
import { useEffect, RefObject } from 'react';
/**
* Hook that handles outside click event of the passed refs
*
* @param refs array of refs
* @param handler a handler function to be called when clicked outside
*/
export default function useOutsideClick(
refs: Array<RefObject<HTMLElement> | undefined>,
@anthowen
anthowen / useFilter.ts
Last active November 29, 2022 09:34
A react custom hook designed for querying data from API. (TypeScript)
import { useState, useReducer, useEffect } from 'react';
import { Nullable } from 'interfaces';
type SearchState<T> = {
results: Array<T>;
isSearching: boolean;
isError: boolean;
};
type SearchAction<T> =
| { type: 'FETCH_INIT' }
@anthowen
anthowen / react-input-search.ts
Last active November 29, 2022 09:33
This shows how to implement debounced search (interacting with API) in a custom input element
// Note: I write down only essential parts of the component, because the other part can make sense without itself.
import { useFilter } from 'hooks/useFilter.ts';
import debounce from 'lib/debounce';
function InputSearch({...} : InputSearchInterface) {
// api - a search api wrapper that returns promise
// useFilter - a custom react hook used for search (https://gist.github.com/anthowen/7309f9d54dcdeefcefab1e37a75d716c)
const [{ results, isSearching }, doFilter] = useFilter<T>(api, null, []);
@anthowen
anthowen / typescriptreact.json
Last active June 29, 2020 13:39
VS Code Snippet for ease of redux-saga request handlers
{
// Place your snippets for typescriptreact here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@anthowen
anthowen / debounce.ts
Created June 29, 2020 12:12
a debounce utility in TypeScript
const debounce = <F extends (...args: any[]) => any>(
func: F,
waitFor: number,
) => {
let timeout: NodeJS.Timeout;
return (...args: Parameters<F>): Promise<ReturnType<F>> =>
new Promise((resolve) => {
if (timeout) {
clearTimeout(timeout);
@anthowen
anthowen / usePagination.js
Created June 30, 2020 18:59
Pagination implementation using react-query. Thanks @tannerlinsley for this awesome library!
let [hasNextPage, setHasNextPage] = React.useState(true)
const { data } = useInfiniteQuery(key, (key, nextPage) => {
const data = fetch('/api?page=' + nextPage)
if (data.length) {
return data
} else {
setHasNextPage(false)
return []
@anthowen
anthowen / 1.md
Created July 7, 2020 12:41 — forked from swyxio/1.md
Learn In Public - 7 opinions for your tech career

2019 update: this essay has been updated on my personal site, together with a followup on how to get started

2020 update: I'm now writing a book with updated versions of all these essays and 35 other chapters!!!!

1. Learn in public

If there's a golden rule, it's this one, so I put it first. All the other rules are more or less elaborations of this rule #1.

You already know that you will never be done learning. But most people "learn in private", and lurk. They consume content without creating any themselves. Again, that's fine, but we're here to talk about being in the top quintile. What you do here is to have a habit of creating learning exhaust. Write blogs and tutorials and cheatsheets. Speak at meetups and conferences. Ask and answer things on Stackoverflow or Reddit. (Avoid the walled gardens like Slack and Discourse, they're not public). Make Youtube videos