Skip to content

Instantly share code, notes, and snippets.

View benjie's full-sized avatar

Benjie benjie

View GitHub Profile
-- 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
benjie / postgraphile-tsv-plugin.js
Last active June 24, 2018 07:30 — forked from mlipscombe/postgraphile-tsv-plugin.js
full text search plugin for postgraphile (edited)
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;
fi;
@benjie
benjie / README.md
Last active November 17, 2017 11:01
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
benjie / npm-wrong-tag.md
Created July 26, 2017 12:16
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
@benjie
benjie / minimonocle.js
Created December 4, 2016 05:12
A monoclejs-like purely promise based asynchronous generator iterator thingy (where you can relatively safely sprinkle `yield` everywhere)
function isIterator(obj) {
return (obj && typeof obj === 'object' && typeof obj.next === 'function' && typeof obj.throw === 'function');
}
function isPromise(obj) {
return (obj && typeof obj === 'object' && typeof obj.then === 'function');
}
function o_P() {
var _resolve, _reject;
var promise = new Promise(function (resolve, reject) {
_resolve = resolve;
begin;
create table a(foo varchar not null primary key);
create table b(foo varchar not null primary key, constraint qux foreign key (foo) references a deferrable initially deferred);
create function bar() returns trigger as $$
begin
if TG_OP = 'INSERT' then
insert into b(foo) values(new.foo);
elsif TG_OP = 'DELETE' then
delete from b where foo = old.foo;
end if;
@benjie
benjie / circle.yml
Last active October 29, 2024 19:38
Getting PLv8 to run on Postgresql 9.5 on CircleCI (Ubuntu 14.04)
dependencies:
pre:
- sudo apt-get update
- sudo pip install pgxnclient
- sudo apt-get install libpq-dev libv8-dev postgresql-server-dev-9.5
- sudo pgxn install 'plv8=1.4.4'
# Just to be 100% certian you are using 9.5, and save a bit of memory.
- sudo service postgresql stop 9.4
- sudo service postgresql restart 9.5
@benjie
benjie / 2016-04-13.md
Last active April 20, 2016 08:18
Dalek Committee notes

Phase 2 Initial Dalek Planning Meeting

Tuesday 12th April 2016, 8pm

Present: Alan D, Al B, Benjie G, Bracken D, James B, Mark H, Paul D, Richard G, Step S, Tyler W

Apologies: Jem G, Stephen C, Chris S

First we attempted to outline some of the issues the Dalek has and what we'd like to improve about him. These included things such as (in alphabetical order...):

@benjie
benjie / README.md
Created April 1, 2016 09:15
Easy plv8 on OSX

Heroku runs plv8 v1.4.2 (checked on 1st April 2016). On OSX it's easiest to install v1.4.3 since that allows V8 3.15 which is available via homebrew. (1.4.2 wants V8 3.14.5).

To install:

brew install v8-315
pip install pgxnclient
LIBRARY_PATH="/usr/local/opt/v8-315/lib" CPATH="/usr/local/opt/v8-315/include" pgxnclient install plv8=1.4.3