Skip to content

Instantly share code, notes, and snippets.

@nicholashagen
nicholashagen / DI.dart
Created April 30, 2013 20:48
Simple Dependency Injection (DI) in Dart. This is my first Dart script and attempt at playing with the language, so there are probably many better ways to do this. I'll tweak this as I learn more.
import 'dart:mirrors';
class System {
static final Map<String, TController> _controllers = new Map();
static final Map<String, TService> _services = new Map();
static TController loadController(Symbol name) {
TController controller = _controllers[name];
if (controller == null) {
@nicholashagen
nicholashagen / gist:5306330
Created April 3, 2013 23:12
HDHomeRun Configuration Command Line

Download Source

#> wget http://download.silicondust.com/hdhomerun/libhdhomerun_20130117.tgz
#> tar zxvf libhdhomerun_20130117.tgz 

Install Tools

@nicholashagen
nicholashagen / gist:4665567
Created January 29, 2013 16:30
JMX via Groovy with Authentication
import javax.management.*
import javax.management.remote.*
def creds = [ 'username', 'password' ] as String[]
def env = [ (JMXConnector.CREDENTIALS) : creds ]
def serverUrl = 'service:jmx:rmi:///jndi/rmi://hostname:port/jmxrmi'
def server = JMXConnectorFactory.connect(new JMXServiceURL(serverUrl), env).MBeanServerConnection
new GroovyMBean(server, 'java.lang:type=Threading').dumpAllThreads(true, true).each { thread ->
println "THREAD: ${thread.threadName}"
}
@nicholashagen
nicholashagen / LongTaskServlet.java
Created September 2, 2012 20:10
Server-Sent Events in Servlets
package com.znet.examples.sse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.servlet.ServletConfig;
@nicholashagen
nicholashagen / gist:2881938
Created June 6, 2012 13:46
Dynamic MBeans
/**
* Simple definition of a dynamic MBean, named "SimpleDynamic".
*
* The "SimpleDynamic" dynamic MBean shows how to expose for management
* attributes and operations, at runtime, by implementing the
* "javax.management.DynamicMBean" interface.
*
* This MBean exposes for management two attributes and one operation:
* - the read/write "State" attribute,
* - the read only "NbChanges" attribute,
@nicholashagen
nicholashagen / gist:2855167
Created June 1, 2012 21:12
Git Rebase/Merge Workflow

Git Workflow for Feature Branches

The following is an example workflow for developing on a temporary branch and merging back to the main branch squashing all commits into a single commit. This assumes you already have a branch named branch-xyz and have finished the work on that branch.

Step 1: Checkout the feature branch

git checkout branch-xyz
@nicholashagen
nicholashagen / gist:2041175
Created March 15, 2012 01:56
Working with GitHub Forks

The following code is day-to-day operations when working with 3 forks: an open source project, a local fork of that project, and a company fork of that project. The power of Git is remote aliases that allow you to work with all 3 forks in parallel in the same code base and instantly compare, push, merge, etc.

Setup:

#> git clone [url of local fork: ie: username/project]
#> cd project
#> git remote add project [url of project: ie: project/project]
#> git remote add company [url of company fork: ie: company/project]
@nicholashagen
nicholashagen / gist:2039581
Created March 14, 2012 21:16
Accessing Temporary Directory in Servlet Container
File tmpDir = (File) servletContext.getAttribute(SERVLET_TMP_DIR);
if (tmpDir == null) {
throw new ServletException("Servlet container does not provide temporary directory");
}
File workDir = new File(tmpDir, "classes");
if (!workDir.mkdirs()) {
throw new ServletException("Unable to create classes temporary directory");
}
@nicholashagen
nicholashagen / gist:1993769
Created March 7, 2012 15:22
Git Commands
# control color output via ASCII codes for better visual aspsect in terminal
git config --global color.ui auto
# update line-ending support for win/unix cross-platform (cr/cflf)
# force to be LF in the repo (regardless of OS)
git config --global core.autocrlf input
# force windows t oconvert to platform on checkout and back on commit
git config --global core.autocflf true
# individually control portions of a file (patch mode)
@nicholashagen
nicholashagen / gist:1989663
Created March 6, 2012 23:09
Groovy Closure to Callable
// anonymously invoke a closure into callable and submit to executor
// this fails w/o the explicit (Callable) since it converts it to Runnable
def executor = java.util.concurrent.Executors.newFixedThreadPool(5)
def future = executor.submit((java.util.concurrent.Callable) {
'TEST'
})
assert('TEST' == future.get())