Skip to content

Instantly share code, notes, and snippets.

View phil8192's full-sized avatar
🦇

Phil Stubbings phil8192

🦇
View GitHub Profile
def sample(x):
"""
1
2 3
4 5 6 7
=
4 2 6 1 3 5 7
>>> list(sample(['a', 'b', 'c', 'd', 'e', 'f', 'g']))
[('d', 1), ('b', 2), ('f', 2), ('a', 3), ('c', 3), ('e', 3), ('g', 3)]
"""
# desired matrix:
# 1 1
# 1 2
# 1 3
# 2 1
# 2 2
# 2 3
# 2 4
# 3 1
# 3 2
@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 \
@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" \
#!/bin/bash
curl -s "https://www.buscms.com/api/REST/html/departureboard.aspx?clientid=CardiffBus&stopid=14302" \
|sed 's/.*data-departureTime//; s/<.*//; s/.*>//'

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@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)
@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 / 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 / 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))