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
@danieldietrich
danieldietrich / README.md
Last active Oct 20, 2019
The easiest way to bundle a simple TypeScript web application
View README.md

The easiest way to bundle a simple TypeScript web application

Packaging JavaScript applications can be a bit overwhelming. The popular project uglifyjs does not support ES6, it is cumbersome to configure the allmighty Webpack, bundlers like Parcel and Microbundle still have bugs or do not compile to ESM bundles that work in a browser. It is hard to figure out the best way to bundle an application.

Here I give a small example, how we achieve the goal using the

@danieldietrich
danieldietrich / package.json
Created Oct 14, 2019 — forked from jayphelps/package.json
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",
}
}
@danieldietrich
danieldietrich / babel-webpack.md
Created Oct 14, 2019 — forked from ncochard/babel-webpack.md
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.
@danieldietrich
danieldietrich / unicode.ts
Created Sep 5, 2019
Unicode Dictionary for Slugifying / Hyphenating URLs (see https://github.com/danieldietrich/slugify)
View unicode.ts
// A subset of Unicode version 12.0
// https://en.wikipedia.org/wiki/List_of_Unicode_characters
// https://en.wiktionary.org/wiki
// Identity translations a-zA-Z0-9 and most punctuations are suppressed.
// Units and currencies and some are translated.
const unicode = {
"Basic Latin": {
// ASCII Punctuation & Symbols
'$': 'dollar',
'%': 'percent',
View Fetch.java
import io.vavr.control.Try;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
public final class Fetch {
View vavr-logo-history.txt
2014-2015
/ \____ _ ______ _____ / \____ ____ _____
/ \__ \/ \ / \__ \ / __// \__ \ / \/ __ \
_/ // _\ \ \/ / _\ \\_ \/ // _\ \ /\ \__/ /
/___/ \_____/\____/\_____/____/\___\_____/_/ \_/____/
2015-2016
/ \____ _ _ ____ ______ / \ ____ __ _ _____
/ / \/ \ / \/ \ / /\__\/ // \/ \ / / _ \
_/ / /\ \ \/ / /\ \\__\\ \ // /\ \ /\\/ \__/ /
@danieldietrich
danieldietrich / README.md
Last active Jul 16, 2019
Deeply merging JavaScript objects
View README.md

Deeply merging JavaScript objects

This method is like Object.assign except that it recursively merges own enumerable string keyed properties of source objects into the destination object. Source properties that resolve to undefined are skipped if a destination value exists. Arrays are concatenated. Plain object properties are merged recursively. Other objects and value types are overridden by assignment. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.

Note: This method mutates target.

Motivation

  • The native Object.assign does simply overwrite values on duplicate keys.
  • The Lodash _.merge does not handle arrays the way I would expect it:
@danieldietrich
danieldietrich / scratchbook.md
Created May 26, 2019
Markdown enumerated list
View scratchbook.md

List

  1. first
  2. second
  3. third
@danieldietrich
danieldietrich / Generics.md
Last active May 21, 2019
Simple but interesting Java generics example.
View Generics.md

Interestingly I had to use

static <T> Predicate<T> instanceOf(Class<? extends T> type)

instead of

static <T> Predicate<? super T> instanceOf(Class<T> type)
View .bash_profile
# -----------------------------------------------------------------------------
# This is a fragment of ~/.bash_profile that adds git status and branch
# information to the terminal prompt. The 'colors' section is optional.
# -----------------------------------------------------------------------------
# prompt
export PS1="\[\e[0;32m\]\u@\h:\[\e[1;36m\]\w\[\e[0;33m\]\$(parse_git_status)\[\e[1;32m\]\$(parse_git_branch)\[\e[1;36m\] $\[\e[0m\] "
# colors
export TERM=xterm-color
You can’t perform that action at this time.