Skip to content

Instantly share code, notes, and snippets.

View itzg's full-sized avatar

Geoff Bourne itzg

View GitHub Profile
@itzg
itzg / gist:3967270
Created October 28, 2012 02:55
Ensure a method of a specific JS object instance is called due to an event
function ShapeModel(shapeStr) {
this.shapeStr = shapeStr;
}
ShapeModel.prototype = {
doClick: function() {
alert("Clicked "+this.shapeStr);
}
};
@itzg
itzg / layout.js
Created October 29, 2012 02:47
JS layout manager
var layout = {
layoutMgrData : "layoutMgr",
instances : [],
_addInstance : function(instance) {
var added = false;
// Need to ensure the instances are sorted outer-to-inner for
// any containment relationships. That way we layout the broadest
// element and then allow the inners to adjust accordingly.
var len = layout.instances.length;
@itzg
itzg / gist:3995523
Created November 1, 2012 18:20
Jenkins post-build shell task to deploy WAR to Tomcat
set +x
echo "Deploying to Tomcat at http://tomcat:8080/myapp"
curl -s --upload-file target/MyApp-1.0.war "http://user:password@tomcat:8080/manager/text/deploy?path=/myapp&update=true&tag=${BUILD_TAG}"
@itzg
itzg / pom.xml
Created November 6, 2012 17:43
Maven pom.xml using Shade plugin to support both Dropwizard and Spring
<?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>com.exmaple</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
<properties>
@itzg
itzg / gist:4075447
Created November 14, 2012 22:56
One way to do multi instance JMX metrics
@Component
@ManagedResource
public class GeneralMetricsResource {
private int total;
private ArrayList<AtomicInteger> specifics = new ArrayList<>();
public void inc(int specific) {
total++;
@itzg
itzg / gist:4332635
Created December 18, 2012 22:22
A MarkDown CSS I like to use, based on Bootstrap/Github's
body{
margin: 0 auto;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #444444;
line-height: 1;
max-width: 960px;
padding: 5px;
}
h1, h2, h3, h4 {
color: #111111;
@itzg
itzg / gist:5229498
Last active December 15, 2015 08:19
When using a Jackson JsonGenerator directly (the streaming API), make sure to call close() when finished. Otherwise, the content will be impartial.
JsonFactory jsonFactory = new JsonFactory();
StringWriter prefValue = new StringWriter();
try {
JsonGenerator jsonGen = jsonFactory.createJsonGenerator(prefValue);
jsonGen.writeStartArray();
for (int i = 0; i < source.getSize(); ++i) {
jsonGen.writeString(source.getElementAt(i).getAbsolutePath());
}
jsonGen.writeEndArray();
jsonGen.close();
@itzg
itzg / gist:5230690
Created March 24, 2013 05:31
Using dns-sd, which is provided by Bonjour, to validate presence of vidsync
$ dns-sd -B _rmi._tcp
Browsing for _rmi._tcp
Timestamp A/R Flags if Domain Service Type Instance Name
6:28:50.046 Add 2 12 local. _rmi._tcp. vidsync
Geoff@Quattro ~
$ dns-sd -L vidsync _rmi._tcp
Lookup vidsync._rmi._tcp.local
6:28:59.218 vidsync._rmi._tcp.local. can be reached at Quattro.local.:21099 (interface 12)
@itzg
itzg / gist:5232363
Created March 24, 2013 15:38
Want to find javaw processes from the Windows command-line?
$ tasklist /fi "IMAGENAME eq javaw.exe"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
javaw.exe 6600 Console 1 652,696 K
javaw.exe 1312 Console 1 71,100 K
@itzg
itzg / gist:5233836
Created March 24, 2013 22:24
Eclipse (or STS) Java template for inserting a static 'logger' field using SLF4J
${:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}
private static final Logger logger = LoggerFactory.getLogger(${enclosing_type}.class);