Skip to content

Instantly share code, notes, and snippets.

View eastlondoner's full-sized avatar

Andrew Jefferson eastlondoner

View GitHub Profile
@eastlondoner
eastlondoner / mesos-dns.js
Last active July 26, 2016 08:28
Simple node "module" for doing marathon "service discovery"
Promise = require('bluebird');
resolveSrv = Promise.promisify(require('dns').resolveSrv);
function fetchMarathonServiceBaseUrl(serviceName){
var dns_url = ['_' + serviceName, "_tcp.marathon.mesos"].join('.');
return resolveSrv(dns_url).then(function(addresses){
// TODO: take an address at random ?
// should we use some logic to choose addresses?
var internalUrl = "http://" + addresses[0].name + ":" + addresses[0].port;
@eastlondoner
eastlondoner / endianness.js
Created July 22, 2016 21:11
Is this server big or little endian
var littleEndian = (function() {
var buffer = new ArrayBuffer(2);
new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
// Int16Array uses the platform's endianness.
return new Int16Array(buffer)[0] === 256;
})();
console.log(littleEndian ? 'little' : 'big');
@eastlondoner
eastlondoner / node-array.coffee
Last active July 22, 2016 21:35
make a float 32 array and save it to disk
fs = require 'fs'
toFloatArray = (list) ->
buffer = new ArrayBuffer(4 * list.length)
dataView = new DataView buffer
offset = 0
addNextValue = (value) ->
dataView.setFloat32 offset, value, true
offset += 4
addNextValue val for val in list
@eastlondoner
eastlondoner / .block
Last active October 17, 2017 21:21 — forked from mbostock/.block
Graph display from TSNE
license: gpl-3.0
@eastlondoner
eastlondoner / create.txt
Last active November 1, 2018 02:40
Create word2vec style graphs using cypher
call apoc.periodic.iterate('
load csv from "https://raw.githubusercontent.com/wess/iotr/master/lotr.txt" as row fieldterminator \'"\'
with row
unwind row as text
RETURN text','
WHERE text is not NULL
with reduce(t=tolower(text), delim in [",",".","!","?",\'"\',":",";","\'","-","#","*","(",")","[","]","/","`","and","the","not","but","for","with","from"] | replace(t,delim,"")) as normalized
// Remove all short words (length <2)
with [w in split(normalized," ") WHERE w IS NOT NULL and size(trim(w)) > 2 | trim(w)] as words
where words is not null and size(words) > 1
@eastlondoner
eastlondoner / neo4j-training.ipynb
Created November 6, 2018 13:50
Neo4J Training.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# start from golang image based on alpine-3.8
FROM golang:1.10-alpine3.8 AS dev-build
# add our cgo dependencies
RUN apk update && apk add --update ca-certificates cmake make g++ openssl-dev git curl pkgconfig
# clone seabolt-1.7.0 source code
RUN git clone -b v1.7.0 https://github.com/neo4j-drivers/seabolt.git /seabolt
# invoke cmake build and install artifacts - default location is /usr/local
RUN mkdir /seabolt/build
WORKDIR /seabolt/build
# CMAKE_INSTALL_LIBDIR=lib is a hack where we override default lib64 to lib to workaround a defect
@eastlondoner
eastlondoner / host.py
Last active May 5, 2019 16:51
LOAD CSV using local CSV file on any remote Neo4j Server with internet access
# PYTHON 3.6+ is required
from http.server import HTTPServer, SimpleHTTPRequestHandler
from functools import partial
import os
import time
import kthread
from pyngrok import ngrok
PORT = 8000
@eastlondoner
eastlondoner / numbers.csv
Created May 22, 2019 12:29
The numbers 1 to 10 as a csv
value text
1 one
2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
9 nine
@eastlondoner
eastlondoner / serve.sh
Last active May 22, 2019 14:34
Use whichever python version is available to start a simple http server that serves the current directory.
#!/usr/bin/env bash
set -e
# Example usage: `cd web && PORT=8000 ./serve.sh`
# Default to 8080 if no PORT is specified
PORT="${PORT:-8080}"
# Check which python major version is available and start a simple http server accordingly
if [[ "$(python -c 'import sys; print(sys.version_info[0])')" == "3"* ]]; then