Skip to content

Instantly share code, notes, and snippets.

View RobertFischer's full-sized avatar

Robert Fischer RobertFischer

View GitHub Profile
@RobertFischer
RobertFischer / Retry.java
Last active July 25, 2020 22:12
A utility method for retrying on exception, using Java 8 lambdas
public class Retry {
private static final Logger log = Logger.getLogger(Retry.class);
public static interface CallToRetry<T> {
<T> T doIt() throws Exception;
}
public static T withRetry(int maxTimes, long initialWait, int waitMultiplier, CallToRetry<T> call) {
if(maxTimes <= 0) {
@RobertFischer
RobertFischer / .js
Created August 17, 2015 13:22 — forked from usman88/.js
var handle = null;
handle = $.PeriodicalUpdater('/notifications', {
method: 'GET',
data: id: $field_id,
cookie: false,
maxTimeout: 5000,
error: function (xhr,status,message) {
// Do stuff
handle.stop();
}
@RobertFischer
RobertFischer / gist:b446738f4c686870f46b
Last active August 29, 2015 14:25 — forked from ameyawebonise/gist:0a86fd8f9486dd576648
TRACKER_CUSTOM_DATA_AFTER_INSERT
DECLARE groupID INT;
INSERT INTO TRACKER_REVIEW_AUDIT (trCTM_DataID, AUDIT_Date, EditWho_Id, WAS_Value, IS_Value, WAS_trCTM_ItemID, IS_trCTM_ItemID, WAS_Approved, IS_Approved, WAS_Expiration_Date, IS_Expiration_Date, WAS_Rej_Reason, IS_Rej_Reason, WAS_Reviewer, IS_Reviewer, WAS_Dose, IS_Dose, WAS_Administered_Date, IS_Administered_Date, IS_Test_Results, IS_Test_Result_Notes, IS_Next_Step, IS_Complete, IS_Pre, IS_Pre_Date, IS_Post, IS_Post_Date, WAS_Test_Results, WAS_Test_Result_Notes, WAS_Next_Step, WAS_Complete, WAS_Pre, WAS_Pre_Date, WAS_Post, WAS_Post_Date, IS_Record_Type, WAS_Record_Type, IS_trCTM_Status, WAS_trCTM_Status)
VALUES (NEW.trCTM_DataID, NOW(), NEW.EDIT_Who, NULL, NEW.trCTM_Value, NULL, NEW.trCTM_ItemID, NULL, NEW.trCTM_Approved, NULL,NEW.trCTM_Expiration_Date, NULL, NEW.trCTM_Rej_Reason, NULL, NEW.trCTM_Reviewer, NULL, NEW.trCTM_Dose,NULL, NEW.trCTM_Administered_Date,NEW.trCTM_Test_Results, NEW.trCTM_Test_Result_Notes, NEW.trCTM_Next_Step, NEW.trCTM_Complete, NEW.trCTM_Pre, NEW.tr
/**
* Use this in a try-with-resources block to automatically implement logging timing.
*/
public class TimingLogger implements AutoCloseable {
private final Logger logger;
private final String description;
private final long startTime;
private final AtomicBoolean closed = new AtomicBoolean(false);
@RobertFischer
RobertFischer / LambdaJedis.java
Last active August 29, 2015 14:23
JedisPool/Jedis Resource Handling Example
private interface RedisCallback<T> {
T apply(Jedis jedis) throws IOException;
}
private <T> T withRedis(RedisCallback<T> callback) throws IOException {
Objects.requireNonNull(redisConnectionPool, "redis connection pool must be initialized");
Objects.requireNonNull(callback, "callback needs to be provided");
try(Jedis jedis = redisConnectionPool.getResource()) {
T result = callback.apply(jedis);
redisConnectionPool.returnResource(jedis);
@RobertFischer
RobertFischer / AnonymousExtend.java
Created May 6, 2015 14:04
Demonstration of Anonymous Extension in Java
public class AnonymousExtend {
public static class Doer {
public void doIt() {
System.out.println("Hello, World!");
}
}
public static final Doer MY_DOER = new Doer() {
@Override
@RobertFischer
RobertFischer / golf.js
Created December 22, 2014 15:35
That's some fine golf you got there...
{
toFixed: function(num) {
return num.toFixed(0).replace(/./g, function(c, i, a) {
return i > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c;
});
}
}
@RobertFischer
RobertFischer / helper.haml
Created December 3, 2014 12:54
Tabbed Helper
-# Here are the assumptions.
-# 1. We have a consistent UI concept of 'tabbed pages', which have a consistent frame (at least in terms of Haml).
-# 2. Each component of the tabbed pages can be represented as a partial.
-#
-# Given that, I propose that we create a helper that you would call like this.
= tabs {:first => "First Tab!", :second => "2nd Tab", :third => "last tab"}
-# The argument to that function we will call "tab_hash"
-# It would then first load the tab UI component, roughly equivalent to something like this.
= partial "partials/tabs", {:locals => tab_hash}
@RobertFischer
RobertFischer / aliasing.java
Last active August 29, 2015 14:08
Java Type Aliasing
class Aliasing {
// Put your type alias right before the return value.
public static <L extends Long> String parseToHex(String str) {
return L.toHexString(L.parseLong(str));
}
// Use this for when you have some ugly type.
public static <MAP extends Map<String,Set<String>>> boolean addToKey(String key, String value) {
MAP x = service.getKeyMap();
@RobertFischer
RobertFischer / point_line.js
Last active August 29, 2015 14:08
Finding the Best Line for a Point Problem
/*
Here's the approach that I would take. In the description that follows,
P denotes the point where the user clicked, which has coordinates (x_p, y_p).
Each of these steps will involve checking pairs of points against the point
where the user clicked, denoted as A and B, with coordinates (x_a, y_a)
and (x_b, y_b).
We will move forward in three steps:
first, we will identify those pairs of points that could possibly be our point;
second, we will calculate the distance from the point to the line defined by