Skip to content

Instantly share code, notes, and snippets.

View craiggoldstone's full-sized avatar

Craig Goldstone craiggoldstone

  • United Kingdom
View GitHub Profile
@craiggoldstone
craiggoldstone / logging.js
Created April 11, 2013 23:38
Async logging in Node.JS – JUST CHILL, WINSTON.
var winston = require('winston');
var fs = require('fs');
fs.mkdir('./logs', function(err) {
if (err) throw err;
});
// Define levels to be like log4j in java
var customLevels = {
levels: {
app.filter('capitalize', function() {
return function(input, scope) {
if (input!=null)
input = input.toLowerCase();
return input.substring(0,1).toUpperCase()+input.substring(1);
}
});
app.filter('bytes', function() {
return function(bytes, precision) {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
}
});
function transform(seconds) {
const times = {
year: 31557600,
month: 2629746,
day: 86400,
hour: 3600,
minute: 60,
second: 1
};
@craiggoldstone
craiggoldstone / index.js
Last active April 26, 2017 13:12
requirebin sketch
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
var JSONAPIDeserializer = require('jsonapi-serializer').Deserializer;
var jsonapi = {
"meta": {
"status": 200,
"message": "Farm data successfully deleted"
@craiggoldstone
craiggoldstone / style.json
Last active September 1, 2017 16:02 — forked from anonymous/style.json
Positron
{
"version": 8,
"name": "Positron",
"metadata": {
"mapbox:autocomposite": false,
"mapbox:type": "template",
"mapbox:groups": {
"b6371a3f2f5a9932464fa3867530a2e5": {
"name": "Transportation",
"collapsed": false