Skip to content

Instantly share code, notes, and snippets.

View zvyn's full-sized avatar
🐧

Milan Oberkirch zvyn

🐧
View GitHub Profile
@zvyn
zvyn / list-package-sizes.bash
Last active April 17, 2018 20:09
My disk went full so I wrote the following script to generate a list of all installed packages with their (theoretical) disk-usage as estimated by pacman. #ArchLinux #pacman
#!/bin/bash
function list-package-sizes () {
if [ $1 ]; then
case $1 in
-h|--help)
local errno=0
;;
*)
local errno=1
@zvyn
zvyn / declare -A array=$(the php-way)
Created August 23, 2013 15:31
Store multiple values in a declarative array, including the error-code of a command. (Note that in most cases you want to use $? directly or $PIPESTATUS if you have a pipe to get just the error-code.) Needs bash-version > 4.
#!/bin/bash
# generates a string in the form of an array-declaration and puts it into declare -A
declare -A exit_status=$(echo -n "( \
[output]=\"" ; cat /no/such/file 2>&1 ; echo -en "\"
[errno]=$?
)")
# to test it:
echo error ${exit_status[errno]}: ${exit_status[output]} >/dev/stderr
@zvyn
zvyn / color_functions.sh
Created November 10, 2013 21:38
Functions to color sh-output. Useful for logging or bash-prompt.
changeColor () {
## Usage
local help_message="\
Usage:
changeColor ((fg|bg|light|light-bg)? color (bold|dim|underlined|inverted)*)+
Example:
changeColor fg red light-bg green underlined bold"
#/>
## local properties
function ssh_no_memory() {
command ssh $*
echo -n "Remove "
tail -1 $HOME/.ssh/known_hosts | cut -d' ' -f1 | tr -d '\n'
echo " from known hosts?"
read yesno
case $yesno in
Y|y|Yes|yes|YES|Nagut|Jo|Jepp|Jadoch|klar)
sed -i '$ d' $HOME/.ssh/known_hosts
;;
@zvyn
zvyn / designer.html
Created June 10, 2014 14:40
designer
<link rel="import" href="../core-pages/core-pages.html">
<link rel="import" href="../core-drawer-panel/core-drawer-panel.html">
<link rel="import" href="../core-input/core-input.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../core-item/core-item.html">
<polymer-element name="my-element">
<template>
<style>
#!/bin/env python
import logging
def float_to_bin(x):
p = 0
while ((2 ** p) * x) % 1 != 0:
logging.info('Remainder = %s' % ((2 ** p) * x - int((2 ** p) * x)))
p += 1
[Unit]
Description=Create dynamic bg.svg in /tmp.
[Service]
User=nobody
Group=nobody
ExecStart=/usr/local/bin/dynbg.py /usr/local/etc/dynbg.svg /tmp/bg.svg
Restart=no
Type=oneshot
@zvyn
zvyn / maybe.py
Last active December 29, 2016 04:33 — forked from senko/maybe.py
# maybe.py - a Pythonic implementation of the Maybe monad
# Copyright (C) 2014. Milan Oberkirch <milan.py@oberkirch.org>
# Copyright (C) 2014. Senko Rasic <senko.rasic@goodcode.io>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@zvyn
zvyn / dump-imap.py
Last active August 29, 2015 14:27 — forked from FiloSottile/dump-imap.py
Simple script to dump an IMAP folder into eml files
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
import imaplib
import getpass
import argparse
argparser = argparse.ArgumentParser(description="Dump a IMAP folder into .eml files")
argparser.add_argument('-s', dest='host', help="IMAP host, like imap.gmail.com", required=True)
argparser.add_argument('-u', dest='username', help="IMAP username", required=True)
@zvyn
zvyn / config.json
Created January 31, 2016 06:53 — forked from anonymous/config.json
Bootstrap Customizer Config
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#5b9aa9, 6.5%)",
"@brand-success": "#889a3a",