Skip to content

Instantly share code, notes, and snippets.

View RomkeVdMeulen's full-sized avatar

Romke van der Meulen RomkeVdMeulen

View GitHub Profile
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sudo sh -c "echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
sudo apt-get update -qq
sudo apt-get install -qqy lxc-docker
#!/bin/bash
# Auto suspend and wake-up script
#
# Puts the computer to sleep and automatically wakes it up at specified time
#
# Written by Romke van der Meulen <romke.vd.meulen@gmail.com>
#
# Takes a 24-hour time HH:MM as its argument
# Example:
#!/bin/sh
# Auto suspend and wake-up script
#
# Puts the computer to sleep and automatically wakes it up after specified period
#
# Courtesy of http://ubuntuforums.org/member.php?u=130449
# from thread http://ubuntuforums.org/showthread.php?t=938533&page=2
# Edited by Romke van der Meulen <romke.vd.meulen@gmail.com>
@RomkeVdMeulen
RomkeVdMeulen / Renderable.php
Last active August 29, 2015 14:14
Baseclass for simple template inheritance
<?php
/**
* Every renderable can have template files in the directory matching its class. The matching directory
* follows the Zend naming convention, except lowercased to prevent conflicts between OSes.
* E.g. for class `ReqHandler_Home` the path to template "view" would be `reqhandler/home/view.tpl.php`
* This obeys inheritance: e.g. if class `ReqHandler_Home extends ReqHandler_Base`
* and template `reqhandler/base/view.tpl.php` exists, than that template is used by default,
* but can be overriden by `reqhandler/home/view.tpl.php`
*
@RomkeVdMeulen
RomkeVdMeulen / up.sh
Created February 4, 2015 20:33
Script for automatically updating a number of projects in your workspace
#!/bin/bash
###############################################
# #
# Auto-update externals #
# #
# Will go into your workspace (~/workspace) #
# and `git pull` all projects listed in #
# .git-auto-pull, and will `svn up` all #
# projects listed in .svn-auto-up #
@RomkeVdMeulen
RomkeVdMeulen / docker-mysqlroot.sh
Last active August 29, 2015 14:15
Bash function for interacting with dockerized mysql server
# Use `mysqlroot` to go to interactive mysql shell,
# type e.g. `mysqlroot "SHOW DATABASES" to directly execute query
# or type `mysqlroot my-script.sql` to execute script
function mysqlroot() {
if [ $# -eq 0 ]; then
docker run -it --link mysql_mysql_1:mysql --rm mariadb sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
else
if [ -f $1 ]; then
cat $1 | docker run -i --link mysql_mysql_1:mysql --rm mariadb sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
else
@RomkeVdMeulen
RomkeVdMeulen / logrotate_dockerized_mysql_backup
Created February 13, 2015 17:45
Logrotate backup instructions for a Dockerized mysql server.
# Logrotate backup instructions for a Dockerized mysql server.
# This will automatically dump all your databases once a day
# and maintain a compressed one week backlog.
# Write this config to /etc/logrotate.d/mysql-backup
/var/backups/db.sql.gz {
daily
rotate 8
nocompress
create 640 root adm
postrotate
@RomkeVdMeulen
RomkeVdMeulen / smooth-anchors-scroll.js
Created July 30, 2016 14:38
Smooth scrolling to anchors using jQuery
$('a').click(function(ev){
href = this.href.replace(window.location.href,'');
if ( href[0] != '#' || !$(href) ) {
return;
}
$('html, body').animate({ scrollTop: $(href).offset().top }, 500);
ev.stopPropagation();
return false;
});
@RomkeVdMeulen
RomkeVdMeulen / autowrap.js
Last active July 30, 2016 18:14
Vanilla JS code to have textareas wrap text that exceeds the `col` value. Unlike browser wrapping it inserts newlines that are preserved when you copy that textarea contents. Tries to wrap on words if possible.
Array.prototype.forEach.call(document.querySelectorAll("textarea.autowrap"), function(textarea) {
function wrap() {
var cursorPos = textarea.selectionStart;
var newValue = textarea.value.split("\n").map(function(line) {
var wrapped = "";
while (line.length > textarea.cols) {
var wrapPos = line.lastIndexOf(" ", textarea.cols);
if (wrapPos === -1) {
wrapPos = textarea.cols;
}