Skip to content

Instantly share code, notes, and snippets.

@karlwestin
karlwestin / README.md
Created August 30, 2018 09:08
How does PouchDB choose adapter?

How does PouchDB choose adapter:

Source is in pouchdb-core

is it http or https? - use these adapters

is it not? - pick the first one in the list of 'preferred adapters'

@karlwestin
karlwestin / config.js
Created March 13, 2018 11:50
config without higher order function
const common = {}
let config = {}
export function setup = url => {
van: {
...common,
remoteDbUrl: process.env.REACT_APP_VAN_COUCHDB_URL || 'http://localhost:5984/',
dateFormats: {
long: 'D MMM, YYYY',
week: 'YYYY-[W]WW'
public save() {
let db = this.get_db();
let data = this.get_data();
let t = this;
console.log('Save:' + this._id);
db.get(this._id, {conflicts: false})
.catch(function (err) {
if (err.status === 404) {
return {}; // you can just return an empty map if docs not found
}
@karlwestin
karlwestin / webpack-dev-server.js
Created October 12, 2016 16:01
Make webpack dev server more quiet
var webpack = require('webpack')
var WebpackDevServer = require('webpack-dev-server')
var config = require('./webpack.dev')
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
inline: true,
historyApiFallback: true,
// It suppress error shown in console, so it has to be set to false.
@karlwestin
karlwestin / README.md
Last active April 22, 2019 08:07
Redux Stopwatch Example

Redux Stopwatch Example

Just an idea, to practice after reading about redux async actions and middleware

the important part is this function

let INTERVAL = 50
let runTimer = () => {
 return (dispatch, getState) => {
@karlwestin
karlwestin / institutet-mot-mutor.md
Created January 15, 2016 16:26
Institutet Mot Mutor

institutet - institutet för högerpolitik,
institutet - en slags dimridå
institutet - för att låtsas att man är många
institutet - när man bara är några få

@karlwestin
karlwestin / add-bearer-token.js
Created October 19, 2015 10:18
Modify kazana-account to return AuthSession
// https://github.com/eHealthAfrica/kazana-account
// this file is found in lib/utils
module.exports = addBearerToken;
var Wreck = require('wreck');
var _ = require('lodash');
var cookieToToken = require('./cookie-to-token');
var addUserIdAndAgency = require('./add-user-id');
var loadUserDocProperties = require('./load-user-doc-properties');
module.exports.getConversationsForUser = function (user, cb) {
db.query(function (doc) {
emit(doc.author, null);
}, {include_docs: true, startkey: user.userId, endkey: user.userId }).then(function (response) {
console.log('response', response)
cb(null, response)
}).catch(function (err) {
cb(err)
})
}
@karlwestin
karlwestin / dev-logs-node1.log
Created July 15, 2015 19:11
starting couchdb 2.0 error
{error,on_load_failure} = load_app_module(couch_ejson_compare)
2015-07-15 21:06:45.032 [debug] Undefined <0.82.0> Lager installed handler error_logger_lager_h into error_logger
2015-07-15 21:06:45.032 [debug] Undefined <0.69.0> Supervisor gr_param_sup started gr_param:start_link(gr_lager_default_tracer_params) at pid <0.84.0>
2015-07-15 21:06:45.032 [debug] Undefined <0.68.0> Supervisor gr_counter_sup started gr_counter:start_link(gr_lager_default_tracer_counters) at pid <0.85.0>
2015-07-15 21:06:45.032 [debug] Undefined <0.70.0> Supervisor gr_manager_sup started gr_manager:start_link(gr_lager_default_tracer_params_mgr, gr_lager_default_tracer_params, []) at pid <0.86.0>
2015-07-15 21:06:45.032 [debug] Undefined <0.70.0> Supervisor gr_manager_sup started gr_manager:start_link(gr_lager_default_tracer_counters_mgr, gr_lager_default_tracer_counters, [{input,0},{filter,0},{output,0}]) at pid <0.87.0>
2015-07-15 21:06:45.062 [info] Undefined <0.7.0> Application lager started on node 'node1@127.0.0.1'
2015-07-15 21
@karlwestin
karlwestin / About.md
Created June 30, 2015 16:29
Porting the erlang checkpoint comparison to JS

Porting CouchDB checkPoints from erlang to javascript

This is an attempt to implement CouchDB checkpoint comparison for PouchDB, to be able to pick up interrupted replications even though checkpoint writing is in an unknown state. Mismatching checkpoints causes replication to start over from change 0

This gist is a request for comments from people familiar with both JS and Erlang, to see if they are functionally identical