Skip to content

Instantly share code, notes, and snippets.

@henrik242
henrik242 / java2kt2java.sh
Last active Jan 11, 2019
Preliminary work that commits renames of .java files to .kt, and renames them back to prepare for IntelliJ code conversion
View java2kt2java.sh
#!/usr/bin/env bash
set -o errexit -o pipefail -o nounset
if [[ $# -eq 0 ]]; then
echo "Usage: $0 someclass.java [someotherclass.groovy ...]"
exit 1
fi
printf "\n\nMoving files with git\n\n"
@henrik242
henrik242 / solrcloud-backup-and-restore.sh
Last active Dec 5, 2018
SolrCloud backup/restore without shared disk
View solrcloud-backup-and-restore.sh
#!/usr/bin/env bash
# https://lucene.apache.org/solr/guide/7_5/making-and-restoring-backups.html explains that
# SolrCloud Backup/Restore requires a shared file system mounted at the same path on all nodes.
#
# This script uses the old Solr Backup/Restore procedure, which is useful if you don't have
# access to a shared disk.
#
# Requires that the target collection is already set up, with identical number of shards/replicas.
@henrik242
henrik242 / run-script-on-startup.command
Last active Oct 12, 2018
Run shell command in background upon macOS login, using tmux
View run-script-on-startup.command
#!/usr/bin/env bash
#
# Make this file executable with `chmod +x run-script-in-background.command`, and add it to
# System Preferences --> Users and Groups --> Startup Items. It needs to have the `.command` suffix.
#
tmux new-session -d -s ostepop \; send -t ostepop.0 "echo Let\'s do this\!; echo More stuff." ENTER
View keybase.md

Keybase proof

I hereby claim:

  • I am henrik242 on github.
  • I am hnrk242 (https://keybase.io/hnrk242) on keybase.
  • I have a public key ASBdZ40ASLGCs4Irw_zD4pJHgpR4M7t3AXGTyNp1WXFHiwo

To claim this, I am signing this object:

@henrik242
henrik242 / Activate OSX Screensaver With Hotkey.md
Last active Dec 14, 2017
MacOSX hotkey for locking screen by starting screensaver
View Activate OSX Screensaver With Hotkey.md

You can usually lock the screen by hitting ctrl-shift-power, but that will power down external monitors, which might take several boring seconds to start up again. Also, a MacBook with a TouchBar doesn't have the power button anymore. With the following guide you can lock the screen by starting the screensaver, keeping the monitors running.

Preparations

Set System Preferences » Security & Privacy » General » Require password immediately after sleep...

The simple way

  1. Download enable-screensaver.zip and unzip it to $HOME/Library/Services/
@henrik242
henrik242 / HttpStuff.java
Last active Mar 2, 2017
HTTP POST and GET in plain Java
View HttpStuff.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"));
@henrik242
henrik242 / groovy
Created Aug 3, 2016
Poor man's /usr/bin/groovy
View 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 / pingstats.sh
Last active Apr 19, 2016
A little script to monitor my network connection
View pingstats.sh
#!/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 / commit-msg
Last active Mar 30, 2016
Git hook to automatically create JIRA issues if not present in commit message
View commit-msg
#!/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
#
You can’t perform that action at this time.