Skip to content

Instantly share code, notes, and snippets.

@meeuw
meeuw / injectfunction.py
Last active August 29, 2015 13:55
Script to inject error_log debug backtrace to create xrefs in PHP scripts
#!/usr/bin/python
import sys
import fileinput
import re
for line in fileinput.input(inplace=True):
if fileinput.isfirstline():
function = False
interface = False
class_name = ""
comment = False
@meeuw
meeuw / bottleswift.py
Created February 26, 2014 19:40
fake/dummy swift/cloudfiles server for debugging / development purposes
from bottle import route, put, run, request, response
from time import time
from hashlib import md5
import json
from os import makedirs, walk, stat
from os.path import dirname
from mimetypes import guess_type
from datetime import datetime
@route('/')
def index():
@meeuw
meeuw / fix_utf8_latin1.py
Created February 26, 2014 19:45
script to fix a messed up mysql database with invalid collation / charset and invalid use of utf8encode / utf8decode in latin1 tables.
import MySQLdb
import unicodedata
mysql_cred = {'host':'localhost', 'user':'root', 'passwd':'new-password', 'db':'test'}
conn_latin1 = MySQLdb.connect(**mysql_cred)
c_latin1 = conn_latin1.cursor(MySQLdb.cursors.DictCursor)
c_latin1.execute("SELECT id FROM texts")
ids = []
while 1:
@meeuw
meeuw / svnmergetool.sh
Created March 1, 2014 20:04
use vimdiff as external merge tool for subversion
#!/bin/bash
vimdiff $1 $2 $3
@meeuw
meeuw / svnvimdiff.sh
Created March 1, 2014 20:05
use vimdiff as external difftool in subversion
#!/bin/bash
vimdiff $6 $7
@meeuw
meeuw / mergetool.py
Created March 1, 2014 20:05
script to cherrypick a list of subversion revisions
#!/usr/bin/python
import subprocess
import fileinput
if False:
revs = []
for line in subprocess.check_output(['svn', 'merge', '../branches/dev', '--dry-run']).split('\n'):
if line.startswith('--- Merging'):
s = line.split(' ')
@meeuw
meeuw / dmdbt.php
Created March 10, 2014 20:29
log php backtrace to a file
<?php
$dmdbtf = fopen('/home/meeuw/log.txt', 'w');
function dmdbt($bt) {
global $dmdbtf;
if (isset($bt[0]['class']) && isset($bt[1]['class'])) {
fwrite($dmdbtf, "\"{$bt[1]['class']} {$bt[1]['function']}\" -> ".
"\"{$bt[0]['class']} {$bt[0]['function']}\"\n"
);
fflush($dmdbtf);
}
@meeuw
meeuw / phpfilter.py
Created March 20, 2014 20:47
git smudge filter to k&r style php code
#!/usr/bin/python
import sys
import re
CANTSMUDGE = '<?php //cantsmudgethis ?>'
class RewStream:
def __init__(self, holdlines=0):
self.holdlines = holdlines
self.current = 0
@meeuw
meeuw / grid style visualizer.js
Created April 23, 2014 19:48
chrome userscript to visualize the http://960.gs/ containers / grid
// ==UserScript==
// @match http://www.carddreams.nl/*
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "window.$=jQuery.noConflict(true);(" + callback.toString() + ")();";
@meeuw
meeuw / loopmount.sh
Last active April 23, 2016 10:12
dracut module for loop mounting a root filesystem
#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
if getargbool 0 rd.loop; then
info "Mount /sysroot as r/w"
mount -o remount,rw /sysroot
mkdir /run/initramfs/loop
mount -o bind /sysroot /run/initramfs/loop
umount /sysroot