Skip to content

Instantly share code, notes, and snippets.

View paul-bjorkstrand's full-sized avatar

paul-bjorkstrand

View GitHub Profile
/*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
@paul-bjorkstrand
paul-bjorkstrand / Main.java
Last active November 28, 2021 00:17
Loom simple actor pattern
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.FutureTask;
import java.util.concurrent.LinkedBlockingQueue;
public class Main {
public static void main(String[] args) {
var a1 = proxy(new TestActor("ta1"), Actor.class);
@paul-bjorkstrand
paul-bjorkstrand / cleanExample.java
Last active November 22, 2021 20:48
Loom snippets
// Roguh translation for my first approach, that had no way to an
// underlying error that occurred during execution of the tasks
class test {
public <V> List<V> test(List<Callable<V>> someTasks) {
try (var se = StructuredExecutor.open()) {
var futures = someTasks.stream()
.map(se::fork);
se.join();
(async () => {
let response = await fetch('/system/console/status-pattern-detector.json');
let text = await response.text();
let json = text.replaceAll(/\n/g, ',')
.slice(0, -1);
let items = JSON.parse(`[${json}]`);
function getComponentName(item) {
//get the component name from the item
return "";
module = module ? {}
module.exports = (robot) ->
class Factoid
constructor: (@x, @v, @y) ->
robot.logger.info("making factoid [#{@x}, #{@v}, #{@y}]")
@y = if Array.isArray(@y) then @y else [@y]
respond: (robot, message) ->
robot.logger.info("responding to [#{@x}, #{@v}, #{@y}]")
switch @v
window.addEventListener('storage', function(e) {
if (e.storageArea === localStorage) {
var key = e.key;
if (data) {
$(document).trigger('storage.' + e.key, data);
}
}
});
$(document).on("storage.test", function(e, data) {
@paul-bjorkstrand
paul-bjorkstrand / jQuery.parents-selector.js
Created August 28, 2014 21:11
jQuery.parents-selector.js
(function($) {
$.expr[":"].parents = $.expr.createPseudo(function(arg) {
return function( elem ) {
return $(elem).parents(arg).length > 0;
};
});
})(jQuery);
@paul-bjorkstrand
paul-bjorkstrand / Math.min-max.js
Created May 6, 2014 13:36
Simple min-max, bounding a value between a minimum and maximum
if (!Math.minMax) {
Math.minMax = function(min, max, val) {
return Math.max(min, Math.min(max, val));
};
}
@paul-bjorkstrand
paul-bjorkstrand / jQuery.center.js
Created May 6, 2014 13:34
Centers any element on a page
(function($, window) {
var $w = $(window);
$.fn.center = function() {
this.css({
position: "absolute",
left: Math.max(0, ($w.width() - this.outerWidth()) / 2 + $(window).scrollTop()) + "px",
top: Math.max(0, ($w.height() - this.outerHeight()) / 2 + $(window).scrollTop()) + "px"
});
};
@paul-bjorkstrand
paul-bjorkstrand / show-hide-while.js
Created April 1, 2014 16:33
Show (or hide) an element until a function/promise is complete, then hide (or show) that element after the function/promise is complete.
(function($) {
$.fn.showWhile = function(fn) {
var obj = this.show();
var result = fn();
if (typeof result.then !== "function") {
result = $.Deferred.resolve(fn).promise();
}