Skip to content

Instantly share code, notes, and snippets.

View ericwoodruff's full-sized avatar

Eric Woodruff ericwoodruff

View GitHub Profile
@ericwoodruff
ericwoodruff / gist:c8092f537125e4408b34
Created October 5, 2014 06:19
ssh connection-aware command
ssh localhost "sleep 99 < <(cat; kill -INT 0)" <&1
@ericwoodruff
ericwoodruff / _data-update-target.js
Last active August 29, 2015 14:05
rails form_for data-update-target ajax
// http://mrdanadams.com/2011/partials-ajax-form-submit-rails/#.UWcy9kDCHsg
// http://stackoverflow.com/questions/18770517/rails-4-how-to-use-document-ready-with-turbo-links
$(document).on ('ajax:success', 'form[data-update-target], a[data-update-target]', function (evt, data) {
var dom = $(data);
$('#messages').html(dom.siblings('#messages:first').contents());
var target = $(this).data('update-target');
$('#' + target).html(dom.siblings('#body:first').contents());
});
@ericwoodruff
ericwoodruff / zipcmp.rb
Last active January 3, 2016 12:49
recursive zip compare (deep zipcmp)
#!/usr/bin/ruby
require 'fileutils'
def run(args)
args = args.gsub /$/, ''
`#{args}`
end
def listzip(file)
@ericwoodruff
ericwoodruff / Each.java
Last active January 1, 2016 01:49
Java for(each) Iterable, Each.withIndex
import java.util.Iterator;
public class Each {
public static class Indexed<T> {
public T value;
public int index;
public Indexed (T value, int index) {
this.value = value;
@ericwoodruff
ericwoodruff / rescue_wait.rb
Created December 12, 2013 16:06
Ruby rescue_wait sleep retry
def rescue_wait(timeout, increment = 2)
start = Time.now
begin
yield
return true
rescue Exception => e
puts e.message
sleep increment
retry unless Time.now-start > timeout
end
@ericwoodruff
ericwoodruff / .gitconfig
Created December 8, 2013 19:50
Inverting git index
[alias]
swaplast = !git tag _invert && git reset --hard HEAD~2 && git cherry-pick _invert _invert~1 && git tag -d _invert
invertindex = !git commit -m tmp1 && git add -A && git commit -m tmp2 && git swaplast && git reset HEAD~1 && git reset HEAD~1 --soft
@ericwoodruff
ericwoodruff / WithoutTryFinally.java
Created November 21, 2013 17:33
Without try/finally
public Object methodToOverride () {
Object temp = super.methodToOverride ();
/// do post-super stuff
return temp;
}
@ericwoodruff
ericwoodruff / TryFinally.java
Created November 21, 2013 17:30
try/finally pattern
public Object methodToOverride () {
try {
return super.methodToOverride ();
} finally {
// do post-super stuff
}
}
@ericwoodruff
ericwoodruff / ContentValues.java
Last active December 28, 2015 20:28
toContentValues example
public static ContentValues toContentValues (User user) {
ContentValues values = new ContentValues ();
switch (Column._id) {
case _id: // auto-incremented primary key, skip this one
case sync_state: values.put (Column.sync_state.name (), user.getSyncState ());
case user_id: values.put (Column.user_id.name (), user.getUserId ());
}
return values;
}
@ericwoodruff
ericwoodruff / SampleEnum.java
Created November 20, 2013 03:13
Column enum
public static enum Column {
_id ("INTEGER PRIMARY KEY"),
sync_state ("STRING NOT NULL DEFAULT 'none'"),
user_id ("LONG NOT NULL"),
...
;
}