Skip to content

Instantly share code, notes, and snippets.

@henrik242
henrik242 / p4merge
Last active January 5, 2023 22:23
Helper script for p4merge and Git on MacOSX
#!/bin/bash
for arg; do [[ $arg = /* ]] || arg=$PWD/$arg; absargs+=("$arg"); done;
/Applications/P4Merge.app/Contents/Resources/launchp4merge "${absargs[@]}"
@henrik242
henrik242 / DisableCertificateValidation.java
Created December 22, 2011 12:37
Disable validation of SSL certificates in Java
public static void disableCertificateValidation() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
}};
@henrik242
henrik242 / surf-control.sh
Created February 17, 2012 14:40
Productivity improving firewall script for MacOSX / BSD
#!/bin/bash
##
## Requires pwgen, wc, sed, host, ipfw, sudo
##
HOSTS="last.fm www.discogs.com www.facebook.com facebook.com
macrumors.com dealextreme.com www.dealextreme.com db.no www.db.no
vg.no www.vg.no aftenposten.no www.aftenposten.no amazon.com
www.amazon.com"
@henrik242
henrik242 / Target monitor selector for XBMC.md
Last active September 26, 2017 12:57
Target monitor selector for XBMC

Target monitor selector for XBMC

I have a TV and a projector connected to my Mac Mini media center, and can choose either screen by using these scripts.

The scripts overwrite advancedsettings.xml in XBMC's userdata folder. I got the required data by configuring XBMC for each target screen, and diffing the resulting guisettings.xml files afterwards.

My Samsung 1080p LED TV needs a -250 ms audio delay, and is the main display. It's hooked up to the Mini DisplayPort output.

@henrik242
henrik242 / check-ssl-expiry.sh
Last active December 17, 2015 18:49
Checks for upcoming expiry of SSL certificates, e.g. HTTPS or LDAPS. Useful for cron jobs and server monitoring.
#!/bin/bash
SERVER=my.example.com:443
WARNDAYS=30
EXPIRE=$(openssl s_client -connect $SERVER 2>/dev/null </dev/null | openssl x509 -noout -enddate | cut -d= -f2)
DAYS=$((( $(date --date "${EXPIRE}" +%s) - $(date +%s) ) / 86400));
[ $DAYS -lt $WARNDAYS ] && echo "WARNING: SSL certificate for $SERVER expires in $DAYS days"
#!/bin/bash
if [ $# -lt 3 ]; then
echo "Usage: maven-deploy-file groupId artifactId version [packaging] [repository]"
exit 1
fi
GROUP=$1
ARTIFACT=$2
VERSION=$3
@henrik242
henrik242 / commit-msg
Last active March 30, 2016 07:40
Git hook to automatically create JIRA issues if not present in commit message
#!/usr/bin/env bash
#
# How to install:
#
# cp commit-msg your-project/.git/hooks/
# chmod 755 your-project/.git/hooks/commit-msg
#
# Then update the USER, PASS, PROJECT and JIRAURL variables in your-project/.git/hooks/commit-msg
#
@henrik242
henrik242 / pingstats.sh
Last active April 19, 2016 08:19
A little script to monitor my network connection
#!/bin/bash
# Add to crontab, e.g.:
#
# * * * * * $HOME/cron/pingstats.sh
IP1=84.xx.20.yy
IP2=129.xx.30.yy
IP3=84.xx.64.yy
@henrik242
henrik242 / groovy
Created August 3, 2016 08:50
Poor man's /usr/bin/groovy
#!/usr/bin/env bash
# poor man's /usr/bin/groovy :)
if test -x "$(which java)"; then
JAVAEXEC="$(which java)"
elif test -x "$JAVA_HOME/bin/java"; then
JAVAEXEC="$JAVA_HOME/bin/java"
else
echo "ERROR: Could not find java binary"
@henrik242
henrik242 / HttpStuff.java
Last active March 2, 2017 12:07
HTTP POST and GET in plain Java
import java.io.*;
import java.net.*;
import java.util.Scanner;
import static java.nio.charset.StandardCharsets.UTF_8;
public class HttpStuff {
public static void main(String[] args) throws IOException {
System.out.println(post("http://example.com/", "foo=bar&baz=moo"));