Skip to content

Instantly share code, notes, and snippets.

💭
🕉 Coding...

Daniel Dietrich danieldietrich

💭
🕉 Coding...
Block or report user

Report or block danieldietrich

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@willfrew
willfrew / tuples.ts
Created Aug 15, 2018
Fun with tuple types in Typescript 3.0
View tuples.ts
type Head<T extends unknown[]> = T[0];
type FnWithArgs<T extends unknown[]> = (...args: T) => void;
type TailArgs<T> = T extends (x: unknown, ...args: infer T) => unknown ? T : never;
type Tail<T extends unknown[]> = TailArgs<FnWithArgs<T>>;
// Lol
type Decr<T extends number> =
T extends 10 ? 9 :
T extends 9 ? 8 :
View api-cheatsheet-array.md

Array<T>

Legend:

  • ✏️ method changes this.
  • 🔒 method does not change this.

Array<T>.prototype.*:

  • concat(...items: Array<T[] | T>): T[] 🔒 ES3
@ncochard
ncochard / babel-webpack.md
Last active Nov 13, 2019
The correct way to compile ES6 using babel...
View babel-webpack.md

When you create a npm package, remember it might be used in a browser or a server, or even a command line utility… For each package you create, please pay attention at what it will be used for:

  1. Is it going to be used as a dependency to a nodejs application that is not bundled? (e.g. command line utilities)
  2. Is it going to be used as a dependency to a nodejs application that is bundled? (e.g. AWS Lambdas)
  3. Is it going to be used as a dependency to a browser application (always bundled)?.
  • In cases 2) and 3) you want to allow for tree shaking.
  • In cases 1) and 2) you want to benefit from the "ES6"/"ES next" features supported natively by nodejs.
  • In case 3) you also want to benefit from the native support of "ES6" from your browser.
@jayphelps
jayphelps / package.json
Last active Nov 20, 2019
TypeScript output es2015, esm (ES Modules), CJS, UMD, UMD + Min + Gzip. Assumes you install typescript (tsc), rollup, uglifyjs either globally or included as devDependencies
View package.json
{
"scripts": {
"build": "npm run build:es2015 && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
"build:es2015": "tsc --module es2015 --target es2015 --outDir dist/es2015",
"build:esm": "tsc --module es2015 --target es5 --outDir dist/esm",
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs",
"build:umd": "rollup dist/esm/index.js --format umd --name YourLibrary --sourceMap --output dist/umd/yourlibrary.js",
"build:umd:min": "cd dist/umd && uglifyjs --compress --mangle --source-map --screw-ie8 --comments --o yourlibrary.min.js -- yourlibrary.js && gzip yourlibrary.min.js -c > yourlibrary.min.js.gz",
}
}
View SetNarrowTest.java
import javaslang.collection.*;
import javaslang.*;
public class SetNarrowTest {
static class PersonBase {
public final String name;
public PersonBase(String name) {
this.name = name;
}
@bvaughn
bvaughn / react-lifecycle-cheatsheet.md
Last active Oct 29, 2019
React lifecycle cheatsheet
View react-lifecycle-cheatsheet.md

React lifecycle cheatsheet

Method Side effects1 State updates2 Example uses
Mounting
componentWillMount Constructor equivalent for createClass
render Create and return element(s)
componentDidMount DOM manipulations, network requests, etc.
Updating
componentWillReceiveProps Update state based on changed props
@citrusui
citrusui / dropdown.md
Last active Nov 19, 2019
"Dropdowns" in Markdown
View dropdown.md
How do I dropdown?
This is how you dropdown.

<details>
<summary>How do I dropdown?</summary>
<br>
This is how you dropdown.
@baldwmic
baldwmic / MochaHooksLifecycle
Last active Jun 3, 2018
Mocha Hooks Lifecycle
View MochaHooksLifecycle
describe('Mocha Hooks Lifecycle', () => {
describe('Level 1', () => {
before(() => {
console.log(1, 'before');
});
beforeEach(() => {
console.log(1, 'beforeEach');
});
@ebidel
ebidel / template_vs_innerhtml.html
Last active Oct 7, 2019
Fastest way to create shadow DOM (.innerHTML vs. <template>)
View template_vs_innerhtml.html
<!doctype html>
<html>
<head>
<title>What's the fastest way to create shadow DOM</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
padding: 3em;
font-family: "Roboto", sans-serif;
View sol-test.js
var meta;
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var should = require('chai').should();
contract('HumanStandardTokenFactory', function(accounts) {
var createHumanStandardToken;
You can’t perform that action at this time.