Skip to content

Instantly share code, notes, and snippets.

@dansimau
dansimau / pgclone.sh
Created January 18, 2012 12:52
Clones a new PostgreSQL standby server from master
#/bin/sh -x
#
# Restores a slave node from the specified master and sets up recovery.conf
# with streaming replication.
#
# dsimmons@squiz.co.uk
# 2012-01-24
#
if [ -z "$1" -o "$1" == "--help" ]; then
@dansimau
dansimau / reduce-backups.sh
Created January 20, 2012 09:57
Prunes Squiz CMS backups to the last X number of days. Will bail out if the backups have broken, to avoid deleting backups if they may be needed.
#!/bin/bash
#
# Reduces the total number of Squiz CMS backups to the last X days', whilst
# also ensuring at least X number of backups always exist.
#
# In other words, we want only the last X number of days' backups unless the
# backups have failed, in which case we'd prefer to keep the old ones until
# the backup is running again.
#
# dsimmons@squiz.co.uk
@dansimau
dansimau / showdown.js
Created February 28, 2012 10:12
Markdown-to-HTML file converter using showdown JS library (Node.js)
#!/usr/bin/env node
/**
* Takes specified Markdown files outputs them as HTML.
*
* Requires showdown:
*
* npm install showdown
*
* dan@dans.im
@dansimau
dansimau / .gitignore
Created May 20, 2012 23:52 — forked from urschrei/mkflask.sh
Bootstrap a Flask project on Ubuntu Precise, with Puppet, Vagrant and Fabric. (For latest version, see https://github.com/dansimau/flask-bootstrap)
*~
*.pyc
.vagrant
venv
@dansimau
dansimau / README.md
Created July 13, 2012 10:39
Enable git-style colour output in regular diff on Mac OS X

Enable git-style colour output in regular diff

Mac OS X

  1. Install colordiff using Homebrew:

     brew install colordiff
    
  2. Add function to your ~/.bash_profile:

@dansimau
dansimau / nfs-remount.sh
Created July 17, 2012 15:33
Bash script to add psuedo-remount functionality to NFS mounts in Linux
#!/bin/bash
#
# Remount a filesystem with new options by unmounting it first (with umount)
# and mounting it again.
#
# Used for filesystems that do not support the -o remount option (eg. NFS).
#
# Compatible with Linux/bash only.
#
# 2012-07-17
@dansimau
dansimau / colourpicker.scpt
Created August 5, 2012 15:40
A colour picker app for Mac OS X
set the RGB16bit_list to (choose color)
-- convert choosen color to HEX
set the formatedColor to my RBG_to_HEX(RGB16bit_list)
set the clipboard to formatedColor
display dialog "HEX colour value (" & formatedColor & ") has been copied to the clipboard." with icon 1 buttons {"Dismiss"} default button {"Dismiss"} giving up after 10
on RBG_to_HEX(RGB_values)
-- this subroutine was taken from "http://www.apple.com/applescript/sbrt/sbrt-04.html"
set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
@dansimau
dansimau / test-md5-bin.lua
Created August 23, 2012 03:22
Testing performance of md5 hash calculation in lua vs node
require("md5")
local testname = "lua md5 sum hash test (binary)"
function test()
-- Create object hash
local object_key_plain = [[
"0.0.0.0",
80,
"www.example.com",
@dansimau
dansimau / grepurls.py
Created November 13, 2012 09:44
Recursive grep-like search for extracting URLs from a bunch of files
import os
import re
import sys
# Crazy URL regexp from Gruber
# http://daringfireball.net/2010/07/improved_regex_for_matching_urls
r = re.compile(r'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?]))')
# grep -r
for parent, dnames, fnames in os.walk(sys.argv[1]):

Trying out HHVM (JIT)

Following instructions to set up Wordpress (from http://www.hiphop-php.com/wp/?p=113):

# /usr/bin/hhvm --mode server --user www-data --config /etc/hhvm.hdf
/home/sgolemon/dev/hiphop-php/src/runtime/vm/translator/asm-x64.cpp:79 (makeExecable): mprotect @(nil) 32768 bytes failed (Cannot allocate memory)
/home/sgolemon/dev/hiphop-php/src/runtime/vm/translator/asm-x64.cpp:79 (makeExecable): mprotect @(nil) 32768 bytes failed (Cannot allocate memory)
Aborted (core dumped)