Andy Thomason is a Senior Programmer at Genomics PLC. He has been witing graphics systems, games and compilers since the '70s and specialises in code performance.
import crypto from "crypto"; | |
import { renderToStaticMarkup } from "react-dom/server"; | |
import createMailgun from "mailgun-js"; | |
import type { ActionFunction, LoaderFunction, Session } from "remix"; | |
import { createCookieSessionStorage, json, redirect } from "remix"; | |
/******************************************************************************* | |
* Before we can do anything, we need to make sure the environment has | |
* everything we need. If anything is missing, we just prevent the app from | |
* starting up. |
// Shannon entropy | |
const entropy = str => { | |
return [...new Set(str)] | |
.map(chr => { | |
return str.match(new RegExp(chr, 'g')).length; | |
}) | |
.reduce((sum, frequency) => { | |
let p = frequency / str.length; | |
return sum + p * Math.log2(1 / p); | |
}, 0); |
It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.
More details - http://blog.gbaman.info/?p=791
For this method, alongside your Pi Zero, MicroUSB cable and MicroSD card, only an additional computer is required, which can be running Windows (with Bonjour, iTunes or Quicktime installed), Mac OS or Linux (with Avahi Daemon installed, for example Ubuntu has it built in).
1. Flash Raspbian Jessie full or Raspbian Jessie Lite onto the SD card.
2. Once Raspbian is flashed, open up the boot partition (in Windows Explorer, Finder etc) and add to the bottom of the config.txt
file dtoverlay=dwc2
on a new line, then save the file.
3. If using a recent release of Jessie (Dec 2016 onwards), then create a new file simply called ssh
in the SD card as well. By default SSH i
With the release of Node 6.0.0, the surface of code that needs transpilation to use ES6 features has been reduced very dramatically.
This is what my current workflow looks like to set up a minimalistic and fast microservice using micro and async
+ await
.
The following are a few important npm packages.
Core Babel and access to Babel:
-
babel-core
: the core compilation machinery and plugin infrastructure for Babel. You will rarely need to install this package, because other packages such asbabel-cli
have it as a dependency, meaning that it will be automatically installed when they are installed. -
babel-cli
: a command line interface toBabel
. It includes the following commands: -
babel-doctor
detects common problems with your Babel installation.
exports.get = function(fn) { | |
var deferred = Q.defer(); | |
request('http://example.com', function(err, response) { | |
if (err) { | |
return deferred.reject(err); | |
} | |
if (response.statusCode !== 200) { | |
return deferred.reject(new Error(response.body || 'Response failed with code ' + response.statusCode)); |
{ | |
"a": 8.167, | |
"b": 1.492, | |
"c": 2.782, | |
"d": 4.253, | |
"e": 12.702, | |
"f": 2.228, | |
"g": 2.015, | |
"h": 6.094, | |
"i": 6.966, |
/** | |
* Generates number of random geolocation points given a center and a radius. | |
* @param {Object} center A JS object with lat and lng attributes. | |
* @param {number} radius Radius in meters. | |
* @param {number} count Number of points to generate. | |
* @return {array} Array of Objects with lat and lng attributes. | |
*/ | |
function generateRandomPoints(center, radius, count) { | |
var points = []; | |
for (var i=0; i<count; i++) { |