Skip to content

Instantly share code, notes, and snippets.

@hfs
hfs / git-repo-stats.sh
Created February 16, 2018 08:48
Git statistics for repository per author: Get number of changed files, inserted and deleted lines
#!/bin/sh
git log --shortstat | perl -ne 'chomp; $author = $1 if m/^Author: (.*)/; if (m/(\d+) files? changed, (\d+) insertions.* (\d+) deletions/){ $files{$author} += $1; $insertions{$author} += $2; $deletions{$author} += $3 }; END { foreach $author (sort { $files{$b} <=> $files{$a} } keys %files) {printf("%s: %d files, %d insertions(+), %d deletions(-)\n", $author, $files{$author}, $insertions{$author}, $deletions{$author})}}'
@hfs
hfs / pcniter.py
Created January 30, 2018 15:52 — forked from mortenpi/pcniter.py
Previous / current / next iterator in Python 3
def previous_current_next(iterable):
"""Make an iterator that yields an (previous, current, next) tuple per element.
Returns None if the value does not make sense (i.e. previous before
first and next after last).
"""
iterable=iter(iterable)
prv = None
try:
cur = next(iterable)
@hfs
hfs / mpd-remove-duplicates.sh
Created December 19, 2017 20:06
Remove duplicates (by file path) from the MPD playlist
#!/bin/sh
# Remove duplicates from MPD playlist.
# Export MPD_HOST and MPD_PORT if you want to connect to a different host.
mpc playlist -f '%position%\t%file%' | sort -k 2 | perl -ne 'm/(.*)\t(.*)/; print "$1\n" if $2 eq $prev; $prev=$2' | mpc del
@hfs
hfs / csv2xlsx.sh
Created November 21, 2017 13:28
Convert CSV files with comma separator and US English decimal separator into Excel format using Libre Office
#!/bin/sh
# Convert CSV files into Excel format
# See
# https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options#Filter_Options_for_the_CSV_Filter
#
# 44 = ASCII code of »,«
# 34 = ASCII code of »"«
# UTF-8 input encoding
# 1 = Start in line 1 = first line
# Empty column options = import all as “Standard” formatted
@hfs
hfs / unused_databases.sql
Created June 9, 2017 08:26
PostgreSQL: List databases with no current activity
-- Show databases with no current connections
--
-- BIG FAT WARNING: Don't trust this blindly! Just because there's no *current*
-- activity does not mean a database is no longer needed.
--
SELECT
(pg_stat_file ('base/' || d.oid || '/PG_VERSION')).modification,
d.datname,
pg_size_pretty(pg_database_size(d.datname)) AS size
FROM pg_database d
@hfs
hfs / jira_remove_watches.py
Created March 23, 2017 11:19
JIRA: Unwatch all issues
#!/usr/bin/env python
import json
import requests
JIRA_URL = 'https://JIRA base URL' #Fill in your JIRA Root
WebSession = requests.Session()
WebSession.auth = ('username','password') #JIRA Credentials go here, Optionally use Base64 Encode/Decode
WebParams = {'jql':'watcher = currentUser()', 'fields':'key,summary', 'maxResults':'9999'} #You can use basically any JIRA search query here in the JQL parameter
@hfs
hfs / find.sh
Created March 23, 2017 09:47
find: Ignore some directories
find . -type d -name target -prune -o -type f -name "*.xml" -path "*/src/main/resources/*" -exec grep -i --color=yes stuff '{}' +
@hfs
hfs / Hdf5Test.java
Created March 6, 2017 08:45
Sample Java code to read a HDF5 file and dump some of the contained metadata
import java.io.IOException;
import ucar.nc2.Attribute;
import ucar.nc2.Group;
import ucar.nc2.NetcdfFile;
import ucar.nc2.Variable;
import ucar.nc2.iosp.hdf5.H5iosp;
import ucar.nc2.util.DebugFlags;
/**
@hfs
hfs / JndiDnsTest.java
Created March 6, 2017 08:41
Test DNS resolution via JNDI from the command line
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
@hfs
hfs / colortable256.pl
Created March 6, 2017 08:33
Generate a rainbow color table with 256 entries as CSS
#!/usr/bin/perl
use POSIX;
use strict;
sub hsv2rgb {
my ( $h, $s, $v ) = @_;
if ( $s == 0 ) {
return $v, $v, $v;