Skip to content

Instantly share code, notes, and snippets.

View giacecco's full-sized avatar

Gianfranco Cecconi giacecco

View GitHub Profile
@giacecco
giacecco / R interactive session
Last active September 9, 2016 14:53
Open Addresses UK - Basic inference example
> library(dplyr)
> # I read the ZE postcode area data from the Open Addresses UK 'split'
> # CSV distro
> oa <- read.csv("~/Downloads/2014-12-10-openaddressesuk-addresses-only-split.csv/ZE.csv", stringsAsFactors=FALSE)
> # I drop the addresses whose Primary Addressable Objects (PAO) can't be
> # interpreted as numbers
> oa$pao <- as.integer(oa$pao)
Warning message:
NAs introduced by coercion
> oa <- oa[!is.na(oa$pao),]
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'install' ]
2 info using npm@2.14.9
3 info using node@v0.12.10
4 verbose node symlink /usr/bin/node
5 verbose readDependencies loading dependencies from /opt/package.json
6 warn package.json dicoim-main-website@0.0.1 No README data
7 verbose install where, deps [ '/opt', [ 'express' ] ]
8 verbose install where, peers [ '/opt', [] ]
9 verbose installManyTop reading for lifecycle /opt/package.json
@giacecco
giacecco / example.txt
Last active December 27, 2015 02:09
To reproduce the bug described in issue 23 https://github.com/soldair/node-qrcode/issues/23 in soldair/node-qrcode
Ode to Autumn
by John Keats
Season of mists and mellow fruitfulness,
Close bosom-friend of the maturing sun;
Conspiring with him how to load and bless
With fruit the vines that round the thatch-eaves run;
To bend with apples the moss'd cottage-trees,
And fill all fruit with ripeness to the core;
To swell the gourd, and plump the hazel shells
@giacecco
giacecco / package.json
Created October 30, 2013 15:16
Strange behaviour of node-canvas that I can't understand. I expect this code to write 10 .png files each of which contains a "Page [n]" text. Instead, I get one .png only called page11.png (??? the last should be 10) with "Page 8" in it! There must be something about timing that I am missing.
{
"name": "test",
"version": "0.0.1",
"author": "Gianfranco Cecconi <gianfranco.cecconi@digitalcontraptionsimaginarium.co.uk>",
"description": "Does what it says on the tin",
"contributors": [
{
"name": "Gianfranco Cecconi",
"email": "gianfranco.cecconi@digitalcontraptionsimaginarium.co.uk"
}
[EMPTY FOLDER!]
@giacecco
giacecco / The non-vectorised function
Last active December 25, 2015 18:59
Problem: I would like to write a vectorised version of 'findClosestOutputArea' below, so that I could do something like: incidents$outputAreaGridId <- findClosestOutputAreaVectorised(incidents$davetazLongitude, incidents$davetazLatitude)$gridId 'spDistsN1' comes from package sp http://cran.r-project.org/web/packages/sp/sp.pdf and calculates the …
findClosestOutputArea <- function (incident) {
distances <- spDistsN1(data.matrix(outputAreas[, c('longitudeCentre', 'latitudeCentre')]), matrix(c(incident$davetazLongitude, incident$davetazLatitude), nrow = 1, ncol = 2, byrow = TRUE), longlat = TRUE)
outputAreas[match(min(distances), distances), ]
}
@giacecco
giacecco / Output
Last active December 24, 2015 23:48
Checking Telefonica's 9 - 15 December 2012 data for completeness...
> checkFootfallCompleteness2()
[1] "The total number of grid id areas referenced in the file is 23152"
[1] "Checking 10/12/2012"
[1] "The missing areas are"
[1] "1122333312233" "1122333312341" "1122333312344" "1122333312432" "1122333321343"
[1] "Checking 11/12/2012"
[1] "The missing areas are"
[1] "1122333312341" "1122333312343" "1122333312344" "1122333312432" "1122333313212" "1122333321343"
[7] "1122333432334"
[1] "Checking 12/12/2012"
@giacecco
giacecco / The original function by Chris Veness, made into a standalone script for testing
Last active December 24, 2015 05:39
Testing consistency between dbamber/UkGeoTool (https://github.com/dbamber/UkGeoTool) and the source by Chris Veness (http://www.movable-type.co.uk/scripts/latlong-gridref.html). With easting 510350 / northing 179950 as an input, the first function outputs { latitude: 51.50721000898611, longitude: -0.40978487356944765 } , while the second { lat: …
// Source http://www.movable-type.co.uk/scripts/latlong-gridref.html
Number.prototype.toDeg = function() { // convert radians to degrees (signed)
return this * 180 / Math.PI;
}
osGridToLatLong = function(gridref) {
var E = gridref.easting;
var N = gridref.northing;
HOMEBREW_VERSION: 0.9.4
ORIGIN: https://github.com/mxcl/homebrew
HEAD: 72ee11d988eff7e4af82eec813381f3f82950b08
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: 8-core 64-bit ivybridge
OS X: 10.8.4-x86_64
Xcode: 4.6.3
CLT: 4.6.0.0.1.1365549073
LLVM-GCC: build 2336
@giacecco
giacecco / gist:6371150
Created August 28, 2013 20:55
Crash of example 2 at https://code.google.com/p/python-tesseract/ after a fresh install of python-tesseract
Process: Python [39969]
Path: /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Identifier: Python
Version: 2.7.5 (2.7.5)
Code Type: X86-64 (Native)
Parent Process: bash [96576]
User ID: 503
Date/Time: 2013-08-28 21:55:40.720 +0100
OS Version: Mac OS X 10.8.4 (12E55)