Skip to content

Instantly share code, notes, and snippets.

@vfaronov
vfaronov / mitmproxy-quicker.py
Created December 22, 2018 17:23
mitmproxy scripting cheat sheet / snippets collection
# Copy this file and run mitmproxy like this::
#
# mitmproxy -s mitmproxy-quicker.py --mode reverse:http://dummy.invalid
#
# Then edit the code below. For example,
# http://localhost:8080/index.html will serve the HTML page defined below.
# mitmproxy will automatically reload the script whenever you save it to disk.
# You can specify a real fallback upstream instead of ``dummy.invalid``,
# or remove the ``--mode`` option altogether for a regular (forward) proxy.
#
@vfaronov
vfaronov / forwarded_parser.py
Last active August 5, 2017 20:07
Experimental RFC 7239 parser
import re
import types
_HTTP_QUOTED_STRING = r'"(?:[^\\"]|\\.)*"'
_HTTP_TOKEN = r"[!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+"
_PAIR = '{token}=(?:{token}|{quoted_string})'.format(
token=_HTTP_TOKEN, quoted_string=_HTTP_QUOTED_STRING)
_LEXER_RE = re.compile('{pair}|.'.format(pair=_PAIR))
#!/usr/bin/env bash
socket_prefix=/tmp/geany-$USER
socket=$socket_prefix-$RANDOM
desktop=$( xdotool get_desktop )
pid=$( xdotool search --desktop "$desktop" --class Geany getwindowpid )
if [[ $pid ]]; then
candidate=$( ps -p $pid -o args= | grep -Eo "$socket_prefix-[0-9]+" )
if [[ -e $candidate ]]; then
socket=$candidate
#!/usr/bin/env bash
die()
{
echo "notdot: $1" >&2
exit 1
}
do_add()
@vfaronov
vfaronov / webkitgtk_form.py
Created January 13, 2017 11:21
Problem when handling form submission with WebKitGTK+ 2.14
# To run: install (Ubuntu package names)
# ``python3-gi``, ``gir1.2-gtk-3.0``, ``gir1.2-webkit2-4.0``,
# then do ``python3 webkitgtk_form.py``
import ctypes
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk, WebKit2

Hello world

This document contains interesting stuff.

Section 1

Paragraph 1

Hello world

This document contains interesting stuff.

Section 1

Paragraph 1

$ curl -G --head httpbin.org/response-headers \
> --data-urlencode 'ETag=W/"foo-bar"'
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 30 Jan 2016 14:08:45 GMT
Content-Type: application/json
Content-Length: 96
Connection: keep-alive
ETag: W/"foo-bar"
Access-Control-Allow-Origin: *
(fset 'vf-orig-kill-region (symbol-function 'kill-region))
(defadvice kill-word (before vf-before-kill-word ())
(fset 'kill-region (symbol-function 'delete-region)))
(defadvice kill-word (after vf-after-kill-word ())
(fset 'kill-region (symbol-function 'vf-orig-kill-region)))
(ad-activate 'kill-word)
(defadvice backward-kill-word (before vf-before-backward-kill-word ())
(fset 'kill-region (symbol-function 'delete-region)))
import BaseHTTPServer
import turq
turq.TurqHandler.install_code('''
with path() as r:
r.text('blah blah')
''')
BaseHTTPServer.HTTPServer(('0.0.0.0', 13085), turq.TurqHandler).serve_forever()