Skip to content

Instantly share code, notes, and snippets.

View mattieb's full-sized avatar

Mattie B. mattieb

View GitHub Profile
@mattieb
mattieb / smtptome.py
Created March 1, 2013 20:58
Spawns a little SMTP server that will redirect all mail relayed through it to you.
import asyncore
import smtpd
MY_ADDRESS = '[email protected]'
class RedirectingProxy(smtpd.PureProxy):
def _deliver(self, mailfrom, rcpttos, data):
smtpd.PureProxy._deliver(self, mailfrom, [MY_ADDRESS], data)
if __name__ == '__main__':
@mattieb
mattieb / Sender.java
Created April 2, 2013 17:46
Just a silly little test of Java multicasting.
import java.net.*;
class Sender {
public static void main(String[] args) throws Throwable {
MulticastSocket socket = new MulticastSocket(new InetSocketAddress(InetAddress.getByName("10.42.0.3"), 9999));
InetAddress groupAddress = InetAddress.getByName("239.192.0.1");
socket.send(new DatagramPacket(new byte[0], 0, groupAddress, 9999));
}
}
@mattieb
mattieb / gist:5396214
Created April 16, 2013 14:11
Why PHP sucks, volume 295: how array stupidity breaks json_encode
<?php
var_dump(json_encode(array(1, 2, 3)));
var_dump(json_encode(array(0=>1, 1=>2, 2=>3)));
var_dump(json_encode(array(1=>1, 2=>2, 3=>3)));
$a = array(1, 2, 3);
var_dump(json_encode($a));
unset($a[1]);
var_dump(json_encode($a));
@mattieb
mattieb / macmodel.py
Created August 7, 2013 13:58
A slightly less quick-and-dirty way to look up a Mac's friendly model name.
#!/usr/bin/env python
#
# Looks up a Mac's friendly model name.
#
# Based on http://apple.stackexchange.com/a/98089/21050
#
from subprocess import check_output
from urllib import urlopen
import xml.etree.ElementTree as ET
@mattieb
mattieb / time_del.py
Last active February 28, 2022 22:02
Time various methods of removing a possibly-present item from a dict
#!/usr/bin/python
import time
def new_d():
return {
1: 2, 3: 4, 5: 6, 7: 8, 9: 10,
11: 12, 13: 14, 15: 16, 17: 18, 19: 20
}
@mattieb
mattieb / service1.apacheconf
Last active December 26, 2015 03:08
Running multiple mod_wsgi applications under different accounts
# In CentOS 5, mod_wsgi can be installed from EPEL
# <http://fedoraproject.org/wiki/EPEL>. I use mod_wsgi to run several
# independent WSGI services, each of which is contained in its own
# RPM.
#
# In addition to the LoadModule statement covering mod_wsgi itself,
# each service carries its own .conf file that is installed to
# /etc/httpd/conf.d. Because they are associated with different
# subsystems, they must be run under appropriate accounts. Determining
# how to do so took some poring over the documentation.
@mattieb
mattieb / vagrant.pp
Created November 11, 2013 19:48
Puppet manifest for octothorpe development in a Vagrant VM (currently broken)
class {'asterisk':
configs => false,
}
file {'/etc/asterisk':
require => Class['asterisk'],
ensure => link,
target => '/vagrant/etc/asterisk',
force => true,
}
@mattieb
mattieb / bashing_bash.txt
Created November 19, 2013 16:39
bashing bash
megaweapon:tmp matt$ mkdir -p foo/baz
megaweapon:tmp matt$ cd foo
megaweapon:foo matt$ PATH=/tmp/foo/baz:/tmp/foo:$PATH
megaweapon:foo matt$ cat >bar
#!/bin/sh
echo "this isn't the bar you're looking for"
megaweapon:foo matt$ chmod +x bar
megaweapon:foo matt$ bar
this isn't the bar you're looking for
megaweapon:foo matt$ cat >baz/bar
@mattieb
mattieb / bashing_bash_2.txt
Created November 19, 2013 16:51
bashing bash, the encore
megaweapon:foo matt$ # an encore to https://gist.github.com/zigg/7548324
megaweapon:foo matt$ rm baz/bar
megaweapon:foo matt$ bar
-bash: /tmp/foo/baz/bar: No such file or directory
megaweapon:foo matt$ which bar
/tmp/foo/bar
megaweapon:foo matt$ hash -r
megaweapon:foo matt$ bar
this isn't the bar you're looking for
@mattieb
mattieb / unix_xmlrpc.py
Last active December 31, 2015 18:59
Python xmlrpclib client over Unix sockets
#!/usr/bin/env python
#
# Works for Python 2.4. Newer versions of Python changed xmlrpclib, a lot...
#
import httplib
import socket
import xmlrpclib