Skip to content

Instantly share code, notes, and snippets.

View benjaminaaron's full-sized avatar

Benjamin Degenhart benjaminaaron

View GitHub Profile
@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 / 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);
};
@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

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 / 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");
@benjaminaaron
benjaminaaron / Main.java
Created March 10, 2017 21:39
Simple Swing
import java.awt.event.ActionEvent;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("Simple Swing");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
@benjaminaaron
benjaminaaron / MandelbrotSet.m
Last active January 2, 2017 15:39
a minimal implementation of the mandelbrot set in Matlab
grid = 0.01;
iter = 50;
%% mandelbrot set
[Re,Im] = meshgrid(-2:grid:1,-1:grid:1);
z0 = Re + Im*1i; % creates a grid of complex numbers from -2 to 1 on the real axis and from -1 to 1 on the imaginary axis
values = zeros(size(z0));
z = z0;