Skip to content

Instantly share code, notes, and snippets.

View athoune's full-sized avatar

Mathieu Lecarme athoune

View GitHub Profile
#!/usr/bin/env python
# encoding: utf-8
import argparse
import os
import sys
from jinja2 import Template
parser = argparse.ArgumentParser(description='µ template')
import socket
import struct
def ip_to_long(ip):
return struct.unpack('!L', socket.inet_aton(ip))[0]
def subnet_match(ip, subnet):
lsubnet = ip_to_long(subnet)
return lsubnet == (ip_to_long(ip) & lsubnet)
@athoune
athoune / Dockerfile
Last active August 29, 2015 14:12
Building wp-cli
FROM debian:wheezy
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get -y install ca-certificates wget fakeroot
WORKDIR /tmp
ADD https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-cli-updatedeb.sh /tmp/
RUN /bin/bash wp-cli-updatedeb.sh
@athoune
athoune / gist:cab5efe261dc05c8186e
Created February 19, 2015 23:21
rm exited dockers
docker rm `docker ps -f status=exited -q`
@athoune
athoune / gist:0088f0ea3356d13c42ef
Created February 21, 2015 21:05
Casper web screenshot
var casper = require("casper").create({
verbose: true,
logLeval: "debug",
timeout: 5000,
onTimeout: function() {
casper.echo("oups Timeout", arguments);
}
});
var args = casper.cli.args;
@athoune
athoune / gist:a39ae465c86d92e3e01b
Created February 24, 2015 09:45
Reading wp options from sql dump
#!/usr/bin/env python
import sqlparse
from sqlparse.sql import Comment, Identifier, Parenthesis
from phpserialize import loads, phpobject
f = open('dump-no-contents.sql', 'r')
for line in sqlparse.split(f):
p = sqlparse.parse(line)[0]
if type(p.tokens[0]) == Comment:
@athoune
athoune / gist:0bdb2fcfad82a57cd22a
Created March 10, 2015 21:32
Reading auditd events while testing apparmor
#!/usr/bin/env python
import socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect('/var/run/audispd_events')
def read(s):
@athoune
athoune / helloworld.py
Last active August 29, 2015 14:19
Chronology monkeypatching for nameko
import timeit
import json
import eventlet
from nameko.rpc import Rpc, RpcProxy
q = eventlet.Queue()
def read_events(q):
with open('timing.log', 'w') as l:
@athoune
athoune / header.py
Created April 30, 2015 15:16
Find plugins in a Wordpress folder
#!/usr/bin/env python
import re
import glob
import os.path
GARBAGE = re.compile("^(\s|[*#])+")
def headers(lines, keys=["Plugin Name", "Plugin URI", "Version", "Author",
"License", "Author URI", "Description", "Network"]):
@athoune
athoune / gist:635b01795cb8e399fa9c
Created May 18, 2015 10:09
Bootstraping Grafana 2
import requests
import json
s = requests.Session()
r = s.get('http://localhost:3000/login')
print r
r = s.post('http://localhost:3000/login',
data=json.dumps(dict(user="admin", email="", password="admin")),