Skip to content

Instantly share code, notes, and snippets.

View runekaagaard's full-sized avatar

Rune Kaagaard runekaagaard

  • Copenhagen, Denmark
View GitHub Profile
@runekaagaard
runekaagaard / ableton_mencoder.sh
Created August 27, 2014 06:51
Good ffmpeg options for Ableton playback
ffmpeg -i [INPUT_FILE] -an -pix_fmt yuv420p -vcodec mjpeg -f mov -y [OUTPUT_NAME].mov
@runekaagaard
runekaagaard / gist:aec4e53de4097f46f797
Created May 28, 2014 11:31
manage.py Only print statements
stdbuf -o0 python manage.py runserver 127.0.0.1:8001 2>&1 | stdbuf -o0 sed "s/Quit the server with CONTROL-C\./__THETIME__/g" | stdbuf -o0 grep -v -E '("GET )|("POST )|(0 errors found)|(, using settings )|(Development server is running at)|(Validating models\.\.\.)' | awk '{ gsub("__THETIME__", "SERVER RELOADED AT " strftime("%Y-%m-%d %H:%M:%S" "\n======================================") ,$0); print $0; fflush(); }'
@runekaagaard
runekaagaard / pgx.rst
Last active September 18, 2018 14:09
Bash scripts for extracting individual databases from a sql file dumped using pg_dumpall

Postgresql Xtra commands

  • pgx_list_dbs: Lists the names of databases in an .sql file dumped using pg_dumpall.
  • pgx_extract_db: Extracts a single database from a sql file dumped with pg_dumpall and outputs its content to stdout.

Installation

@runekaagaard
runekaagaard / celerybeat
Created March 27, 2013 13:57
An /etc/init.d/celerybeat script modified from https://raw.github.com/ask/celery/master/contrib/generic-init.d/celeryd to support a status command using the standard lsb functions.
#!/bin/bash
# =========================================================
# celerybeat - Starts the Celery periodic task scheduler.
# =========================================================
#
# :Usage: /etc/init.d/celerybeat {start|stop|force-reload|restart|try-restart|status}
# :Configuration file: /etc/default/celerybeat or /etc/default/celeryd
#
# See http://docs.celeryq.org/en/latest/cookbook/daemonizing.html#init-script-celerybeat
#!/usr/bin/env python
# encoding=utf-8
import sys
import os
from pprint import pprint
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qa.settings")
from django.contrib.contenttypes.models import ContentType
# Output utf-8 on the command line, why is this buggy on my box?
reload(sys)
@runekaagaard
runekaagaard / fizzbuzz-forloop.php
Created August 7, 2012 19:23
FizzBuzz solutions
<?php
function fizzbuzz($n) {
for ($f=$b=$i=1;
$i<=$n;
$line = '',
($f==3 && !$f=0) ? $line = "Fizz" : null,
($b==5 && !$b=0) ? $line .= "Buzz" : null,
print ($line !== '' ? $line : $i) . "\n",
++$f,++$b,++$i
@runekaagaard
runekaagaard / php-generator-example.php
Created July 4, 2012 11:02
A userland implementation of a generator function. A bit like a python context manager too.
<?php
namespace Functional;
error_reporting(E_ALL|E_STRICT);
const BEFORE = 1;
const NEXT = 2;
const AFTER = 3;
const FORWARD = 4;
@runekaagaard
runekaagaard / gist:1729500
Created February 3, 2012 10:14
/usr/local/bin/hg-delete-obstructed-files
#!/usr/bin/env php
<?php
$obstructed_files = array();
foreach (array_filter(explode("\n", `hg status $(hg root)`)) as $line) {
if ($line{0} !== "!") continue;
$obstructed_files[] = trim($line, "! ");
}
$files_str = implode(" ", $obstructed_files);
$cmd1 = "hg revert $files_str";
$cmd2 = "hg rm $files_str";
@runekaagaard
runekaagaard / gist:934612
Created April 21, 2011 14:21
firstset, firstfull, setor, fullor userland implementation.
<?php
// Errors on.
error_reporting(E_ALL);
ini_set('display_errors', 1);
/**
* Returns the first passed argument that is set.
*
* @return mixed
*/
@runekaagaard
runekaagaard / CakePHP 2.0.0-dev
Created April 21, 2011 10:40
Popular PHP frameworks/CMS: isset/empty in ternary operator
Instances of isset:
###################
1 return isset($this->request->params['action']) ? $this->request->params['action'] : '';
2 $this->plugin = isset($request->params['plugin']) ? $request->params['plugin'] : null;
3 $enable = isset($settings['enabled']) ? $settings['enabled'] : true;
4 $newUnique = isset($value['unique']) ? $value['unique'] : 0;
5 $oldUnique = isset($old[$name]['unique']) ? $old[$name]['unique'] : 0;
6 $fields[$key] = isset($matches[4]) ? $matches[2] . '.' . $matches[4] : $matches[1];
7 $default = isset($col['default']) ? $col['default'] : null;