Skip to content

Instantly share code, notes, and snippets.

View RobertFischer's full-sized avatar

Robert Fischer RobertFischer

View GitHub Profile
@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 / 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 / ExceptionEater.java
Created August 25, 2015 14:49
Lambda for the pattern of eating exceptions
public class ExceptionEater {
private static final Logger log = //TODO Create Logger
public static <T> T swallowNPE(Supplier<T> producer) {
try {
return supplier.get();
} catch(NullPointerException npe) {
log.info("NullPointerException being swallowed", npe);
@RobertFischer
RobertFischer / ExceptionEater.java
Created August 25, 2015 14:57
ExceptionEater with Optional
public class ExceptionEater {
private static final Logger log = //TODO Create Logger
public static <T> Optional<T> swallowNPE(Supplier<T> producer) {
try {
return Optional.ofNullable(supplier.get());
} catch(NullPointerException npe) {
log.info("NullPointerException being swallowed", npe);
return Optional.empty();
@RobertFischer
RobertFischer / MagnusProperty.groovy
Created August 25, 2015 22:34
Example of type-safe properties
@CompileStatic
abstract class MagnusProperty<T> {
final String key;
MagnusProperty(String key) {
assert key : "No key provided!"
this.key = key
}
public enum TimePeriod {
ONE_YEAR_AGO(Calendar.YEAR, -1),
THREE_MONTHS_AGO(Calendar.MONTH, -3),
// and so on...
;
private int calendarField;
private int changeMagnitude;
private TimePeriod(int calendarField, int changeMagnitude) {
@RobertFischer
RobertFischer / HashFlash.js
Created March 7, 2016 21:00
Flash detection with Modernizr and Check1.js
<html>
<head>
<script src="check1.js"></script>
<script>
var modzrFlash;
Check1(
"hasFlash",
"https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js",
function() {
return Modernizr.flash;
@RobertFischer
RobertFischer / gist:df1a7027c1f8bb8e401edb90fcad9089
Created January 18, 2017 15:22
Changesets with state count (for Dave)
robert=# \d+ changeset
Table "public.changeset"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+--------------------------------------------------------+---------+--------------+-------------
id | integer | not null default nextval('changeset_id_seq'::regclass) | plain | |
Indexes:
"changeset_pkey" PRIMARY KEY, btree (id)
Referenced by:
TABLE "state" CONSTRAINT "state_changeset_id_fkey" FOREIGN KEY (changeset_id) REFERENCES changeset(id)
@RobertFischer
RobertFischer / Lib.hs
Created March 28, 2017 17:27
What's wrong with this?
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Lib
( startApp
, app
) where
import Data.Aeson
import Data.Aeson.TH
@RobertFischer
RobertFischer / Main.elm
Created October 4, 2017 20:00
Nifty Trick for Loading CSS in Pure Elm
module Main exposing (main)
import Navigation exposing (program, Location)
import Platform.Cmd as Cmd exposing (Cmd)
import Platform.Sub as Sub exposing (Sub)
import Html exposing (Html)
import Html.Attributes as Attr
import Html.Events as Event
import Routes exposing (Route(..))
import RemoteData exposing (..)