Skip to content

Instantly share code, notes, and snippets.

@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: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: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 / 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: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 / 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 / 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 / LoadTest.java
Last active December 17, 2015 10:59
Faster Synchronization Through Hash Maps
public class LoadTest {
public static void main(String[] args) {
// int count = 5000;
int count = 25000;
// int count = 100000;
// int count = 250000;
long s = System.nanoTime();
for (int i = 0; i < 1000; i++) {
@nicholashagen
nicholashagen / HTTPBuilderGitHubFailure.groovy
Created May 23, 2013 14:26
Groovy HTTPBuilder fails with GitHub
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.6' )
import groovyx.net.http.*
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.URLENC
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
// this fails
try {
@nicholashagen
nicholashagen / GrailsMongoDBTest.groovy
Created May 28, 2013 18:33
MongoDB plugin in Grails and Criteria queries
/* ASSUME FOLLOWING OBJECT MODEL
class Address {
String street
String city
}
class Role {
boolean admin
String type