Skip to content

Instantly share code, notes, and snippets.

View jvhaarst's full-sized avatar

Jan van Haarst jvhaarst

  • FB-IT, Wageningen University and Research
  • Wageningen, Netherlands
View GitHub Profile
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Pragma: no-cache");
function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
@jvhaarst
jvhaarst / movedigiphotos.bash
Last active December 12, 2022 22:02
Bash script to move images, based on exif data and file timestamp
#!/bin/bash
# Reads EXIF creation date from all .JPG files in the
# current directory and moves them carefully under
#
# $BASEDIR/YYYY/YYYY-MM/YYYY-MM-DD/
#
# ...where 'carefully' means that it does not overwrite
# differing files if they already exist and will not delete
# the original file if copying fails for some reason.
@jvhaarst
jvhaarst / gistmirror.sh
Last active October 9, 2022 09:32
Github mirror script, including organisation repos and gist mirror script.
#!/bin/bash
# Gist mirror script
# Jan van Haarst jan@vanhaarst.net
# 20150115
# Debug
#set -o xtrace
#set -o verbose
# Stop on error
@jvhaarst
jvhaarst / get_tree_size.py
Last active April 6, 2022 02:55
Simple script to print: human size of a directory tree, number of files in that tree, number of hard links in that tree, number of softlinks in that tree and number of directories.
#!/usr/bin/env python3
# Simple script to print:
# Size of a directory tree
# Number of files in that tree
# Number of hard links in that tree
# Number of softlinks in that tree
import os
import sys
import datetime
@jvhaarst
jvhaarst / ssh_alias.sh
Last active April 6, 2022 02:55
Script to create bash aliases for hostnames in ssh config and known_hosts files
#!/bin/bash
# Script to create bash aliases for hostnames in ssh config and known_hosts files
# Original fom http://samrowe.com/wordpress/2008/07/29/bash-ssh-happiness/
# Updated by ja@vanhaarst.net
# Example usage:
# ALIAS_TEMP=$(mktemp);bash ssh_alias.sh | sort -r > $ALIAS_TEMP;source $ALIAS_TEMP;rm $ALIAS_TEMP;alias
set -o errexit # Exit on error
set -o nounset # Exit on use of unset variable
#set -o verbose # Prints shell input lines as they are read.
@jvhaarst
jvhaarst / grab_days.ini.example
Last active April 18, 2021 08:17 — forked from tvdsluijs/slimmemeterportal.nl.py
Small script to get your energy data from the slimmemeterportal.nl
[DEFAULT]
login = [YOUR LOGIN]
password = [YOUR PASSWORD]
START_URL = https://slimmemeterportal.nl/login
LOGIN_URL = https://slimmemeterportal.nl/user_session
DOWNLOAD = [LOCATION TO STORE THE FILES]
@jvhaarst
jvhaarst / analyse.ipynb
Last active February 5, 2020 23:09
solar panel scrape and plot
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jvhaarst
jvhaarst / eta.ipynb
Last active January 17, 2020 16:47
A couple of analyses on sacct output (ETA and CPU usage)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jvhaarst
jvhaarst / split_subreads2dir.py
Created May 8, 2019 12:48
Simple script to split PacBio BAM file into subread files.
import os
import sys
import gzip
filetype="txt"
for line in sys.stdin:
# {movieName}/{holeNumber}/{qStart}_{qEnd} according to https://pacbiofileformats.readthedocs.io/en/3.0/BAM.html
(movieName,holeNumber,subread)=(line.split()[0].split('/'))
directory = movieName+'/'+holeNumber[:3]
@jvhaarst
jvhaarst / solar graph.ipynb
Created January 9, 2018 07:48
Use pysolar to create a solar graph.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.