Skip to content

Instantly share code, notes, and snippets.

View phil8192's full-sized avatar
🦇

Phil Stubbings phil8192

🦇
View GitHub Profile
@phil8192
phil8192 / red-tint.r
Created March 29, 2016 16:47
255 tints of red
# 255 tints of red
red_tint <- function(v) as.hexmode(bitwOr(0xff0000, bitwOr(bitwShiftL(v, 8), v)))
cols <- paste0("#", red_tint(1:255))
barplot(255:1, col=cols, border=cols)
@phil8192
phil8192 / web-server.rb
Created April 8, 2016 15:26
dummy webserver
require 'sinatra'
require 'json'
post '/*' do
puts JSON.pretty_generate(JSON.parse(request.body.read))
status 201
end
@phil8192
phil8192 / testgpu.py
Last active April 21, 2016 15:50
testgpu
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
@phil8192
phil8192 / rle-trickery.R
Created June 6, 2016 16:49
rle sequence replace
oi <- c(0,1,0,0,-1,0,0,1,0,-1,0,0,0,0,0,1,0,0,0,-1,0,0,0)
cs <- cumsum(oi)
# ^-- map: 0 1 1 1 0 0 0 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0
# ^-- to: 0 1 1 1 0 0 0 2 2 0 0 0 0 0 0 3 3 3 3 0 0 0 0
(rle.cumsum.trickery <- function(mask) {
rle1 <- rle(mask)
x <- rle1$values
rle1$values <- cumsum(x) * x
inverse.rle(rle1)
@phil8192
phil8192 / cumseq.R
Created June 9, 2016 12:29
cumulative sequence
##' cumulative sequence of sequence changes.
##'
##' assigns a cumulative sum to a sequential occurrence in a vector.
##'
##' @param x a vector containing sequences.
##' @return a vector containing change counts.
##' @author phil
##' @examples
##'
##' my.seq <- c(6, 6, 6, 20, 20, 5, 3, 3, 3, 3, 6, 6)
@phil8192
phil8192 / bng2wgs85.py
Created April 12, 2017 14:16
BNG to WGS84
# http://www.bgs.ac.uk/data/webservices/convertForm.cfm#convertToLatLng
import pyproj
x, y = (383772, 800512)
p1 = pyproj.Proj(init='EPSG:27700')
p2 = pyproj.Proj(init='EPSG:4326')
lng, lat = pyproj.transform(p1, p2, x, y)

Keybase proof

I hereby claim:

To claim this, I am signing this object:

#!/bin/bash
curl -s "https://www.buscms.com/api/REST/html/departureboard.aspx?clientid=CardiffBus&stopid=14302" \
|sed 's/.*data-departureTime//; s/<.*//; s/.*>//'
@phil8192
phil8192 / gource_combo.sh
Last active December 16, 2021 01:41
gource video
#!/bin/bash
## combine and clean logs ready for gource
## https://github.com/acaudwell/Gource/wiki/Visualizing-Multiple-Repositories
# user/org repo location
src="https://github.com/phil8192"
# some repos to combine...
repos=("ob-analytics" "limit-order-book" "shiny-ob-analytics" "tsp-java" \
"ticker" "image-evolution" "tsp-lisp" "dithering-algorithms" \
@phil8192
phil8192 / gource_video.sh
Last active September 7, 2018 16:16
make gource video
#!/bin/bash
## make gource video from gource logfile.
# tmp output location. this example will need 13G free.
OUT_PPM="/mnt/raid/phil/out.ppm"
# result
OUT_MP4="dump.mp4"
# dump to $OUT_PPM
gource -1280x720 --camera-mode track --hide progress --output-ppm-stream $OUT_PPM \