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 / python_regex.py
Created July 26, 2015 10:46
Quick python regex callback example, for my memory
import re
def callback(match):
return "<a href=\"http://github.com/%s>%s</a>" % (match.group(0), match.group(0))
string = "this is a #test #32345 dfsdf"
print re.sub('#[0-9]+', callback, string)
@mapkyca
mapkyca / gist:2420796
Created April 19, 2012 12:52
Quickly remove non-alpha chars from a string
// Quick regexp to remove non-alpha chars from a string. Very handy
$string = preg_replace("/[^a-zA-Z0-9\s]/", "", $string);

Keybase proof

I hereby claim:

  • I am mapkyca on github.
  • I am mapkyca (https://keybase.io/mapkyca) on keybase.
  • I have a public key ASCIDBawC_Ho4zeR5v42rPJrp_ZfMg9Q-lCpE8-InQBScwo

To claim this, I am signing this object:

@mapkyca
mapkyca / gist:7938ee8b19b25d539e41
Created March 26, 2016 13:31
Import a public key from a url
curl -L https://example.com/key.pgp | gpg --import
@mapkyca
mapkyca / gist:dc07d66772cdd5a3b6d0
Created February 5, 2016 12:01
Get a list of unique downloads from an awstats download list
curl http://localhost/~marcus/awstats/domain/month/awstats.localhost.downloads.html | grep 'http://your.domain/you/are/interested/in' | sed -ne 's/.*\(http[^"]*\).*/\1/p' >> /tmp/files.csv
cat /tmp/files.csv | sort | uniq > /tmp/sorted.csv
@mapkyca
mapkyca / gist:264a3877d13dee6ff9ce
Created February 4, 2016 09:36
Find dead links
wget --spider -o wget.log -e robots=off -w 1 -r -p URL
@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 """