Skip to content

Instantly share code, notes, and snippets.

create table foo (
id bigserial primary key,
prev bigint
);
insert into foo(id, prev) values
(1, NULL),
(2, 1),
(4, 2),
(12, 4),
/**
This middleware enhances redux-thunk, to deal with asynchronous actions
conventions and usage:
- an action is a plain object `{type: TYPE_CONSTANT, value: ANY_VALUE}` or an array of those actions (handled by reducer)
- you can shape action creators as `queryArgs => promise` (where the promise returns an action)
- or `queryArgs => action` (where the action value is a promise).
examples:
const getProfile = id => ({ type: GET_PROFILE, value: fetchApi(`/profile/${id}`) });
create table foo (
id bigserial primary key,
name text,
created date
);
insert into foo(name,created) values
('lol', '2018-01-09'),
('lol', '2018-01-08'),
('lol', '2018-01-08'),
@caub
caub / context-demo#.js
Created January 13, 2018 15:21
React context demo
// https://codesandbox.io/s/jznpj65nm5
// ------- index.js
import React from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
import DataProvider from './DataProvider';
import * as data from './dataStore';
const styles = {

Keybase proof

I hereby claim:

  • I am caub on github.
  • I am caub (https://keybase.io/caub) on keybase.
  • I have a public key whose fingerprint is 252A 77AD 73A4 A8BC FF76 D655 303C 5F10 6F57 4D9B

To claim this, I am signing this object:

@caub
caub / knex-bin.diff
Last active November 30, 2017 09:44
knex CLI patch, for allowing --config=connectionString. add a npm script: "cd node_modules/knex && curl https://cdn.rawgit.com/caub/a8c23f97aa1942f2012ad8639769168c/raw/b3e96e3f09b2895329315b3aab13ce79a50049bc/knex-bin.diff | patch -p1 -t"
diff --git a/bin/cli.js b/bin/cli.js
index 9dc79f9..cf68699 100755
--- a/bin/cli.js
+++ b/bin/cli.js
@@ -33,11 +33,23 @@ function checkLocalModule(env) {
}
function initKnex(env) {
-
checkLocalModule(env);
@caub
caub / session-store.js
Created November 23, 2017 16:12
Custom session store
const { Store } = require('express-session');
const { knex } = require('.');
class PGStore extends Store {
destroy(sid, cb) {
return knex('sessions').where('id', sid).delete().then(() => cb());
}
get(sid, cb) {
// console.log('get', sid);
// render .js files as templates (they must be function taking options as arguments and outputting a valid HTML string)
app.engine('js', function (filePath, options, callback) {
if (process.env.NODE_ENV !== 'production') {
require.cache[filePath] = undefined; // invalidate require cache in dev
}
callback(null, require(filePath)(options)); // note: should wrap in a safeHtml in prod
});
app.set('views', __dirname + '/views');
app.set('view engine', 'js');
@caub
caub / .gitconfig
Last active August 24, 2020 20:50
[user]
email = cyril.auburtin@gmail.com
name = caub
[alias]
a = add --all
au = add -u
b = branch
br = branch -r
amend = commit --amend -C HEAD
@caub
caub / yes.js
Last active October 12, 2017 19:43
a fast yes implementation
const { Readable } = require('stream');
const ys = Buffer.from('y\n'.repeat(2**16));
class Y extends Readable {
_read(size) {
this.push(ys.slice(0, size));
}
}
new Y().pipe(process.stdout); // test with node yes | pv -r > /dev/null