Skip to content

Instantly share code, notes, and snippets.

Benjie Gillam benjie

Block or report user

Report or block benjie

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
benjie / .gmrc
Created Oct 10, 2019
Example gmrc from (not published at time of writing)
View .gmrc
"pgSettings": {
"search_path": "app_public,app_private,app_hidden,public"
"placeholders": {
"afterReset": [
benjie / hacky-hooks.tsx
Created Aug 2, 2019
Hacky hooks to help you solve certain performance issues with minimal fuss; e.g. `<Foo bar={[1, 2, 3]} />` passes a new array every time, but `useDynamicToStatic` can be used to treat it as if it were the same array so as to not trigger further hook's update methods.
View hacky-hooks.tsx
* If you're sent a dynamic value but you want to treat it as static (e.g. for
* hook dependencies), you can use this function. For arrays it will compare the
* contents of the array rather than the array object itself. For objects it
* will compare the keys and values of the object, rather than the object
* itself. For functions it will just replace the function with a static
* function that calls the underlying function using references.
export function useDynamicToStatic<T>(value: T) {
let condition = [];
View PgUpsertPlugin.js
module.exports = function PgUpsertPlugin(
{ pgDisableDefaultMutations }
) {
if (pgDisableDefaultMutations) {
builder.hook("inflection", (inflection, build) =>
build.extend(inflection, {
benjie /
Created Dec 7, 2018
Updates the `latest` dist-tag on a package so that package@latest points to the same version as package@next
echo "Enter OTP code:"
read otp
export NPM_CONFIG_OTP=$otp
function next2latest {
V=$(npm info $1 | xargs)
npm dist-tags add $1@$V latest
next2latest graphql-parse-resolve-info
next2latest graphile-build
View emulate_require.js
* Read a file manually, but pretend it's actually a Node.js module. Tested in Node 8.11.3 only.
"use strict";
const fs = require("fs");
const path = require("path");
const { Module } = require("module");
// Get the javascript contents from wherever: filesystem, database, network, etc.
// Node calls this filename, but it's actually the full path to the file
View bigdata.sql
-- It's a joke.
drop schema if exists bigdata cascade;
create schema bigdata;
create extension if not exists citext;
set search_path to bigdata, public, pg_catalog;
create table users (
id serial primary key,
username citext not null unique,
benjie / postgraphile-tsv-plugin.js
Last active Jun 24, 2018 — forked from mlipscombe/postgraphile-tsv-plugin.js
full text search plugin for postgraphile (edited)
View postgraphile-tsv-plugin.js
const TSVECTOR_TYPE_ID = 3614;
export const PostGraphileTSVPlugin = builder => {
builder.hook('infection', (inflection, build) => {
return build.extend(inflection, {
fullTextScalarTypeName() {
return `FullText`;
pgTsvRank(fieldName) {
return this.camelCase(`${fieldName}-rank`);
# Ensure all foreign key constraints heve 'ON DELETE' clauses
grep 'FOREIGN KEY.* REFERENCES .*' db/schema.sql | grep -v ' ON DELETE '
if [ "$?" == "0" ]; then
echo "Foreign key constraints without delete instructions - aborting"
exit 2;
benjie /
Last active Nov 17, 2017
Ensure promises are awaited (or have `.catch(...)` installed) within same tick

In node v8 the code in test.js will result in the following:

(node:47866) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Thrown error
(node:47866) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error: Thrown error
    at foo (/Users/benjiegillam/Documents/test/test.js:2:9)
    at Object.<anonymous> (/Users/benjiegillam/Documents/test/test.js:5:17)
    at Module._compile (module.js:612:30)
    at Object.Module._extensions..js (module.js:623:10)
benjie /
Created Jul 26, 2017
Resolve publishing npm package to wrong tag

If you accidentally publish a package to the wrong tag (e.g. @latest when you meant to tag it as @next) you can resolve as follows:

npm show PACKAGE_NAME versions # To view the versions you've published
npm dist-tags add PACKAGE_NAME@NEW_VERSION next # Tag the new package version as `@next`
npm dist-tags add PACKAGE_NAME@OLD_VERSION latest # Restore the correct `@latest` to be your previous release version
You can’t perform that action at this time.