Skip to content

Instantly share code, notes, and snippets.

View blahah's full-sized avatar

Rik Smith-Unna blahah

  • upward spiral ∞⟨X∴↯⟩∞
  • Bristol / Berlin / Nairobi
  • X @blahah404
View GitHub Profile
@blahah
blahah / nest-elife-json.sh
Last active April 9, 2017 15:18
move elife json into nested directories based on ID
for json in $(ls *.json); do
splitdir=$(echo $json | sed -e 's/elife-\([0-9]\{5\}\)-v[0-9]\.json/\1/' -e 's/\(.\)/\1\//g')
echo moving $json to $splitdir
mkdir -p $splitdir
mv $json $splitdir/
done
@blahah
blahah / crossref-sample-jats.sh
Last active April 8, 2017 16:23
get CC-BY 3 or 4 papers from CrossRef that have XML fulltext available (example URLs / bash pipelines)
# get count of fulltext XML papers by license
http://api.crossref.org/v1/works?filter=has-full-text:true,full-text.type:text/xml&facet=t
# for a given license, get count of publishers, e.g.
http://api.crossref.org/v1/works?filter=has-full-text:true,full-text.type:text/xml,license.url:http://creativecommons.org/licenses/by/3.0/&facet=t
# for a given license and publisher, get the first 10 papers URLs and download them, e.g.
URL = "http://api.crossref.org/v1/works?filter=has-full-text:true,full-text.type:text/xml,license.url:http://creativecommons.org/licenses/by/3.0/,publisher-name:Elsevier BV&rows=10"
curl $URL | jq ".message.items[].link[].URL" | grep 'text\/xml' | wget
@blahah
blahah / readdir_sync.js
Created April 6, 2017 20:22
hyperdrive v8 readdir behaviour check
const hyperdrive = require('hyperdrive')
const discover = require('hyperdiscovery')
const key = '33fcb3ea86942f913240d3f39c7c68f81fc2bdefc65cb56646d52a62a90bdec9'
const drive = hyperdrive('.', '')
drive.once('ready', () => {
driveswarm = discover(drive)
drive.once('content', () => {
for dir in $(ls); do
splitdir=$(echo $dir | sed -e 's/\(.\)/\1\//g' -e 's/\/$//')
echo $dir to $splitdir
mkdir -p $splitdir
mv $dir/* $splitdir
rmdir $dir
done
@blahah
blahah / run.js
Last active December 4, 2016 20:28
hyperdrive + pages usage
const level = require('level')
const hyperdrive = require('hyperdrive')
const discover = require('hyperdiscovery')
const pages = require('random-access-page-files')
const key = '154624e28aabcdf52625769f7b42361b4f7dafe53a14d27035d9ea9878262e16'
const drive = hyperdrive(level('./test_pages.hd'))
const archive = drive.createArchive(
@blahah
blahah / dat.sh
Last active November 5, 2016 17:02
install dat on a digitalocean droplet (fixing npm permissions issues)
# if you try to install dat on a digitalocean droplet you usually get an error like:
# sh: 1: prebuild: Permission denied
#
# this is caused by several intersecting facts:
# - digitalocean droplets, by default, only expose a root user for login
# - most node setup methods will create a node install that isn't owned by root
# - npm uses an 'undefined' user for installation
#
# and is solved in the following way:
# - taking root ownership of the node install and library install directory tree (with `chown`)

Let’s hypothesize that I have the magical ability to open a connection to any web server, and that every key press I make on my keyboard will be sent to the remote computer. I want to get the Google homepage, so I connect to one of their many web servers.

If the server spoke English, I might type:

Hello!  Please give me the content located at the path /
on the domain www.google.com.
I'm using the Chrome web browser, version 26.
I would like to receive the content as HTML,
zipped to save bandwidth,
@blahah
blahah / index.js
Created June 30, 2016 11:16
use the unified / rehype / retext ecosystem to extract enriched keywords from each article in a corpus of JATS XML articles
var fs = require('fs')
var unified = require('unified')
var parseHTML = require('rehype-parse')
var visit = require('unist-util-visit')
var findAfter = require('unist-util-find-after')
var file = '/Users/rds45/.sciencefair/data/elife_dws2/articles/01096/elife-01096-v1.xml'
var getBody = function () {
@blahah
blahah / email.md
Last active June 25, 2016 17:32
Letter to my MP (Alan Haselhurst) requesting block of EU withdrawal

Dear Sir Alan,

My partner Steph and I run a successful scientific software business from our house in Saffron Walden. We have a son who is approaching his first birthday. We are both Cambridge-educated scientists. We are appalled by the prospect of the UK withdrawing from the EU, and want to implore you to do anything in your power to help prevent it.

As I understand it, parliament must ultimately decide on whether to trigger Article 50 of the Lisbon Treaty in order to initiate withdrawal.

My first request is that you vote against withdrawal and against triggering of Article 50. Reasons for doing so are abundant. To highlight a few:

  • The world economy has clearly judged that Brexit would be a terrible idea. The pound has tanked, many British companies have lost unprecedented market capitalisation, and the Bank of England is having to resort to devaluing the pound in order to try to stabilise markets. Financial firms are already starting to move thousands of staff overseas.
  • Other EU leaders have ma
@blahah
blahah / response_to_wiley_fake_dois.md
Last active March 19, 2025 22:55
Reply to Wiley's claim that they "do not create fake DOIs"