Skip to content

Instantly share code, notes, and snippets.

View athoune's full-sized avatar

Mathieu Lecarme athoune

View GitHub Profile
#!/usr/bin/env python2
from __future__ import print_function
from dns import resolver
from StringIO import StringIO
import sys
buff = StringIO()
answers = resolver.query(sys.argv[1], 'TXT')
import os
def pam_sm_open_session(pamh, flags, args):
try:
user = pamh.get_user(None)
except pamh.exception, e:
return e.pam_result
with open('/tmp/debug', 'w') as d:
d.write(user)
@athoune
athoune / pregexp.rb
Created December 9, 2015 22:10
Prefix index for massive regexp parsing, like Piwik does
require "set"
require 'regexp_parser'
require 'commons-collections4-4.1.jar'
module PreRegexp
def self.tokenize sentence
sentence.split(/[\s;()|]+/).sort.reverse
end
@athoune
athoune / thrift-gunicorn.py
Last active March 4, 2016 00:25
Hacking thrift with gunicorn
#!/usr/bin/env python
import sys
sys.path.append('gen-py')
from gunicorn.app.base import Application
from gunicorn.workers.sync import SyncWorker
from gunicorn.arbiter import Arbiter
from thrift.transport.TSocket import TSocket
def bucketize(items):
# Bucketsize = 1 minute
bucket = []
ts = None
for item in items:
if item is None:
continue
dt = (item['datetime'].day,
item['datetime'].hour,
item['datetime'].minute)
import asyncio
class Boniface:
"""
Like Boniface Malcoeur, the necromancer
"""
def __init__(self, redis):
self._redis = redis
@athoune
athoune / msgpack-rpc.py
Created September 21, 2015 21:41
Server
import asyncio
from msgpack import Unpacker, packb
class App(dict):
def make_handler(self):
return MsgpackProtocol(self)
@athoune
athoune / celery_concurrency.py
Created September 16, 2015 15:51
Playing with celery concurrency
#!/usr/bin/env python
# encoding: utf-8
from time import sleep
import os
from billiard import freeze_support
freeze_support()
from celery.concurrency import prefork
from celery.concurrency.prefork import TaskPool
@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")),
@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"]):