Skip to content

Instantly share code, notes, and snippets.

View michd's full-sized avatar

MichD michd

View GitHub Profile
@michd
michd / xkcd-publish-dates.user.js
Last active July 9, 2020 14:24
XKCD, but with publish dates appended to the title
// ==UserScript==
// @name XKCD with publish dates
// @author MichD
// @include /^https?://xkcd.com.*$/
// @version 1
// @grant none
// ==/UserScript==
function pad(text) {
return (text.length < 2 ? "0" : "") + text;
@michd
michd / rpi-tv-select.bash
Last active December 13, 2019 10:23
A user-friendly bash script for playing content on a TV through Raspberry Pi
#!/bin/bash
# This script collects files in a media folder and presents them in a dialog,
# where you can select one with arrow keys and enter. It is then played with
# omxplayer.
# The script allows navigating into subdirectories, and back up as well. Spaces
# in file names should also work properly.
# Assumptions:
# - `whiplash` is installed. `dialog` is an alternative, but it didn't work well
@michd
michd / snake.c
Created May 20, 2019 08:05
ncurses-snake (cobbled together in a couple of hours)
#include <ncurses.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "snake.h"
#define SNAKE_BOX_W 32
#define SNAKE_BOX_H 16
#define SNAKE_LOCATIONS (SNAKE_BOX_W * SNAKE_BOX_H)
#define INITIAL_SNAKE_LENGTH 5
@michd
michd / radio.bash
Created May 18, 2019 09:15
.bash_profile snippet for listening to Digitally Imported sites' radio streams from the command line
# Usage:
# $ radio <network> <channel-key>
# Where network is a network key as specified in http://api.audioaddict.com/v1/networks
# and where channel-key is the name of a channel as seen in a channel page URL
# The script will ask for a listen key and save it in ~/.listen_key if you don't
# have one on file yet.
radio() {
# Modify playCmd to launch the stream with a different player
local playCmd="mplayer "
local network=$1
@michd
michd / .bash_profile
Last active August 29, 2015 14:01
My bash prefix (PS1)
# Return current git branch prefixed with |, nothing if not in git repo
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\|\1/'
}
# Returns some "dirty" flags if they apply, nothing if not in git repo,
# or current branch is clean.
# Flags: M = modified files, ? = untracked files, % = unresolved merges
# These flags are prefixed with a |
parse_git_dirty() {
@michd
michd / jsondata.js
Last active December 15, 2015 22:49
Load JSON file as data in vanilla JS
loadJSON({
"lorem": "Lorem ipsum dolor sit amet",
"consectetur": "adipisicing elit, laboris, adipisicing dolores nulla tempore cupidatat"
});
@michd
michd / forEach.js
Created October 28, 2012 12:41
JavaScript forEach Object, Array and String
(function () {
"use strict";
/**
* Iterate over an Object, Array of String with a given callBack function
*
* @param {Object|Array|String} collection
* @param {Function} callBack
* @return {Null}
*/