Skip to content

Instantly share code, notes, and snippets.

@jmbjorndalen
jmbjorndalen / minecraft_fix_java_timer.py
Created March 23, 2023 12:41
Hack to fix high idle CPU time for Minecraft servers on a Linux host
#!/usr/bin/env python3
"""
This is a quick hack that is intended to be used as a tool to help diagnose
high CPU usage by what should be an idle minecraft server.
Use with care! It may break things.
Needs to run as root to work.
The main problem is that Minecraft appears to be running parkNanos in a tight
loop with a very low timeout. Linux has higher precision timeouts by default
than, for instance, Windows. When this happens, you can observe that Minecraft
@jmbjorndalen
jmbjorndalen / asyncio_executors_threads_procs.py
Created April 26, 2018 08:10
Combining Python 3 asyncio coroutines with thread pool and process pool executors
#!/usr/bin/env python3
# Combining coroutines running in an asyncio event loop with
# blocking tasks in thread pool and process pool executors.
#
# Based on https://pymotw.com/3/asyncio/executors.html, but this version runs both
# threads and processes at the same time and interleaves them with asyncio coroutines.
#
# All appears to be working.
#
@jmbjorndalen
jmbjorndalen / pebble-time-kickstarter-info
Last active August 29, 2015 14:22
Quick and dirty tampermonkey hack to view some of the hidden information on the Pebble Time Kickstarter webpage
// ==UserScript==
// @name pebble kickstarter test
// @namespace http://your.homepage/
// @version 0.2
// @description Adds hidden tracking info to the kickstarter page (and logs it to the js console)
// @author John Markus Bjørndalen
// @match https://kickstarter.getpebble.com/pledges/*
// @grant none
// ==/UserScript==
events.damage(function(event) {
// Wearing a pumpkin on your head protects you from fall damage
var src = event.getDamageSource();
if (src.getDamagetype() == Packages.net.canarymod.api.DamageType.FALL) {
var def = event.getDefender()
var isPlayer = (def instanceof Packages.net.canarymod.api.entity.living.humanoid.Player);
if (isPlayer) {
var inv = def.getInventory();
var head = inv.getSlot(39);
if (head) {