Skip to content

Instantly share code, notes, and snippets.

Plan A is looking for a backend and infrastructure freelancer

We need you to help with the launch of a new digital platform that helps companies calculate, monitor and reduce their carbon emissions and establish a more sustainable culture.

  • When? Immediately, with more intense work within the next few weeks and potentially ongoing support in the future
  • What? We're running Laravel (PHP/MySQL) on AWS, currently upgrading from a single EC2 instance to AWS Elastic Beanstalk; some Stripe subscription payment integration also needs to be done
  • Where? In a nice office in the center of Berlin; mostly on-site expected
  • Who? Amazingly friendly, motivated, purposeful, young, open-minded team from all over the world with a strong mission to fight climate change

Please get in touch via Twitter @xMartin

import { createStore, applyMiddleware, compose } from 'redux';
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(reducer, INITIAL_STATE, composeEnhancers(
applyMiddleware(thunkMiddleware)
));
@xMartin
xMartin / n-promises.js
Created February 15, 2017 22:58
Running n async operations sequentially in JavaScript with Promises (note the re-assignment of `promise`)
const n = 10
let promise = Promise.resolve()
for (let i = 0; i < n; ++i)
promise = promise.then(doSomethingAsync)
@xMartin
xMartin / optimal-select-phantomjs-test.js
Created November 7, 2016 10:48
Runs a simple test with optimal-select in PhantomJS (`phantomjs optimal-select-phantomjs-test.js`)
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open('http://xmartin.de/', function(status) {
page.evaluate(function() {
console.log(document.title);
});
@xMartin
xMartin / browser.html
Created February 19, 2016 19:36
crypto-pouch binary attachments
<!DOCTYPE html>
<script src="node_modules/pouchdb/dist/pouchdb.js"></script>
<script src="node_modules/crypto-pouch/bundle.js"></script>
<script>
var db = new PouchDB('db')
PouchDB.plugin(crypto)
var id = 'id-' + PouchDB.utils.uuid()
db.crypto('secretSecureEncryptionKey')
@xMartin
xMartin / gist:ba4e098cbbbe92e48fc7
Created September 1, 2014 16:20
JS Component Registry
function Registry() {
this._store = {};
}
Registry.prototype.get = function (id) {
return this._store[id];
};
Registry.prototype.require = function (id) {
var entry = this.get(id);
@xMartin
xMartin / gist:9f3e5e46e8527e0182af
Last active August 29, 2015 14:05
JS DIContainer
function DIContainer(constructors) {
this._instances = {};
this._constructors = {};
for (var id in constructors) {
this.set(id, constructors[id]);
}
}
DIContainer.prototype.get = function (id) {
var entry = this._instances[id];
@xMartin
xMartin / gist:8185040
Created December 30, 2013 17:22
Simple test case demonstrating an IE issue where opacity is not inherited
<!doctype html>
<head>
<style>
#outer {
background: red;
height: 5em;
transition: opacity 1s;
/* position: relative; /* fixes opacity issue below */
}
#inner {
@xMartin
xMartin / base64.js
Created December 12, 2011 10:44
dojox.encoding.base64 with no dependencies
define(function() {
var base64 = {};
var p="=";
var tab="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
base64.encode=function(/* byte[] */ba){
// summary
// Encode an array of bytes as a base64-encoded string