Skip to content

Instantly share code, notes, and snippets.

@ephemient
ephemient / robolectric-jars⁄build.gradle.kts
Last active July 12, 2023 13:27
Download Robolectric jars using Gradle
// see org.robolectric.plugins.DefaultSdkProvider
enum class Sdk(val apiLevel: Int, val androidVersion: String, val robolectricVersion: String) {
JELLY_BEAN(16, "4.1.2_r1", "r1"),
JELLY_BEAN_MR1(17, "4.2.2_r1.2", "r1"),
JELLY_BEAN_MR2(18, "4.3_r2", "r1"),
KITKAT(19, "4.4_r1", "r2"),
LOLLIPOP(21, "5.0.2_r3", "r0"),
LOLLIPOP_MR1(22, "5.1.1_r9", "r2"),
M(23, "6.0.1_r3", "r1"),
N(24, "7.0.0_r1", "r1"),
@ephemient
ephemient / example.hs
Created December 30, 2019 08:50
A forkIO'ed thread that is reading from the TTY cannot be killed?
#!/usr/bin/env stack
-- stack script --resolver lts --package unix
module Main where
import Control.Concurrent
import Control.Concurrent.MVar
import System.Posix
main :: IO ()
main = do
@ephemient
ephemient / pty-example.hs
Created December 30, 2019 08:28
How to fake forkpty without posix-pty
#!/usr/bin/env stack
-- stack script --resolver lts --package "ioctl monad-loops process unix"
{-# LANGUAGE CPP, MultiParamTypeClasses, NondecreasingIndentation #-}
module Main where
import Control.Concurrent (forkFinally, killThread)
import Control.Concurrent.MVar (newEmptyMVar, takeMVar, tryPutMVar)
import Control.Exception (bracket, catchJust, finally)
import Control.Monad (void, when)
import Control.Monad.Fix (fix)
#include <stdlib.h>
#include <string.h>
static void swap(int *a, int *b) {
if (a != b) {
int c = *a;
*a = *b;
*b = c;
}
}
import android.content.Context
import android.graphics.Canvas
import android.graphics.Outline
import android.graphics.Path
import android.graphics.Rect
import android.graphics.Region
import android.graphics.drawable.Drawable
import android.graphics.drawable.LevelListDrawable
import android.os.Build
import android.util.AttributeSet
#!/bin/bash
set -euo pipefail
declare -r IFACE=${IFACE:-wg0}
declare -r CONFIG_FILE=${CONFIG_FILE:-/etc/systemd/network/90-${IFACE}.netdev}
declare -r BASE_TIME=${BASE_TIME:-$(date -d '5 minutes ago' +%s)}
declare -A PEERS=()
declare PEER_SECTION= PUBLIC_KEY= ENDPOINT=
@ephemient
ephemient / ⁄etc⁄systemd⁄system⁄x11chromoting@.service
Created December 13, 2018 20:34
Chrome Remote Desktop - DISPLAY=:0 sharing
[Unit]
Description=Chromoting Server for X11
Requires=display-manager.service
Wants=network-online.target user@%i.service
After=display-manager.service network-online.target
[Service]
User=%I
Group=chrome-remote-desktop
PermissionsStartOnly=true
@ephemient
ephemient / Advent of Code 2018.md
Last active December 29, 2018 07:33
my answers in Python
@ephemient
ephemient / sc.md
Created September 25, 2018 21:52
Sister cities

Source: Sister Cities of the World + Graphviz

7158 18672 2463 731 0.7578 198 0.8743

  • 7158 nodes
  • 18672 edges
  • 2463 connected components
  • 731 strongly connected components
  • 0.7578 fraction of nodes in a non-trivial strongly connected components
  • 198 maximum degree
#!/bin/bash
set -euo pipefail
inhibit() {
while { read -n1 -r -s -t30 || [[ $? -gt 128 ]]; } && [[ -z ${REPLY} ]]; do
dbus-send --session --dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SimulateUserActivity
done
}
if [[ $# -gt 0 ]]; then
coproc inhibit >&2
command "$@" {COPROC[0]}<&- {COPROC[1]}>&-