Skip to content

Instantly share code, notes, and snippets.

View mapkyca's full-sized avatar
💭
Always out numbered, Never out gunned

Marcus Povey mapkyca

💭
Always out numbered, Never out gunned
View GitHub Profile
@mapkyca
mapkyca / methinks.php
Last active December 23, 2015 23:59
A rough implementation of https://en.wikipedia.org/wiki/Weasel_program, experimenting with a simple genetic algorithm.
<?php
/**
* Genetic algorithm test.
* This is basically a rough implementation of the Weasel program
* https://en.wikipedia.org/wiki/Weasel_program
*/
$ascii = "abcdefghijklmnopqrstuvwxyz "; // Ascii characters
@mapkyca
mapkyca / .procmailrc
Created September 4, 2013 10:00
Procmail script to encrypt outgoing root email before forwarding.
SUBJECT=`formail -xSubject:`
FROM=`formail -xFrom:`
:0 c
*^To:.*root.*
|formail -I "" | gpg --trust-model always -ear "marcus@marcus-povey.co.uk" | mail -r "$FROM" -s "$SUBJECT" marcus@example.org
@mapkyca
mapkyca / strip_replies_regexp.php
Created August 1, 2013 15:39
Strip email replies from an email message body. Note, this regex is simplistic, since stripping replies reliably is a whole world of hurt.
// Try simple regex, strip quoted (&gt;) replies from an email
return preg_replace('/(^\w.+:\n)?(^&gt;.*(\n|$))+/mi', '', $message);
// Try simple regex, strip replies from email using >
return preg_replace('/(^\w.+:\n)?(^>.*(\n|$))+/mi', '', $message);
@mapkyca
mapkyca / security_home_api.py
Last active December 18, 2015 12:29
A modification of my earlier security.py which gives an example of how such a security tool could interact with the Home.API application.
import piface.pfio
import time
import sys
import syslog
import json
import urllib
import httplib
class SecurityIndicator:
""" A switch and LED link: Displays light when switch is closed """
@mapkyca
mapkyca / security.py
Created June 13, 2013 15:48
A home security system. Logs when windows are opened or closed to the syslog, and gives you an indicator panel so you can see at a glance whether a you've left something open before walking out of the house!
import piface.pfio
import time
import sys
import syslog
class SecurityIndicator:
""" A switch and LED link: Displays light when switch is closed """
def __init__(self, pin_pair, label):
self.pin_pair = pin_pair
@mapkyca
mapkyca / crossing_lights.py
Created May 27, 2013 15:00
Piface/Raspberry Pi Pelican crossing light control.
import piface.pfio
import time
import sys
class crossinglight:
""" A (UK) Crossing traffic light """
def __init__(self, red_pin, amber_pin, green_pin, red_man_pin, green_man_pin, beeper, button):
self.red_pin = red_pin
self.amber_pin = amber_pin
@mapkyca
mapkyca / traffic_lights.py
Last active December 17, 2015 18:58
Drive a simple set of (UK) traffic lights using a Raspberry Pi and PiFace.
import piface.pfio
import time
import sys
class trafficlight:
""" A (UK) Traffic light """
def __init__(self, red_pin, amber_pin, green_pin, start_on_red = False):
self.red_pin = red_pin
self.amber_pin = amber_pin
@mapkyca
mapkyca / piface_cycle_leds.py
Last active December 17, 2015 17:59
As a teaching/learning aid, here is a simple bit of code to cycle through the LEDs / Outputs on a Raspberry Pi with Piface attachment board.
import piface.pfio
import time
import sys
def main(argv):
piface.pfio.init()
cnt = 0
loop = 0
@mapkyca
mapkyca / .htaccess
Created April 24, 2013 07:58
Enable xdebug profiling in a .htaccess file
#Turn on XDebug profiling in .htaccess
php_value xdebug.profiler_enable On
php_value xdebug.profiler_output_dir "/tmp"
php_value xdebug.profiler_output_name "%H.%R.%u.cachegrind.out"
@mapkyca
mapkyca / gist:5276270
Created March 30, 2013 10:41
Weather Display clientele.txt data format
1	Wind: Speed - Average - Current	(Knots)
2	Wind: Speed - Current	(Knots)
3	Wind: Dir - Current		(Compass heading)
4	Temp: Outside - Current	(Celsius)
5	Humidity: Outside - Current	(Percent)
6	Baro: Current	(hPa)
7	Rain: Today - Current total	(Millimeters)
8	Rain: Total for Month	(Millimeters)
9	Rain: Total for Season	(Millimeters)
10	Rain: Rain Rate - Current	(Millimeters)