Skip to content

Instantly share code, notes, and snippets.

View benjaminaaron's full-sized avatar

Benjamin Degenhart benjaminaaron

View GitHub Profile
@benjaminaaron
benjaminaaron / AttributesExample.java
Last active April 14, 2022 09:10
validate json by reflection before using gson
public class AttributesExample {
private String str = "foo";
private double dbl = 0.8;
private boolean bool = false;
}
@benjaminaaron
benjaminaaron / script.js
Created March 20, 2022 10:38
JS code for the chrome developer console to extract a CSV file from "Tabs from other devices" in chrome://history/syncedTabs
// To access the list-element within shadowroot I clicked inspect on the list and right-clicked on <div id="tab-item-list">
// --> "Store as global variable", this gives you temp1 that is the basis for this cript
// There are probably better ways to access elements in shadowroot, but I didn't want to take the time to learn about it at this point :)
items = temp1.getElementsByClassName("item-container")
for (i = 0; i < items.length; i++) {
item = items[i].firstChild;
line = '"' + item.title.replace(/['"]+/g, '') + '","' + item.href + '"';
setTimeout (console.log.bind (console, line));
@benjaminaaron
benjaminaaron / script.py
Last active June 30, 2020 17:42
Generate all combinations based on a combination of mandatory and optional parts
import numpy as np
line = "mandatory1(optional1)mandatory2(optional2)(optional3)"
# use regex or a char by char stack approach to extract these?
parts = ["mandatory1", "optional1", "mandatory2", "optional2", "optional3"]
fixPositions = [0, 2]
elements = len(parts)
optionalElements = elements - len(fixPositions)
n = 2 ** optionalElements
@benjaminaaron
benjaminaaron / graphml-augment.js
Created June 30, 2020 17:40
A node.js script to add node ids as node labels for a GraphML format readable by yEd. As next step after exporting without the label apparatus.
const fs = require('fs');
const parser = require('xml2json');
const format = require('xml-formatter');
// true only for debugging, it messes the labels up because the space after <y:NodeLabel> and before the string gets included
const prettyPrint = false;
const replaceAll = (str, find, replace) => {
return str.replace(new RegExp(find, 'g'), replace);
};

Keybase proof

I hereby claim:

  • I am benjaminaaron on github.
  • I am benjaminaaron (https://keybase.io/benjaminaaron) on keybase.
  • I have a public key ASBuRpomqWDBY2eo0WdOjH7P-czBI_U5LACFpehr4tamego

To claim this, I am signing this object:

@benjaminaaron
benjaminaaron / FilesTreeToGraphML.java
Created June 6, 2018 21:20
convert find-output to GraphML to visualize directory structures in yEd
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@benjaminaaron
benjaminaaron / Main.java
Created May 28, 2018 21:15
possible subgroup constellations in a group of size n
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
static List<List<Integer>> partitions = new ArrayList<>();
static void partition(int n, int max, String prefix) {
@benjaminaaron
benjaminaaron / old_scenario_format.json
Created June 29, 2016 08:16
the .scenario format as it currently is
{
"release": "not a release",
"topographyhash": "d439ba0f5e95a65942da5d53374e3fb1372c2020",
"name": "New_scenario",
"processWriters": [],
"attributeshash": "bf1f2ba3b13f6b61e215e57743c81a3de5973418",
"vadere": {
"attributesModel": {
"OPTIMAL_STEPS_MODEL": {
"stepCircleResolution": 18.0,
@benjaminaaron
benjaminaaron / spatial_fourier_interactive.py
Created September 22, 2017 14:51
to experiment what the transformation from spatial to fourier domain does
import numpy as np
import matplotlib.pyplot as plt
#
# The purpose of this script is to get a feeling what the transformation from spatial to fourier domain does.
#
# The user can set white or black pixels in the spatial domain and the fourier domain will be updated accordingly.
# The left mouse button creates white pixels (value = 1), the right mouse button black pixels (value = 0).
# Both one-time clicks work as well as dragging (moving while button is pressed down) the mouse.
# The drawing radius can be changed with the + and - keys, also during dragging.
@benjaminaaron
benjaminaaron / saveDOMelementAsText.js
Created August 24, 2017 19:47
download the content of a DOM element as text - run in browser console
function saveAsTextFile(element, filename) { // via stackoverflow.com/a/32858416
var textFileAsBlob = new Blob([element.innerHTML], {type:'text/plain'});
var link = document.createElement("a");
link.download = filename;
link.href = window.URL.createObjectURL(textFileAsBlob); // works only in Chrome without attaching it to the DOM
link.click();
}
saveAsTextFile(document.getElementById("content"), "content.xml");