Skip to content

Instantly share code, notes, and snippets.

Brendan Graetz bguiz

Block or report user

Report or block bguiz

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
View web3-provider-with-fallback-for-old-version.js
// web3 provider with fallback for old version
window.addEventListener('load', async () => {
// New web3 provider
if (window.ethereum) {
window.web3 = new Web3(ethereum);
try {
// ask user for permission
await ethereum.enable();
// user approved permission
View whoami.json
{"id": "0d593b03242553b24568b3dbccceadd8cb419795091f6e75267f37d8e6100771c10b3bd55285eae9adc99c3e1b0a770f152e132c20c8425b94d43c7d65fc36a9"}
View .block
license: gpl-3.0
height: 700
border: no
View a-way-to-edit-a-different-git-branch.md

Why

  • You want to do a minor edit to files on another branch
  • The copy of the git repo that you have locally is in a state that is too much effort to clean up/ revert/ stash etc to bother

How

  • simply clone the repo in a different folder
  • but this clone is minimal, so it's much faster
View javascript-unsigned-integer-16-bitshift.txt
> 0b11111111111111110000000000000000 - 0b100000000000000000
4294770688
> ((0xffff - 2) * 0x10000)
4294770688
> ((0xffff - 2) << 16)
-196608 # WHY??>?
> ((0xffff - 2) << 16) >>> 0
4294770688
@bguiz
bguiz / README.md
Last active Aug 22, 2017
Custom NodeJs REPL
View README.md

Custom NodeJs REPLs

A way to create read-eval-print-loops for your own projects, with a per-instance history, rather than a global history.

Sample Usage

@bguiz
bguiz / RouteListener.js
Last active Jul 24, 2017
onUpdate in react-router-4
View RouteListener.js
import { Component } from 'react';
import PropTypes from 'prop-types';
function RouteListenerFactory(plugins = []) {
plugins.forEach((plugin, pluginIdx) => {
if (!plugin.name) {
plugin.name = `routeListenerPlugin#${pluginIdx}`;
}
if (!plugin.initialise) {
@bguiz
bguiz / npm-path-extras.sh
Created Aug 25, 2016
See what npm run prepends to the PATH
View npm-path-extras.sh
$ pwd
/Users/bguiz/code/scratch-project
$ echo ${PATH}
/Users/bguiz/.nvm/versions/node/v4.4.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ npm run print-my-path # "print-my-path": "echo ${PATH}"
> scratch-project@0.8.2 print-my-path /Users/bguiz/code/scratch-project
> echo ${PATH}
/Users/bguiz/.nvm/versions/node/v4.4.7/lib/node_modules/npm/bin/node-gyp-bin:/Users/bguiz/code/scratch-project/node_modules/.bin:/Users/bguiz/.nvm/versions/node/v4.4.7/bin:/Users/bguiz/.nvm/versions/node/v4.4.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
@bguiz
bguiz / git-dependency-install-and-build.sh
Created Aug 23, 2016
Installs a dependency from a git repo using info specified in pakage.json, then builds it
View git-dependency-install-and-build.sh
#!/bin/bash
# Installs a dependency from a git repo using info specified in pakage.json, then builds it
: <<"MultilineCommentDelimiter"
Place this file in ./devops/git-dependency/install-and-build.sh
Update package.json to add "config" and a a build step to "scripts"
{
"config": {
@bguiz
bguiz / catch-doesnt-stop-promise-chain.js
Last active Jul 1, 2016
`.catch()` doesn't stop the rest of a promise chain from executing
View catch-doesnt-stop-promise-chain.js
// returns a promise that always rejects
function myPromise() {
return new Promise((resolve, reject) => {
reject('error in myPromise');
});
}
// promise.catch(a).then(b).catch(c)
myPromise().catch(function a(err) {
console.log('a:', err);
You can’t perform that action at this time.