Skip to content

Instantly share code, notes, and snippets.

@dirkraft
dirkraft / JavaPIDishTest.sh
Last active October 13, 2015 02:58
Java PID equivalent test, since there's really no guarantee in any direction (exception, format, ...) what this might do. Used this on an ec2 instance to make sure some metrics code wouldn't explode with OpenJDK.
echo "Does my jvm output something reasonable for a PID equivalent?"
echo "public class Main{public static void main(String[]args){System.out.println(java.lang.management.ManagementFactory.getRuntimeMXBean().getName());}}" > Main.java
javac Main.java
java Main
@dirkraft
dirkraft / alternating vs random iteration.java
Last active December 14, 2015 12:38
divergent performance between alternating conditional and random conditional
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
* sort_strat<ul>
* <li>0 random numbers - slowest by a factor of 5 than strat 2 or 3</li>
* <li>1 random numbers sort time included - by far the slowest, even NOT counting the sort time. This one is puzzling.</li>
* <li>2 incrementing numbers - same as 2</li>
@dirkraft
dirkraft / .bash_profile
Last active March 15, 2018 01:09
.bash_profile (for Mac)includes sections for Bash, Homebrew, Ruby, Python, AWS
###############################################################################
# Globals-ish
export VISUAL=vim
export EDITOR=vim
export JAVA_HOME=`/usr/libexec/java_home`
###############################################################################
# Bash
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the active virtualenv
# * the branch/status of the current git repository
# * the return value of the previous command
# * the fact you just came from Windows and are used to having newlines in
# your prompts.
@dirkraft
dirkraft / build.gradle
Last active June 23, 2017 15:00
A build.gradle project template, which bootstraps all necessary parts of a Java, Maven, IntelliJ project on GitHub with the minimum artifact publishing requirements to Sonatype's Maven central.
/* Root build.gradle for Java, Maven, and IntelliJ with Maven central POM. Assumes GitHub.
You should eventually read through and understand this entire Gradle script. Last tried with IntelliJ 2017.1.
Quick start:
- Copy this file into a directory named for your project.
- Choose one Gradle integration mode. Once chosen, stick to it.
IntelliJ Gradle integration:
- Import the project directory as a Gradle project.
- To change Gradle files, enable auto-synchronize or click the synchronize button in the Gradle panel.
@dirkraft
dirkraft / gist:9213344
Last active August 29, 2015 13:56
Performs `gradle dependencyInsight` recursively over all modules. `gxargs` because brew install gnutls on a mac. built-in xargs is a POS. Gradle 1.11 dependencyInsight is significantly more reliable than 1.10. Go 1.11
SAMPLE_DEPENDENCY="jersey-core"
find . -type f -name build.gradle -exec dirname {} \; \
| gxargs -I{} gradle -p {} dependencyInsight --dependency ${SAMPLE_DEPENDENCY}
@dirkraft
dirkraft / ScalaJacksonJerseyClient.scala
Last active August 29, 2015 14:01
Scala jackson jersey-client: Arcane incantation that gets Jersey client serializing scala types. dependencies: 'org.scala-lang:scala-library:2.10.3', 'com.fasterxml.jackson.module:jackson-module-scala_2.10:2.3.3', 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.3.3', 'com.sun.jersey:jersey-client:1.18.1'
val client = Client.create(new DefaultClientConfig(
classOf[ScalaJacksonJsonProvider]
))
class ScalaJacksonJsonProvider extends JacksonJsonProvider(new ObjectMapper().registerModule(DefaultScalaModule)) {}
// sample usages
val stringResult = client.resource("http://localhost:8080/service").get(new GenericType[String](){})
@dirkraft
dirkraft / echo.js
Last active August 29, 2015 14:05
echo remote address (node.js)
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200);
res.end(req.socket.remoteAddress);
}).listen(8080, '0.0.0.0');
@dirkraft
dirkraft / jdunkDelayedAction.js
Last active August 29, 2015 14:08
Angular $timeout delayed function, limiting invocations of any function, such as a typeahead-like search form input.
/**
* Usage:
* <pre>
* $scope.refresh = new DelayedSearch({
* immediate: function() {
* // always do this immediately
* // e.g. show refreshing indicator
* },
* delayMs: 200,
* delayed: function() {
@dirkraft
dirkraft / ConsoleTable.scala
Last active May 1, 2018 22:40
Formats data to a table format for humans with better-than-nothing column resizing.
/*
The MIT License (MIT)
Copyright (c) 2017 Jason Dunkelberger (aka "dirkraft")
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is