Skip to content

Instantly share code, notes, and snippets.

View danielpcox's full-sized avatar

Daniel Cox danielpcox

View GitHub Profile
@danielpcox
danielpcox / retrync
Last active December 21, 2015 13:19
retrync ("retrying rsync") executes resumable rsync uploading/downloading via SSH with progress over and over until the transfer is complete. First stick your public SSH key in ~/.ssh/authorized_keys on the remote server. Original version came from http://blog.iangreenleaf.com/2009/03/rsync-and-retrying-until-we-get-it.html
#!/bin/bash
# Usage: retrync path/to/thing/locally user@host:/path/where/you/want/it/remotely
trap "echo Exited!; exit;" SIGINT SIGTERM
false
while [ $? -ne 0 ]
do
@danielpcox
danielpcox / Config.java
Created July 4, 2013 15:56
Simple, static, global configuration. Depends on Log4j and Guava.
package rmt.analytics.tagger.configuration;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@danielpcox
danielpcox / merge-remote.sh
Last active December 16, 2015 01:59
Merge the root of a given branch from repository A into a subdirectory of a given branch in the current repository, preserving yet rewriting the history so that it looks as if A had always been developed inside that subdirectory. It also rewrites the tags to point to the new commits, appending the subdirectory name to the tag names to avoid conf…
#!/usr/bin/env sh
# USAGE: merge-remote.sh <subdirectory-name> <new-local-branch-name> <remote-branch-name> <remote-repository-url>
#
# <new-local-branch> will be created it it does not already exist
SUBDIR_NAME=$1
LOCAL_BRANCH=$2
REMOTE_BRANCH=$3
REMOTE_URL=$4
@danielpcox
danielpcox / rails_engine.md
Last active December 11, 2015 17:48
Creating a new Rails Engine "blorgh" with RSpec and YARD

Creating a new Rails Engine "blorgh" w/ RSpec + YARD

I did all of the following with Rails 3.2.12 and Bundler 1.3.0 acquired with

$> gem install --version '3.2.12' rails
$> gem install --version '1.3.0' bundler

Start by using Rails' Engine generator with a few options.

$&gt; rails plugin new blorgh --full --dummy-path=spec/dummy \
@danielpcox
danielpcox / gist:2989641
Created June 25, 2012 16:37
Git Presentation

Git Crash Course

Git is a source code management system.

Third Level

text

@danielpcox
danielpcox / readFileAsString.java
Created June 14, 2012 14:16
A little Java snippet for reading a file into a string.
private static String readFileAsString(String filePath)
throws java.io.IOException{
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(
new FileReader(filePath));
char[] buf = new char[1024];
int numRead=0;
while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
@danielpcox
danielpcox / printy.rb
Created May 16, 2012 12:04
Helpful little server for debugging. Spits out everything about an HTTP request made to it.
require 'sinatra'
require 'awesome_print'
get %r{.*} do
puts_env
end
post %r{.*} do
puts_env
end
@danielpcox
danielpcox / WITS_TEST.xml
Created May 2, 2012 19:56
Failing Transformation
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="events.xsl"?>
<!-- Or if I remove the namespace attributes on IncidentList, it works. -->
<IncidentList xmlns="http://wits.nctc.gov" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wits.nctc.gov WITS.XSD">
<Incident>
<ICN>200458431</ICN>
<Subject>10 civilians killed, at least 45 wounded by suspected GAM in Peureulak, Indonesia</Subject>
<Summary>On 1 January 2004, in Peureulak, Aceh Province, Indonesia, a bomb exploded at a concert, killing ten civilians, wounding 45 others, and causing major damage to the stage area. Many of the victims were Indonesian teenagers. Police blamed the Free Aceh Movement (GAM), although the GAM denied responsibility. No other group claimed responsibility.</Summary>
<IncidentDate>01/01/2004</IncidentDate>
@danielpcox
danielpcox / SandboxApp.java
Created May 2, 2012 12:20
Neo4j java-rest-binding bug
public class SandboxApp
{
private static Node node1;
private static RelationshipType relType = DynamicRelationshipType.withName("BEHOLD");
public static void main( String[] args ) throws ParseException, JSONException
{
RestAPI restAPI = new RestAPI("http://localhost:7474/db/data");
node1 = restAPI.createNode(map());
@danielpcox
danielpcox / neo4j_shell.sh
Created March 4, 2012 11:13
Runs the neo4j shell
#!/bin/sh
# Set this to your own project directory
PROJECT_DIR=/Users/jim/neo/development/neo4j-tutorial
LIB_DIR=$PROJECT_DIR/lib
java -cp $LIB_DIR/neo4j-jmx.jar:$LIB_DIR/neo4j-community.jar:$LIB_DIR/neo4j-server.jar:$LIB_DIR/neo4j-cypher.jar:$LIB_DIR/neo4j-kernel.jar:$LIB_DIR/neo4j-shell.jar:$LIB_DIR/neo4j-graph-algo.jar:$LIB_DIR/neo4j-lucene-index.jar:$LIB_DIR/lucene-core.jar:$LIB_DIR/neo4j-graph-matching.jar:$LIB_DIR/neo4j-server-static-web.jar:$LIB_DIR/scala-library.jar:$LIB_DIR/geronimo-jta_1.1_spec.jar org.neo4j.shell.StartClient -path $1