Skip to content

Instantly share code, notes, and snippets.

@ahume
ahume / extendObj.js
Last active September 22, 2016 21:17
const extendObj =
R.curry((key, valueCreator, obj) => Object.assign({}, obj, { [key]: valueCreator(obj) }));
// e.g.
fetch(url).then(results => results.json())
.then(
R.map(extendObj('deployment_id', () => deploymentId)))
.then(
R.map(extendObj('friendly_created_at', r => moment(r.created_at).format('YYYY-MM-DD HH:mm'))))
# Update, upgrade, and clean
sudo apt-get -y update && sudo apt-get -y dist-upgrade && sudo apt-get -y autoclean && sudo apt-get -y autoremove
# Update rpi firmware
sudo apt-get -y install rpi-update && sudo rpi-update
sudo reboot
@ahume
ahume / amd-to-commonjs.js
Created March 15, 2016 13:29
amd-to-commonjs.js
/**
* Codemod to convert AMD modules to ES2015 syntax
*/
module.exports = function(file, api) {
const j = api.jscodeshift;
const toSourceOpts = { quote: 'single' };
/**
* UNUSED
*
@ahume
ahume / withNoopToggle.js
Last active August 29, 2015 14:22
withNoopToggle
define(function () {
return withNoopToggle;
function withNoopToggle() {
/**
* If toggle is false, do not execute named methods.
*/
this.noopToggle = function (methods, toggle) {
methods.forEach(function (method) {
@ahume
ahume / a.js
Last active August 29, 2015 14:12
withObservableState API
function Compose() {
this.initialState({
characterCount: 0
});
this.after('initialize', function () {
this.provideObservableResource('dockedCompose.state', this.state);
this.attachChild(CharacterCount, this.$node);
});
}
Verifying that +andyhume is my openname (Bitcoin username). https://onename.io/andyhume
// All these methods return promises, so I can chain thens like below.
function test() {
page.loadAndWaitForSignInUi()
.then(function() {
return page.setViewportSize(1300, 500);
})
.then(function() {
return page.patchStreamScribe();
})
import timeit
import math
import sys
import socket
repeat = 10
url = 'http://m.guardian.co.uk'
ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'
if len(sys.argv) > 1 and sys.argv[1] > 0:
<!-- Standard implementation, just before closing body tag -->
_ophan.loaded = function() {
Ophan.logPageView();
}
<script src="http://s.ophan.co.uk/js/ophan.min.js" async defer></script>
</body>
<!-- Or something more custom using require -->
require(["http://s.ophan.co.uk/js/ophan.min.js", adverts, id], function(ophan, adverts, id) {
ophan.additionalData({"isLoggedIn": id.isLoggedIn()});
@ahume
ahume / WorkerPool.js
Created December 20, 2011 11:09
Example of creating a pool of Web Workers
function WorkerPool(url) {
this.url = url;
this.pool = [];
}
WorkerPool.prototype.getWorker = function() {
var w;
if (this.pool.length > 0) {
w = this.pool.pop();
} else {
w = new Worker(this.url);