Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

const unordered = {
b: "foo",
c: "bar",
a: "baz",
};
console.log(JSON.stringify(unordered));
// → '{"b":"foo","c":"bar","a":"baz"}'
const ordered = Object.keys(unordered)
@edwinwright
edwinwright / circ-dep-plugin-config.js
Created November 30, 2021 10:53 — forked from sfrieson/circ-dep-plugin-config.js
Custom configuration around the circular-dependency-plugin to help avoid new ones.
const CircularDependencyPlugin = require('circular-dependency-plugin');
const CIRC_DEP_MAX = 238;
const defaultConfig = {
aggregateDirDepth: 2,
exclude: /node_modules/,
include: /.*/,
logWarnings: true,
logErrors: true,
@edwinwright
edwinwright / macos-app-icon.md
Created August 22, 2019 19:17 — forked from jamieweavis/macos-app-icon.md
How to make an app icon for macOS using iconset & iconutil

How to create a .icns macOS app icon

How to make an app icon for macOS using iconset & iconutil

Saving images

Save your app icon with the following names & dimensions:

Name Dimensions
icon_16x16.png 16x16
@edwinwright
edwinwright / parse_dotenv.bash
Created March 6, 2019 10:50 — forked from judy2k/parse_dotenv.bash
Parse a .env (dotenv) file directly using BASH
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)
function loadScript(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState) {
script.onreadystatechange = function () {
if (script.readyState === "loaded" || script.readyState === "complete") {
script.onreadystatechange = null;
callback();
}
};
@edwinwright
edwinwright / amend-git-commit-user.sh
Last active May 16, 2018 14:11
Change git commit history - amend user name and email
git filter-branch --env-filter '
OLD_EMAIL="old@email.com"
NEW_NAME="New Name"
NEW_EMAIL="new@email.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
@edwinwright
edwinwright / mocha-test-promises.js
Created December 4, 2017 17:44
Testing functions that return Promises in Mocha
// Basic verification
// Returns the promise from somethingAsync()
// The test passes if resolved, fails if rejected
it('does something async with promises', function() {
return somethingAsync();
});
// Verify a fulfilled promise
// Returns the promise from somethingAsync() and runs assertions in the onFulfilled callback
@edwinwright
edwinwright / install-hooks.sh
Last active November 22, 2017 14:27
git hooks install script
#!/bin/bash
HOOK_NAMES="pre-commit"
HOOK_DIR=$(git rev-parse --show-toplevel)/.git/hooks
INSTALL_DIR=$(git rev-parse --show-toplevel)/hooks
COLOR_GREEN=`tput setaf 2`
COLOR_RESET=`tput sgr0`
for hook in $HOOK_NAMES; do
echo "Installing $hook hook..."
@edwinwright
edwinwright / injectScript.js
Created June 13, 2017 14:30
Promise based script loader
const injectScript = (function() {
const scripts = {};
return (url) => {
if (scripts[url]) {
return scripts[url];
} else {
const promise = new Promise((resolve, reject) => {
const head = document.getElementsByTagName('head')[0];
const script = document.createElement('script');
script.type = 'text/javascript';
@edwinwright
edwinwright / index.js
Last active October 10, 2016 13:54
RequireBin - Flattening Marvel API response with normalizr
const response = {
"code": 200,
"status": "Ok",
"copyright": "© 2016 MARVEL",
"attributionText": "Data provided by Marvel. © 2016 MARVEL",
"attributionHTML": "<a href=\"http://marvel.com\">Data provided by Marvel. © 2016 MARVEL</a>",
"etag": "2f08937547f5cbb41e1f5845f9b3adf36417e332",
"data": {
"offset": 0,
"limit": 20,