Skip to content

Instantly share code, notes, and snippets.

View paulmr's full-sized avatar

Paul Roberts paulmr

  • Guardian
  • London
View GitHub Profile
@paulmr
paulmr / index.html
Last active December 29, 2015 17:19
A simple starting point for experimenting with D3
<html>
<head>
<style type="text/css">
#canvas {
width: 200px;
height: 200px;
border: 1px dotted grey;
}
</style>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.3.10/d3.js" charset="utf-8"></script>
@paulmr
paulmr / gist:8043182
Last active December 31, 2015 20:49
Intercepting PDF link clicks to trigger an event.
(function () {
var elm, i, links = document.getElementsByTagName("a");
for (i = 0; i < links.length; i++) {
elm = links.item(i);
if (elm.href.match(".*\\.pdf$") && !elm.getAttribute("onClick")) {
elm.addEventListener("click", (function (href) {
return function (ev) {
ev.preventDefault();
_gaq.push(function () {
@paulmr
paulmr / gist:8400328
Last active January 3, 2016 03:09
useful callback function
function lcb(str) {
var count = 0;
return function() {
console.log(Date() + "[ " + str + " ]" + " count: " + (count++));
}
}
@paulmr
paulmr / ga_track.js
Created January 15, 2014 15:39
help to log google analytics tracking by temporarily replacing _gaq.push()
var _gaq = {};
_gaq.push = function () {
var args = [];
for (var i = 0; i < arguments.length; i++) {
if (Array.isArray(arguments[i])) {
args.push("[" + arguments[i].join(",") + "]");
} else {
args.push(arguments[i].toString());
}
}
@paulmr
paulmr / betterbox.js
Last active August 29, 2015 13:55
better checkboxes
function betterbox() {
var boxes = $(".betterbox");
function reconcile() {
var e = $(this);
$("#" + e.attr("data-targid")).val(e.is(":checked") ?
e.attr("data-yesval") : e.attr("data-noval"));
}
boxes.each(reconcile);
// locate and save the target
boxes.change(reconcile);
@paulmr
paulmr / deployupdate.vim
Created January 31, 2014 09:39
vim stuff for auto commit/pushing etc
function! DeployUpdate()
argdo write | Gwrite
Gcommit -m "Deploy-Update auto commit"
Git push
endfunction
nnoremap <leader>d :call DeployUpdate()<cr>
.arenamenu {
margin: 0;
padding: 0;
}
.arenamenu-item.level0 {
/* display: inline; */
}
.arenamenu {
margin: 0;
padding: 0;
}
.arenamenu-item.level0 {
/* display: inline; */
}
@paulmr
paulmr / sendMoreMoney.scala
Created September 15, 2015 15:46
After reading (this article)[http://blog.plover.com/prog/haskell/monad-search.html] about `do` notation in Haskell, I had a quick go at solving the problem with Scala list comprehensions.
val digits = (0 to 9).toList
def without[A](l: List[A], r: List[A]) =
l.filterNot(r.contains(_))
def makeNum(l: List[Int]): Int =
l.reduce(_ * 10 + _)
val res =
for {
@paulmr
paulmr / tail_rec.pl
Created October 8, 2015 09:10
Experimenting with tail recursion by implementing it manually in perl5, which it isn't automatically optimised.
use strict;
# simulate tail optimised recursion with goto
sub rec1 {
my $count = shift;
say "-> rec1 ($count)";
if($count > 0) { $_[0] = $count - 1; goto &rec1; }
# this doesn't get executed until the end : which so this sub wouldn't
# normally be elligable for tail recursion optimisation (in the sense that
# tail recursion here changes the execution behaviour).