Skip to content

Instantly share code, notes, and snippets.

View Groostav's full-sized avatar

Geoff Groostav

View GitHub Profile
package com.empowerops.front_end;
import com.empowerops.common.EventBus;
import com.empowerops.common.FormattedDuration;
import com.empowerops.common.SyncingUtilities;
import com.empowerops.common.ui.FXMLLoader;
import com.empowerops.common.ui.PreloadedFX;
import com.empowerops.jargon.events.OptimizationSettingsChanged;
import com.empowerops.jargon.model.OptimizerNode;
import com.empowerops.jargon.model.OptimizerSettingChangeSet;
private void hackPropertiesInViaReflection(javafx.fxml.FXMLLoader fxmlLoader, FXController propertySource) {
Map<String, Object> namespace = ExceptionUtilities.<Map<String, Object>>tryGetAndLogOnException(
log,
"get field 'namespace' on javafx.fxml.FXMLLoader reflectively",
() -> getFieldValue(fxmlLoader, "namespace")
).orElse(new HashMap<>());
Queryable<Field> propertyFieldsOnController = from(propertySource.getClass().getDeclaredFields())
@Groostav
Groostav / SyncingUtilities.java
Last active November 28, 2015 22:17
snippit of our Platform.runImmediately method
public class SyncingUtilities {
//...
public static void runImmediatelyOnFXThread(Action actionToRunOnJavaFXThread, boolean exitOnInterrupt) {
if (BootstrappingUtilities.isFXApplicationThread()) {
actionToRunOnJavaFXThread.run();
return;
@Groostav
Groostav / FXTimeKeeper.java
Created December 11, 2015 19:16
My first attempt at a re-usable requeing class
public class FXTimeKeeper {
private static final Logger log = Logger.getLogger(FXTimeKeeper.class.getCanonicalName());
public static final int SleepPeriod = getEnvInt(FXTimeKeeper.class, "SleepPeriod").orElse(50);
private final Queue<UpdateJob> jobs = new ConcurrentLinkedQueue<>();
private final SyncingUtilities syncingUtilities;
@Groostav
Groostav / RegexTests.java
Created January 27, 2016 08:13
Stack-Overflow in java regex engine
class RegexTests{
@Test
public void regex_can_match_massive_repition_without_stack_overflow(){
Pattern pattern = Pattern.compile("([^\\r\\n]*?\\r?\\n){266959}(?<cool>.{30})");
//a pattern that runs successfully is (?>[^\\r\\n]?\\r?\\n){266959}(?<cool>.{30})
// note the atomic group on the front
// in my case, TwentyMegDocument is the first 300,000 lines or so
// of a wikipedia database dump (abstract-9):
@Groostav
Groostav / SyncingUtilities.java
Created May 26, 2016 18:55
empowerops implementation of `runImmediately` for javafx
public class SyncingUtilities {
//...
public static void runImmediatelyOnFXThread(Action actionToRunOnJavaFXThread) {
if (BootstrappingUtilities.isFXApplicationThread()) {
actionToRunOnJavaFXThread.run();
return;
}
@Groostav
Groostav / CallbackCoroutineConvert.kt
Last active August 10, 2016 19:13
Sample from our problem domain, where legacy clalback-based Fortran needs to be converted to a nice coroutine.
package com.empowerops.language
/**
* Created by Geoff on 2016-08-09.
*/
class GeneratorFrontEnd {
fun beginGeneration() = CallbackAdapter().let { it to it.initialPoint }
}
class LibraryUser {
@Groostav
Groostav / Parboiled help request.md
Created August 12, 2016 20:27
request for help using Parboiled as a push parser from the community

Hey guys,

Has anyone had any experience using Parboiled as a push parser?

Right Now I'm using ANTLR to parse an event sequence to generate a list of undo/redo-able actions. It works fairly well, with the one notable exception that, because ANTLR cannot be used as a push parser (at least formally), I have to re-parse the entire event sequence every time a new event comes in. Since antlr is fast this isn't a performance issue so much as a least-suprise issue: in order to create a facade of "new events coming in", we have to perform a logical diff on the resulting parse tree from parse(eventSeq1) and parse(eventSeq1 + newEvent). That diffing logic involves a number of complex caches, and is very bug prone.

I was hoping to replace this parser with parboiled, but it would be hugely convenient to me if I could use parboiled as a push parser.

What I mean by this is as follows: I would write a parboiled grammar and a parse tree visitor. With an empty set of tokens, I would then write `parseTree.accept(myVisit

@Groostav
Groostav / coerceTo.kt
Created September 10, 2016 00:10
methods to coerce one file system directory "into" another
/**
* make `targetToModify` identical to `source` in as few changes as possible.
*/
@JvmStatic fun coerceTo(source: Path, targetToModify: Path){
NIOFiles.walkFileTree(targetToModify, PruneByComparisonFileVisitor(source, targetToModify))
NIOFiles.walkFileTree(source, AddByComparisonFileVisitor(source, targetToModify))
}
infix fun Int.pow(power: Int) = Math.pow(this.toDouble(), power.toDouble()).toInt()
@Groostav
Groostav / LooperWorker.kt
Last active September 27, 2016 23:01
UI workload sample problem
class LoopWorker {
private val executor = SingleThreadedScheduledExecutorService()
fun doLoops() {
val stopwatch = Stopwatch.createUnstarted()
executor.scheduleWithFixedDelay(5000.ms) {