Skip to content

Instantly share code, notes, and snippets.

View xkr47's full-sized avatar

Jonas Berlin xkr47

View GitHub Profile
@xkr47
xkr47 / message.js
Last active August 23, 2019 04:38
keybase ephemeral message test
// rendition of a message "test" set to expire in 30 seconds, as retrieved by json api after "exploding":
// $ keybase chat api -p -m '{"method": "read", "params": {"options": {"channel": {"name": "keybasefriends", "members_type": "team", "topic_name": "general", "pagination": {"num": 1}}}}}'
{
"msg": {
"id": 52853,
"conversation_id": "0000d5ba71470610a40b4d32af53a52775cc561589525d7b21bad9ec057b6aac",
"channel": {
"name": "keybasefriends",
"public": false,
"members_type": "team",
@xkr47
xkr47 / ot-poi.txt
Last active June 9, 2019 19:36
Handy queries for Overpass Turbo - https://overpass-turbo.eu
// Handy search for POI objects - just swap `shop=kiosk` out for any `key=value` osm tag
(
node[shop=kiosk]({{bbox}});
way[shop=kiosk]({{bbox}});
rel[shop=kiosk]({{bbox}});
);
(._;>;);
out;
@xkr47
xkr47 / StartTomcat.java
Last active May 13, 2019 10:33
Make Tomcat shut down automatically if any component fails to start up (written for tomcat version 7.0.47)
import static org.apache.catalina.Lifecycle.*;
import static org.apache.catalina.LifecycleState.*;
import org.apache.catalina.*;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;
// ...
tomcat.getServer().addLifecycleListener(new LifecycleListener() {
@Override
public void lifecycleEvent(final LifecycleEvent event) {
@xkr47
xkr47 / jsonmap
Last active October 26, 2018 08:52
My perl-based `jq` replacement
echo -n '{"a":5,"b":7}' | jsonmap -r '$_->{"a"}." and ".$_->{"b"}'
#!/usr/bin/perl
# usage: $0 [options] <perlcode> [<inputfile>]
#
# reads json from stdin/inputfile, or if -R given, reads whole input as a string
# perlcode gets the json/string as a perl object in $_
# return object from perlcode is encoded as json to stdout, or passed as-is if -r given
# pretty-printed by default, -c for compact
# all input/output is in UTF-8
@xkr47
xkr47 / README.md
Last active September 11, 2018 11:37
Handy script for generating a github "diff" url between two refs

Example:

$ github-diff origin/master 04ed4b
https://github.com/example/repo/compare/a418bcece3d540ad1d4864030635c2d4ae2628b3...04ed4b34bee0a2b2003f3744b772473a4c8b604b

Requires the commits to be available locally, so you might have to git fetch first.

@xkr47
xkr47 / README.md
Last active August 9, 2018 09:31
Using IntelliJ UI Designer for creating Swing forms in the Ceylon (1.3.0) language

I wanted to create a Swing app in Ceylon and figured I'd give using the UI designer a shot. Here are the necessary steps to get it to work:

Steps

Change IDEA settings

  • From the menu: File -> Settings
  • Navigate to Editor / GUI designer
  • Make sure "Generate GUI into:" has Java source code selected
  • Change "Default accessibility for UI-bound fields:" is something else than "private", for example package-private
  • Click OK to save
@xkr47
xkr47 / setup-readonly-git-remote-with-checkout
Last active July 6, 2018 20:39
How to set up a remote (non-bare) Git repository with read-only checkout of some branch to automatically update on push. This assumes you have already created a regular repository in the remote location already; typically just "git init".
cat > .git/hooks/post-receive <<EOF
#!/bin/bash
set -e
cd ..
unset GIT_DIR
git reset --hard HEAD --
# put any additional cleanup/reload commands here
EOF
chmod ug+rx .git/hooks/post-receive
@xkr47
xkr47 / gist:d0a1706f960c59648218
Last active April 24, 2018 04:29
Forward X DISPLAY over "sudo su - <user>", for example after ssh:ing to server
username=<user> ; echo -n "xauth add `xauth list :${DISPLAY#*:}`" | sudo su - $username ; sudo su - $username ; echo -n "xauth remove :${DISPLAY#*:}" | sudo su - $username
@xkr47
xkr47 / README.md
Last active March 30, 2018 19:57
Ceylon Web Runner: game_of_hny.ceylon
@xkr47
xkr47 / README.md
Last active September 28, 2017 07:59
git tweak-index - tweak/edit files in index without touching the checked out versions

git tweak-index

This git add-on command lets you tweak/edit files in the index/stage directly without touching the checked out working copy.

  • Use case 1: So you accidentally git-added some changes that you didn't want to merge just yet and would like to partially undo?
  • Use case 2: You want to make a quick commit to some file(s) but keep the checked out version(s) as-is?
  • Use case 3: You have been trying to use git reset -p but failed spectacularly?
  • Use case 4: You want to stage something that is not an interpolation of the checked out and the committed version?

Installation