Skip to content

Instantly share code, notes, and snippets.

View wader's full-sized avatar
🦫

Mattias Wadman wader

🦫
View GitHub Profile
@wader
wader / gist:9688134
Created March 21, 2014 15:00
Ugly REXML::UndefinedNamespaceException workaround
require "rexml/document"
# in this case monkey patch to be able to read Inkscape "plain svg" files
# make the namespace stack start out to have inkscape: and sodipodi:
module REXML
module Parsers
class BaseParser
alias_method :old_stream, :stream=
def stream=(source)
old_stream(source)
@wader
wader / gist:10493693
Created April 11, 2014 19:16
Easy to edit JSON post script
#!/bin/sh
exec curl -X POST -H "Content-Type: application/json" -d "$(cat $0 | tail +3)" http://host/path
{
"some": {
"json": "here"
}
}
@wader
wader / gist:09953b1fdd7b1984016e
Created September 1, 2014 13:41
run a dbus-daemon that allows everything
TEMP=`mktemp /tmp/dbusconf.XXXXXX`
# generate dbus config that allows everything
echo '<busconfig><type>system</type><listen>d</listen><auth>ANONYMOUS</auth><allow_anonymous/><policy context="default"><allow send_destination="*" eavesdrop="true"/><allow eavesdrop="true"/><allow own="*"/></policy></busconfig>' > $TEMP
dbus-daemon --nofork --config-file $TEMP --address tcp:bind=0.0.0.0,port=1234
rm $TEMP
@wader
wader / gist:46f380b86b4bb0112e73
Last active August 29, 2015 14:22
nginx webdav and tranmission
server {
listen 80;
server_name bla;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name bla;
mattias@cocospro:ansible (master *)$ pwd
/Users/mattias/src/youtube-audio-dl/ansible
mattias@cocospro:ansible (master *)$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'precise64' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Adding box 'precise64' (v0) for provider: virtualbox
default: Downloading: http://files.vagrantup.com/precise64.box
==> default: Successfully added box 'precise64' (v0) for 'virtualbox'!
@wader
wader / mysqlselectdump.sh
Created September 24, 2011 12:49
Output select query as insert statements
#!/bin/bash
# Output select query as insert statements
#
# Ex: insert all users from database1 into database2 but replace password with "dummy"
# ./mysqlselectdump username database1 "SELECT id, name, \"dummy\" as password FROM users" users password | mysql -u username -ppassword database2
USERNAME="$1"
DATABASE="$2"
QUERY="$3"
INSERTTABLE="$4"
@wader
wader / gist:1245074
Created September 27, 2011 13:45
git push post-receive capistrano deploy hook script
#!/bin/bash
# requires that you use "set :deploy_via, :remote_cache" in deploy.rb
while read oldrev newrev ref
do
if [ "$ref" = "refs/heads/master" ] ; then
echo "Master branch pushed, deploying to staging"
# seams to be set to "." for hooks, unset to make things more normal
unset GIT_DIR
# deploy path, where "current", "releases", "shared" etc are
@wader
wader / gist:1299311
Created October 19, 2011 18:59
Paperclip change path migration helper
# WARNING: don't just use this without testing!
# This is not a database migration but i think it's quite convenient to do as a migration
# multiple styles has not been tested but should work
class ChangeAttachmentPaths < ActiveRecord::Migration
AttachmentPath = Rails.root.join("public", "system")
def self.paperclip_change_path(table, column, old_opt, new_opt)
model = table.to_s.classify.constantize
@wader
wader / gist:1555889
Created January 3, 2012 17:19
Wav merge
// a bit hackish way of merging two wav files, assumes raw samples.
#import <Foundation/Foundation.h>
#define RIFF_ID 0x52494646 // "RIFF"
#define RIFF_FMT_ID 0x666d7420 // "fmt "
#define RIFF_DATA_ID 0x64617461 // "data"
typedef struct riffChunkHeader {
UInt32 rsc_id; // big endian
@wader
wader / printmethods.awk
Created February 8, 2012 17:10
Print class and instance methods declarations from Objective-C implementation
#!/usr/bin/env awk -f
# print class and instance methods declarations from implementation
# Usage: ./printmethods.awk class.m or awk -f printmethods.awk class.m
/^[[:space:]]*@implementation/ {
implementation = 1;
}
/^[[:space:]]*@end/ {
implementation = 0;