Skip to content

Instantly share code, notes, and snippets.

View wader's full-sized avatar
🦫

Mattias Wadman wader

🦫
View GitHub Profile
@wader
wader / dircast.php
Last active September 3, 2019 17:28
Serve a directory with mp3 files as a podcast feed
<?php
// put this script in web accessable directory with mp3 files and it will
// serve them as a podcast feed. can be used as index.php etc.
// absolute url for current request
function absolute_url() {
return
"http" . ($_SERVER["HTTPS"] != "" ? "s" : "") .
"://{$_SERVER["SERVER_NAME"]}" .
@wader
wader / gist:5724410
Created June 6, 2013 19:54
setValue:forKey: for readonly property test
#import <Foundation/Foundation.h>
@interface Test1 : NSObject
@end
@implementation Test1
- (id)retain {
return [super retain];
}
- (oneway void)release {
@wader
wader / gist:7016435
Last active April 12, 2022 15:41
ID3v2 notes

ID3v2 notes

Specs can be found at http://id3lib.sourceforge.net/id3/develop.html

Tag size is always a 4 byte synch safe big endian integer and unsynchronization does not affect it.

v2.2

Frame have 3 byte type.
Frame size is 3 bytes big endian integer (not synch safe).

@wader
wader / gist:7194297
Created October 28, 2013 10:07
KVO test
/*
2013-10-28 11:05:58.558 ivar_kvo_test[17451:303] ivar =
2013-10-28 11:05:58.559 ivar_kvo_test[17451:303] _ivarWithManualSetter =
2013-10-28 11:05:58.559 ivar_kvo_test[17451:303] _prop =
2013-10-28 11:05:58.560 ivar_kvo_test[17451:303] _propWithSetter =
2013-10-28 11:05:58.560 ivar_kvo_test[17451:303] setValue:forKey:ivar
2013-10-28 11:05:58.561 ivar_kvo_test[17451:303] observeValueForKeyPath: ivar
2013-10-28 11:05:58.561 ivar_kvo_test[17451:303] setValue:forKey:ivarWithManualSetter
2013-10-28 11:05:58.561 ivar_kvo_test[17451:303] observeValueForKeyPath: ivarWithManualSetter
@wader
wader / parse_multipart_byteranges.rb
Created January 3, 2014 18:28
Parse multipart byte ranges mime
# multipart byte ranges mime -> [[offset, content], ...]
def parse_multipart_byteranges(body, content_type)
# match boundary=...
match = /boundary=(.*)$/.match(content_type)
return nil if match.nil?
boundary = match[1]
# (\r\n)--boundary\r\npart\r\n--boundary(--)\r\n -> [part, ..]
parts = body.split(/(?:\r\n)?--#{boundary}(?:--)?\r\n/)
ranges = []
@wader
wader / gist:8472639
Created January 17, 2014 12:32
Dummy SMTP server that dumps all data
sudo python -m smtpd -n -d 0:25
@wader
wader / sparse_file.rb
Created January 25, 2014 16:57
Sparse ruby IO class
class SparseFile < IO
def initialize(ranges, total_length, fill = "\0")
@ranges = ranges
@total_length = total_length
@position = 0
@fill = fill
end
def rewind
@position = 0
@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:502174b82a94ff990b86
Last active May 27, 2017 12:29
Telia TG799vn v2 MediaAccess Gateway and SSH problem
# don't set QoS field in packets, the router seems to do something strange if set.
ssh -o IPQoS=cs0 ...