Skip to content

Instantly share code, notes, and snippets.

View EmmanuelKasper's full-sized avatar

Emmanuel Kasper EmmanuelKasper

  • Vienna, Austria
View GitHub Profile
@EmmanuelKasper
EmmanuelKasper / closure.js
Last active December 16, 2016 11:43
Closure Example
var loneTalker = {};
var addSpeach = function(name) {
var text = 'Hello ' + name;
var talk = function() {
console.log(text);
};
loneTalker.talk = talk;
};
@EmmanuelKasper
EmmanuelKasper / create_evolution.sh
Last active May 10, 2016 18:24
Create an evolution script for the play framework based on pg_dump
# after that you need to insert # --- !Ups on top of the generated file
echo '# --- !Ups' > conf/evolutions/default/2.sql
# column inserts are needed in case of new model properties
# we keep only the insert statements, pg_dump comments confuse ebean/play
pg_dump --column-inserts \
--inserts --data-only --exclude-table=play_evolutions \
--username popcon -h localhost popcon \
| grep '^INSERT INTO' \
>> conf/evolutions/default/2.sql
@EmmanuelKasper
EmmanuelKasper / add-certs.sh
Last active February 14, 2016 11:47
Add a self signed certificate to Chrome / Chromium on Linux
#!/bin/sh
# you need to install the libnss3-tools package or equivalent
if [ $# -lt 2 ]; then
echo "Usage: $0 hostname port"
exit 1
fi
hostname=$1
port=$2
pct enter 142
ps ax
PID TTY STAT TIME COMMAND
1 ? Ss 0:00 init [2]
831 ? Ss 0:00 /sbin/rpcbind -w
951 ? Ssl 0:00 /usr/sbin/rsyslogd
1025 ? Ss 0:00 /usr/sbin/atd
1071 ? Ss 0:00 /usr/sbin/cron
1086 ? Ss 0:00 /usr/bin/dbus-daemon --system
@EmmanuelKasper
EmmanuelKasper / Puppet Canonical
Last active January 3, 2016 20:59
A canonical puppet deployment file, based on the package / file /service hierarchy
class amanda {
package { "amanda-client":
ensure => installed,
before => File['/etc/amandahosts'],
}
file { "/etc/amandahosts":
ensure => file,
owner => "backup",
group => "backup",
@EmmanuelKasper
EmmanuelKasper / backup_vhosts
Last active December 27, 2015 13:38
Simple backup of all Virtual Hosts
#!/bin/sh
[ -d /var/backups/vhosts ] || mkdir /var/backups/vhosts
VHOST_DIR=/srv/www/
cd $VHOST_DIR
for VHOST in *; do
if [ "$VHOST" != "basebox.libera.cc" ]; then
tar cpzf /var/backups/vhosts/$VHOST.tar.gz $VHOST
@EmmanuelKasper
EmmanuelKasper / backup_postgres
Last active December 27, 2015 09:09
cron.daily entry for postgres backup all
#!/bin/sh
su -l postgres -c /usr/local/sbin/backup_postgres
# a nice comment
#!/bin/sh
# to be run as postgres user
# a database should be restored as posgres user with
# dropdb popcon
# createdb --encoding=UNICODE --owner=popcon popcon
# psql popcon < popcon.psql
set -e
do_bkp() {
/usr/bin/pg_dump -U postgres --column-inserts --file=/var/backups/postgres/$i.psql $i
@EmmanuelKasper
EmmanuelKasper / ansibleForVagrantboxes
Last active December 25, 2015 17:29
If you've just downloaded one of the vagrant base boxes from http://www.vagrantbox.es/, this gist shows you how to tame them with ansible
# create a temporary inventory file
echo "vagrant ansible_ssh_host=localhost ansible_ssh_user=vagrant ansible_ssh_port=2222" > hosts
# run a root shell in the vagrant env
ansible \
--inventory hosts \
--private-key=/opt/vagrant/embedded/gems/gems/vagrant-1.2.7/keys/vagrant \
--sudo \
--args "id" vagrant
@EmmanuelKasper
EmmanuelKasper / qemu-autostable-serial
Created July 3, 2013 15:38
Automatic Debian7 installation on qemu, using libvirt, the debian installer and a preseed file, inside a terminal (ie you can start it on a remote server)
#!/bin/sh
export OS=Debian7
virt-install \
--connect qemu:///system \
--name ${OS} \
--ram 512 \
--vcpus 1 \
--file ${OS}.img \