Skip to content

Instantly share code, notes, and snippets.

View sixtyfive's full-sized avatar
🐯
Rawrrr.

J. R. Schmid sixtyfive

🐯
Rawrrr.
View GitHub Profile
@sixtyfive
sixtyfive / reduce.rb
Created August 3, 2017 09:35
Examples for how to use Ruby's Array#each_with_object, Array#reduce (thanks to #ruby's Radar and baweaver)
src = [{foo: 1.2, bar: 2.3}, {foo: 3.2, bar: 3.0}]
src.each_with_object({foo: [], bar: []}) { |data, acc| acc[:foo] << data[:foo]; acc[:bar] << data[:bar] }
# => {:foo=>[1.2, 3.2], :bar=>[2.3, 3.0]}
[{foo: 1.2, bar: 2.3}, {foo: 3.2, bar: 3.0}].reduce { |a,b| a.merge(b) { |_,o,n| Array(o) << n } }
# => {:foo=>[1.2, 3.2], :bar=>[2.3, 3.0]}
@sixtyfive
sixtyfive / config.ru
Last active August 1, 2017 13:18
Example showing a Sinatra RuntimeError upon shutdown
require 'sinatra/base'
class Application < Sinatra::Base
get '/' do
'Hello World!'
end
end
run Application.run!
@sixtyfive
sixtyfive / fixdebianupgrade.md
Last active July 16, 2017 18:40
Debian refusing to upgrade because of udev...

If you recently tried to update a Debian-based box and during the upgrade got these two messages, among others:

insserv: Service mountkernfs has to be enabled to start service udev
update-rc.d: error: insserv rejected the script header

Then this is what will help you get the upgrade done:

  1. Edit /etc/init.d/udev and remove mountkernfs from the line starting with Required-Start:, keep the rest of the line though
@sixtyfive
sixtyfive / README.md
Created July 15, 2017 11:38
My dream window manager

My dream window manager

  • every function accessible by mouse needs to be accessible by keyboard and vice-versa

  • there are 1-n screens

    • each screen has 1-n workspaces, but the default is 12
    • workspaces do not span screens
@sixtyfive
sixtyfive / whatshouldihaveforbreakfast.sh
Created July 8, 2017 12:29
What should I have for breakfast? Let's ask Cpt. Random!!!
ruby -e 'puts "For breakfast: #{["scrambled eggs, grilled tomatoes and rye bread", "musli with oranges, raisins and warm milk", "rye bread with various spreads and cheeses"].sample}."'
@sixtyfive
sixtyfive / nginx-md.php
Created November 23, 2016 20:15
How to serve static Markdown directly through Nginx using php-fpm
<?php
error_reporting(0);
# Install from https://github.com/michelf/php-markdown
require_once 'php-markdown/vendor/autoload.php';
use \Michelf\Markdown;
$text = file_get_contents($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']);
$html = Markdown::defaultTransform($text);
?>
@sixtyfive
sixtyfive / kb_layout.sh
Created November 21, 2016 19:59
New i3blocks block for displaying current keyboard layout
#!/bin/bash
#
# Save as /usr/share/i3blocks/kb_layout, then use it by
# adding something like this to your i3blocks configuration:
#
# [kb_layout]
# interval=3
KB_LANG=$(setxkbmap -query | grep layout | cut -d ':' -f 2)
KB_LANG=${KB_LANG//[[:space:]]/}
@sixtyfive
sixtyfive / slash-config-cake.sh
Last active October 22, 2016 09:01
Script for handling the Cake scheduler on EdgeOS
# Save as /etc/config/cake
# The interface to be limited
IF=eth0
# Kbps values
DNSPEED=100000
UPSPEED=7500
# Percentages
DNLIMIT=60 # ERLite3 can only manage 60Mbps
UPLIMIT=95
@sixtyfive
sixtyfive / ch02ex03.R
Created October 13, 2016 12:19
Jockers ch. 3, ex. 2
#!/usr/bin/env Rscript
#
# Obacht! Interaktiver Modus und Skripte funktionieren in R teils verschieden
# voneinander. Interaktiv scan() = geskriptet readLines()! Oder man löst es wie
# unten zu sehen...
cat("\nBitte geben Sie eine positive ganze Zahl ein: ")
benutzereingabe = scan(file('stdin'), what = integer(), n = 1)
gausssche_summe = sum(1:benutzereingabe) # Wenn man Vektoren benutzen möchte.
# Viel cooler ist Mathe:
[...]
d-i preseed/late_command string \
echo -e "\n# The secondary network interface" >> /target/etc/network/interfaces; \
echo "allow-hotplug eth1" >> /target/etc/network/interfaces; \
echo "iface eth1 inet dhcp" >> /target/etc/network/interfaces
d-i preseed/late_command string echo -e "\n# The public network interface\nallow-hotplug eth2\niface eth2 inet static\n address XXX\n netmask XXX\n gateway XXX" >> /target/etc/network/interfaces
d-i finish-install/keep-consoles boolean true
d-i finish-install/reboot_in_progress note