Skip to content

Instantly share code, notes, and snippets.

View mrmanc's full-sized avatar

Mark Crossfield mrmanc

View GitHub Profile
@mrmanc
mrmanc / gist:5bcbe80549393d1b9ea13c7b3e8974ac
Created May 29, 2016 22:17
JUnit test with multiple anonymous and separately scoped scenarios in one method
import org.junit.Rule;
import org.junit.rules.ErrorCollector;
import static org.assertj.core.api.Assertions.assertThat;
public class ReverseTest {
@Rule
public ErrorCollector collector = new ErrorCollector();
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>vending_machine_java_refuctored</artifactId>
<version>1.0-SNAPSHOT</version>

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@mrmanc
mrmanc / github-org-webhook-conversion.sh
Last active March 23, 2016 18:24
Very rudimentary script to convert the payload of a generic GitHub push event webhook to port 5637 into an API call to notify a Go CD material of an update. Not production ready… intended to be used as a test. You will need to set up a .netrc file in the home directory of the user running the script. https://curl.haxx.se/docs/manpage.html#-n
#!/bin/bash
while true; do
echo -e 'HTTP/1.1 200 OK\r\n' | nc -d -l 5637 | grep git_url | sed -e "s/^.*\(git:\/\/[^\"]*\)\".*$/\1/" | xargs -I {} curl -s --netrc 'https://go.atcloud.io/go/api/material/notify/git' -X POST -d "repository_url={}"
done
@mrmanc
mrmanc / blocked-traces.sh
Created January 5, 2016 10:17
Blocked operations in jstack output
/usr/java/default/bin/jstack $1 | grep -A1 "java.lang.Thread.State: BLOCKED" | grep -v ^-- | grep -v "java.lang.Thread.State: BLOCKED" | sort | uniq -c
@mrmanc
mrmanc / sample-jstat-output
Last active December 15, 2015 17:26
Some jstat output from ‘jstat -gc PID 1s’
S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT
271360.0 268800.0 0.0 215492.3 5035520.0 1933309.9 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2185976.4 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2304618.9 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2366035.2 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2488908.0 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2644544.6 11184640.0 2746005.2 524288.0 126285.0 11511 1654.373 181 185.540 1839.913
271360.0 268800.0 0.0 215492.3 5035520.0 2746552.0 11184640.0 2746005.2 524288.0 126285.0 115
@mrmanc
mrmanc / ImmutableMap.java
Created November 10, 2015 20:05
ImmutableMap with mapOf()
import java.util.Map;
public abstract class ImmutableMap {
private ImmutableMap() {}
public static <K, V> Map<K, V> mapOf(K k1, V v1) {
return com.google.common.collect.ImmutableMap.of(k1, v1);
}
public static <K, V> Map<K, V> mapOf(K k1, V v1, K k2, V v2) {
@mrmanc
mrmanc / whisper-calculator.py
Last active October 6, 2015 15:40 — forked from jjmaestro/whisper-calculator.py
whisper-calculator.py:Calculates the size of the whisper storage for the given retention (in frequency:history format)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def archive_to_bytes(archive):
def to_seconds(s):
SECONDS_IN_A = {
's': 1,
'm': 1 * 60,
'h': 1 * 60 * 60,
@mrmanc
mrmanc / xargs-apostrophe
Created November 24, 2014 15:16
Problem caused by apostrophe’s special meaning in xargs
In response to http://askubuntu.com/questions/80244/how-do-i-sort-by-human-readable-sizes-numerically/552976?noredirect=1#answer-552976
mark:~/dutest $ touch "a'b"
mark:~/dutest $ du -s * | sort -n | cut -f2
a'b
mark:~/dutest $ du -s * | sort -n | cut -f2 | xargs du -sh
xargs: unterminated quote
@mrmanc
mrmanc / osx-color-pcl
Last active February 16, 2024 15:48
Describes how to set up OS X to print in color to a PCL printer.
You need to have Foomatic-RIP and Ghostscript installed. You can find links to installers on this page: http://www.linuxfoundation.org/collaborate/workgroups/openprinting/macosx/pxlmono (alternatively you can install ghostscript using brew with ‘brew install ghostscript’). There is a pxlmono download on that page which contains loads of PPD files for all sorts of printers, but none of them support colour.
Once the dependencies are installed, you can use pxlcolor to generate a PPD file on this page for the printer, or generate a Generic PCL 6/PCL XL Printer PPD file (attached), which allows you to print with colour.
http://www.openprinting.org/driver/pxlcolor
Set the printer up using Cups. To do this you need to enable the web interface by running this from a Terminal prompt:
cupsctl WebInterface=yes
You can then browse Cups on http://localhost:631/printers/