Skip to content

Instantly share code, notes, and snippets.

@ahume
ahume / clock-demo.html
Created November 19, 2011 01:10
Simple example clock based on the time sent from the sever.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Clock based on server time</title>
</head>
<body>
<h1>Clock demo for Kylie</h1>
@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);
<!-- 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()});
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:
// 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();
})
Verifying that +andyhume is my openname (Bitcoin username). https://onename.io/andyhume
@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);
});
}
@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 / 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
*
# 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