Skip to content

Instantly share code, notes, and snippets.

View jednano's full-sized avatar
💾
Writing codes

Jed jednano

💾
Writing codes
View GitHub Profile
@jednano
jednano / keybase.md
Created June 17, 2020 16:01
keybase.md

Keybase proof

I hereby claim:

  • I am jedmao on github.
  • I am jedmao (https://keybase.io/jedmao) on keybase.
  • I have a public key ASA7BpF6w9OoKvLe-RIf_anWdjJFBXsYAEPV9yw8cSgctgo

To claim this, I am signing this object:

@jednano
jednano / transform.ts
Created April 8, 2020 00:29
TypeScript Transformer
import { readFile as _readFile } from 'fs';
import * as ts from 'typescript';
import { promisify } from 'util';
const readFile = promisify(_readFile);
transform('input.ts');
async function transform(filename: string) {
const sourceFile = ts.createSourceFile(
@jednano
jednano / grammar.pegjs
Last active October 28, 2019 15:14
EditorConfig Grammar
Document = _ children:(Newline / Comment / Rule)* _ sections:Section* _ {
return {
type: 'EditorConfig',
version: '15.0.0',
children: children.concat(sections),
}
}
_ 'whitespace' = [ \t\n\r]*
@jednano
jednano / redux.ts
Created September 4, 2019 22:47
Redux TS
/** Essentials */
export type Primitive = string | number | boolean | bigint | symbol | undefined | null;
/** Like Readonly but recursive */
export type DeepReadonly<T> = T extends Primitive
? T
: T extends Function
? T
: T extends Date
? T
@jednano
jednano / onAddToCart.js
Last active August 27, 2019 21:20
TypeScript vs. JavaScript
// @ts-check
/**
* @typedef {{ items: Array<CartItem> }} Cart
* @typedef {{
* sku: string,
* name: string,
* price: number,
* color?: Color,
* size?: Size,
@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>,
}