Skip to content

Instantly share code, notes, and snippets.

@ches
ches / docker-entrypoint.sh
Created June 21, 2023 14:29
Java app Docker entrypoint script, with a simple JVM flags file
#!/bin/bash
# Contains a few particularities of $DAYJOB's infra environment, but you get the, erm, gist.
set -o errexit
declare -r app_jar=/opt/myapp/my-app.jar
declare -r consul_template_config=/etc/consul.d/template/config.json
declare -r flags_file="${JVM_FLAGS_FILE:=/etc/myapp/application.ini}"
# For JMX's weird connection negotiation in a container world
@ches
ches / CustomWartsPlugin.scala
Last active February 24, 2023 23:49
sbt mini-plugin for a tool needing compile-time only Maven dependencies, in this case custom WartRemover extension lints
import sbt._, Keys._
import wartremover.WartRemover, WartRemover.autoImport.wartremoverClasspaths
trait CustomWartsKeys {
lazy val customWartsVersion = settingKey[String]("Version of the my-warts library dependency")
}
/** sbt plugin to integrate a package of custom WartRemover extension lints into a project's build.
*
* The purpose of an sbt plugin for this is to solve a problem with WartRemover's [[$custom-warts
@ches
ches / rvm-prompt.sh
Created February 20, 2011 16:02
An example of a bash prompt showing RVM Ruby version and active gemset
RED="\[\033[01;31m\]"
GREEN="\[\033[01;32m\]"
COLOR_NONE="\[\033[0m\]"
function ruby_version {
if [[ -f ~/.rvm/bin/rvm-prompt ]]; then
local system=$(~/.rvm/bin/rvm-prompt s)
local interp=$(~/.rvm/bin/rvm-prompt i)
if [[ ! -n $system ]]; then
# Don't show interpreter if it's just MRI
@ches
ches / tasks.json
Last active April 21, 2021 14:50
A starter VS Code tasks.json file for Bloop, for Scala Metals projects
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "bloop: compile all",
"type": "shell",
"command": "bloop compile $(bloop projects)",
"group": { "kind": "build", "isDefault": true },
@ches
ches / install-pygtk.sh
Created July 20, 2011 11:34
Install PyGTK via Homebrew and virtualenv
# This LOOKS pretty straightforward, but it took awhile to sort out issues with
# py2cairo and pygobject, so I hope I've saved you some time :-)
#
# This assumes you already subscribe to a nice clean virtualenvwrapper workflow
# -- see https://gist.github.com/771394 if you need advice on getting there.
# There are some optional dependencies omitted, so if you're going to be doing
# heavy development with these libs, you may want to look into them.
#
# We go to some configure option pains to avoid polluting the system-level
# Python, and `brew link`ing Cairo which is keg-only by default.
@ches
ches / futureutils.scala
Created June 2, 2016 13:03
Extra Future combinators for Scala
import java.util.concurrent.atomic.AtomicInteger
import scala.collection.generic.CanBuildFrom
import scala.concurrent._
import scala.util.{ Failure, Success }
/*
* Enrichments for some useful Future combinators absent from the standard
* library.
*
@ches
ches / gist:243611
Created November 26, 2009 19:09 — forked from lukesutton/gist:107966
basic example of Warden authentication with Sinatra
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
@ches
ches / ExitStatus.scala
Created February 16, 2019 12:08
A cute little application exit status value class
import scala.language.implicitConversions
/** A process exit status. */
sealed abstract class ExitStatus(val code: Int) extends Product with Serializable
/** Exit statuses used conventionally across components. */
object ExitStatus {
case object Success extends ExitStatus(0)
case object Error extends ExitStatus(1)
case object BadUsage extends ExitStatus(2) // 2 is conventional, e.g. bash builtins, grep

Keybase proof

I hereby claim:

  • I am ches on github.
  • I am ches (https://keybase.io/ches) on keybase.
  • I have a public key ASCIZr7iDy6SDxfmm4ZmlI-IfCYak4OLkqMWqBI3lp8f7Qo

To claim this, I am signing this object:

@ches
ches / follow_observer_spec.rb
Last active November 29, 2018 01:34
Example of testing Rails observers in isolation for cross-cutting concerns
require 'spec_helper'
# Bustle is a pubsub system used for activity streams:
# https://github.com/fredwu/bustle
#
# Here when a person follows another (or a discussion, for instance), the observer wires
# up pubsub between them for future activity notifications. The Follow model knows nothing
# about the implementation choices for the pubsub system.
describe FollowObserver do
subject { FollowObserver.instance }