Skip to content

Instantly share code, notes, and snippets.

View jednano's full-sized avatar
💾
Writing codes

Jed jednano

💾
Writing codes
  • Austin, TX
View GitHub Profile
@jednano
jednano / extensions-to-language.yml
Created August 17, 2019 21:18
File extensions to languages
abap: ABAP
bat: Windows Bat
bib: BibTex
c: C
clj: Clojure
coffee: CoffeeScript
cpp: C++
cs: C#
cshtml: Razor page/view
css: CSS
@jednano
jednano / language_identifiers.yml
Created August 17, 2019 15:57
Language Identifiers
abap: ABAP
bat: Windows Bat
bibtex: BibTeX
clojure: Clojure
coffeescript: Coffeescript
c: C
cpp: C++
csharp: C#
css: CSS
diff: Diff
@jednano
jednano / 01-Labeled.tsx
Last active June 25, 2019 18:44
Example of an extensible and themeable TypeScript React component.
import React from 'react'
export interface LabeledProps {
label: string
/**
* @default 'input'
*/
children?: React.ReactNode
/**
* @default 'label'
@jednano
jednano / objectFromEntries.ts
Last active March 1, 2019 16:23
Object.fromEntries in TypeScript
type ObjectPairs<T, X = keyof T, Y = string> = Array<[X, Y]> | Map<X, Y>
export function objectFromEntries<
T extends { [key: string]: any } = { [key: string]: any },
P extends ObjectPairs<T> = ObjectPairs<T>
>(pairs: P) {
const result = {} as T
for (const [key, value] of pairs.entries()) {
result[key] = value
}
return result
@jednano
jednano / AddToCartFormWithHooks.tsx
Last active June 24, 2022 10:11
React Hooks and Render Props in TypeScript
import { FC, useCallback } from 'react'
import { connect } from 'react-redux';
import addToCart from '../actions/cart'
import useAddToCart, { UseAddToCartOptions } from './useAddToCart'
interface DispatchProps {
onSubmit(options: UseAddToCartOptions): Promise<void>,
}
@jednano
jednano / config.ts
Last active February 22, 2019 20:44
Hooks
import { createNinja, Katana, Shuriken } from './entities';
export default {
Warrior: createNinja,
Weapon: () => new Katana(),
ThrowableWeapon: () => new Shuriken(),
};
@jednano
jednano / actions.ts
Last active February 21, 2019 23:55
TypeScript React Thunk Action Creator
import { Action } from 'redux';
import { AppActionCreator } from '.';
interface FooAction extends Action<'FOO'> {
payload: string;
}
export const foo: AppActionCreator<FooAction> = (
bar: string,
export default interface ResponsePayload {
errors?: ResponsePayloadError[];
// tslint:disable-next-line:no-any
[key: string]: any;
}
/**
* https://jsonapi.org/format/#error-objects
*/
export interface ResponsePayloadError {
@jednano
jednano / transpile.test.ts
Last active January 23, 2019 23:41
transpile
import transpile, { Writer } from './transpile';
describe('transpile', () => {
describe('given a reader that always reads "foobarbaz"', () => {
const reader = { read: () => 'foobarbaz' };
describe('given a default writer', () => {
@jednano
jednano / EventEmitter.test.ts
Last active October 21, 2022 10:52
TypeScript Polling / Event Emitter
import { noop } from 'lodash';
import EventEmitter from './EventEmitter';
describe('EventEmitter class', () => {
describe('on()', () => {
it('subscribes to foo event with listener', () => {
const e = new EventEmitter();
e.on('foo', noop);