Skip to content

Instantly share code, notes, and snippets.

View mikehearn's full-sized avatar

Mike Hearn mikehearn

View GitHub Profile
@mikehearn
mikehearn / Scripts
Last active December 4, 2023 11:45
systemd unit monitoring setup
----------------------------------------------------
#!/usr/bin/env bash
# place in a file called email-unit-status.sh on the PATH
# requires you to have set /etc/admin-email to contain the address to receive the messages
# requires install of ansi2html
#
set -e
@mikehearn
mikehearn / plugin.xml
Created May 1, 2023 16:31
IntelliJ plugin xml for a kotlin scripting plugin
<idea-plugin>
<id>dev.hydraulic.hshell</id>
<name>Hydraulic Shell</name>
<vendor email="contact@hydraulic.software" url="https://hshell.hydraulic.dev">Hydraulic</vendor>
<description><![CDATA[
Hydraulic Shell is a replacement for shell scripting that uses Kotlin.
]]></description>
<depends>com.intellij.modules.platform</depends>
@mikehearn
mikehearn / gist:fdcb2c3ef30c6a2970d089fd8f860216
Created May 1, 2023 16:26
IntelliJ plugin to register a custom Kotlin scripting host
package hydraulic.hshell.intellij
import com.intellij.notification.NotificationGroupManager
import com.intellij.notification.NotificationType
import com.intellij.openapi.diagnostic.logger
import java.io.File
import java.io.IOException
import kotlin.script.experimental.intellij.ScriptDefinitionsProvider
private val LOG = logger<HShellDefinitionProvider>()
@mikehearn
mikehearn / Locker.kt
Created April 6, 2023 08:25
A class that makes it easy to wrap state such that it's only accessible when locked.
package hydraulic.kotlin.utils
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
/**
* A wrapper class that makes it harder to forget to take a lock before accessing some shared state.
*
* Simply define an anonymous object to hold the data that must be grouped under the same lock, and then pass it
@mikehearn
mikehearn / conveyor.conf
Created December 4, 2022 13:19
Config for GH Desktop (using GH Actions to prepare the resources dir)
// A config for Conveyor (https://conveyor.hydraulic.dev/) that creates a download site for GitHub Desktop.
// Shows how to package a real-world and sophisticated Electron app.
include required("/stdlib/electron/electron.conf")
// Import package.json files so we can avoid duplicating config. There are two in this project.
package-json {
include required("app/package.json")
}
#!/usr/bin/env hshell
// -------------------- Dependencies and imports ------------------------------------------------
//
// You can depend on Maven coordinates, they will be downloaded and cached in ~/.m2 automatically.
@file:DependsOn("com.github.ricksbrown:cowsay:1.0.0")
import com.github.ajalt.mordant.table.table
import com.github.ricksbrown.cowsay.Cowsay
import hydraulic.utils.os.runningOnWindows
// A server config for Conveyor: https://conveyor.hydraulic.dev/
// Import config from a Java build system (but you can get it from anywhere).
include required("#!gradle -q printConveyorConfig")
app {
vendor = Hydraulic
fsname = sample-server
machines = [linux.amd64.glibc] // Don't want packages for other platforms.
@mikehearn
mikehearn / teamcity.service
Created June 10, 2022 15:45
An example systemd service for TeamCity
[Unit]
After=postgresql.service
Description=JetBrains TeamCity
Requires=postgresql.service
Wants=network-online.target
# Can be included to allow a server to write to its own files.
[Service]
CacheDirectory=jetbrains/teamcity
ConfigurationDirectory=jetbrains/teamcity
package hydraulic.utils.config
import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.containsSubstring
import com.typesafe.config.Config
import com.typesafe.config.ConfigException
import com.typesafe.config.ConfigFactory
import com.typesafe.config.ConfigValueFactory
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNull
package hydraulic.utils.config
import com.natpryce.hamkrest.isBlank
import com.typesafe.config.*
import com.typesafe.config.ConfigException.BadValue
import hydraulic.kotlin.utils.text.camelToKebabCase
import hydraulic.utils.app.UserInput
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
import java.lang.reflect.WildcardType