Skip to content

Instantly share code, notes, and snippets.

View moqmar's full-sized avatar

Moritz Marquardt moqmar

View GitHub Profile
@moqmar
moqmar / README.md
Last active February 11, 2018 21:47
Simplified Git Status for use in zsh prompts with fonts including FontAwesome.

Simplified Git Status for use in zsh prompts with fonts including FontAwesome.

 master

@moqmar
moqmar / evem.js
Last active March 20, 2018 21:42
Event Emitter
// Minimal Event Handler
// Call makeEmitter(obj) to make obj an event emitter.
// obj.on(event, handler)
// obj.off(event[, handler])
// obj.fire(event[, args...])
// https://gist.github.com/moqmar/1a33e871e9a4b855443d57d40f56d052 (Public Domain/CC0)
function makeEmitter(obj) {
obj.__l = {}; // Listeners - this.on("update", fn) -> { update: [fn] }
obj.on = function(ev, fn) {
if (!this.__l[ev]) this.__l[ev] = [fn];
@moqmar
moqmar / simple-implementations.md
Last active May 4, 2018 11:21
Simple implementations for simple tasks
@moqmar
moqmar / bridge.service
Last active May 28, 2018 17:18
Adding a network bridge with IP address under Linux
[Unit]
Description=Network Bridge
After=syslog.target network.target
[Service]
Type=onehot
ExecStart=/opt/bridge.sh
[Install]
WantedBy=multi-user.target
@moqmar
moqmar / queue.js
Created June 14, 2018 08:10
Completely promise-based queue that works with functions returning promises and normal values.
// Completely promise-based queue that works with functions returning promises and normal values.
/*
function doSomething() {
return new Promise(y => setTimeout(() => y(), 3000));
}
// Using the singleton
for (let i = 0; i < 10; i++) Q(() => doSomething()).then(() => console.log(i));
@moqmar
moqmar / rest-api.js
Last active June 24, 2018 15:22
fetch() wrapper for REST APIs
function RestApi(endpoint, options) {
this.endpoint = (endpoint || "/").replace(/\/$/, "");
this.options = options || {};
// Allow usage in queue, or in other places where the value of "this" is incorrect:
for (let method in ["GET", "POST", "PUT", "DELETE", "HEAD", "PATCH"].reduce((p,c)=>p[c]=1,{})) {
this[method] = RestApi.prototype[method].bind(this);
}
}
RestApi.fetchResponseHandler = function fetchResponseHandler(hardFail, res) {
return new Promise((resolve, reject) => {
// 1. Go to https://open.spotify.com/collection/tracks
// 2. Scroll to the very bottom so everything is loaded
// 3. Press F12 and paste the following code (obviously only if you understand what it does)
// 4. Press Ctrl+A and copy everything to a .csv file
document.documentElement.innerHTML = "<pre>Title\tArtist\tAlbum\n"
+ [...document.querySelectorAll(".tracklist .tracklist-row")]
.map(x => {
const e = x.querySelector(".TrackListRow__explicit-label");
if (e) e.parentElement.removeChild(e);
return x.querySelector(".tracklist-name").textContent + "\t" +
@moqmar
moqmar / autoyay
Last active January 31, 2019 12:38
Bash script to apply a text file with a list of packages to add (package) and remove (!package) to an Arch-based system using yay. Written to keep two computers in sync, but can be used for a lot of purposes. The packages can be separated using spaces or newlines; line comments starting with # are supported, too.
#!/bin/sh
set -eu
IFS=$'\n\t'
# Bash script to apply a text file with a list of packages to add (package) and remove (!package) to an Arch-based
# system using yay. Written to keep two computers in sync, but can be used for a lot of purposes.
# The packages can be separated using spaces or newlines; line comments starting with # are supported, too.
# The packages file can be defined as a command line argument.
# Otherwise, it'll be taken from $XDG_PUBLICSHARE_DIR/packages.
@moqmar
moqmar / setup.sh
Last active February 5, 2019 20:46
#!/bin/sh
# Setup Packages
pacman -S yay
mkdir -p ~/.local/bin
wget https://gist.githubusercontent.com/moqmar/450ac6592028c742177bae71705e6e16/raw/autoyay -O ~/.local/bin/autoyay
chmod +x ~/.local/bin/autoyay
autoyay
# Setup Syncthing
# Build the ubilinux kernel for the UP Boards. The script is built to be used with Docker.
# More information: https://wiki.up-community.org/Compile_ubilinux_kernel_from_source
# Usage: docker run -it --rm debian:9 sh -c 'wget ... && sh up-kernel-build.sh'
apt-get update
apt-get install -y git build-essential libncurses5-dev libssl-dev gcc g++ bc
git clone https://github.com/emutex/ubilinux-kernel.git -b upboard-4.9 linux-upboard
cd linux-upboard
make upboard_defconfig