Skip to content

Instantly share code, notes, and snippets.

@rectalogic
rectalogic / now.py
Last active September 8, 2016 19:18
>>> import datetime
>>> import yaml
>>> def now_constructor(loader, node):
... now = datetime.datetime.utcnow()
... # Value is an optional offset in seconds
... value = loader.construct_scalar(node)
... return now + datetime.timedelta(seconds=int(value)) if value else now
...
>>> yaml.add_constructor(u'!now', now_constructor, Loader=yaml.SafeLoader)
>>> print yaml.safe_load("""{"state": "importing", "time_imported": {"$lte": !now -3600}}""")
@rectalogic
rectalogic / Dockerfile
Last active August 2, 2016 13:22
RabbitMQ exchange federation test with two brokers.
# Configure two rabbitmq nodes and federate all exchanges between them.
# $ docker build -t rectalogic/rabbitmq:latest .
# $ docker network create -d bridge rabbit-net
# $ docker run -d --hostname rabbit1 --name rabbit1 --network=rabbit-net -p=56721:5672 rectalogic/rabbitmq:latest
# $ docker run -d --hostname rabbit2 --name rabbit2 --network=rabbit-net -p=56722:5672 rectalogic/rabbitmq:latest
@rectalogic
rectalogic / ipsec2wireshark.py
Last active June 3, 2021 05:12
Parse spis and keys from "ip xfrm state" output and generate a Wireshark ESP decryption config that can decrypt an ESP capture.
#!/usr/bin/env python
"""
Runs "ip xfrm state" and outputs lines to be added to ~/.wireshark/esp_sa
This process must be run using sudo.
This allows Wireshark to decrypt ipsec traffic captured with 'sudo tcpdump -vni any -U -w /tmp/esp.pcap "ip proto 50"'
"""
import sys
import subprocess
@rectalogic
rectalogic / nscurl.log
Created July 9, 2016 21:09
nscurl output for api.pinboard.in
$ /usr/bin/nscurl --verbose --ats-diagnostics https://api.pinboard.in/v1/
Starting ATS Diagnostics
Configuring ATS Info.plist keys and displaying the result of HTTPS loads to https://api.pinboard.in/v1/.
A test will "PASS" if URLSession:task:didCompleteWithError: returns a nil error.
================================================================================
Default ATS Secure Connection
---
ATS Default Connection
@rectalogic
rectalogic / README.md
Last active July 9, 2016 16:50
Convert Feedly "Saved For Later" to Netscape bookmarks format for import into pinboard.in

First, go to https://feedly.com/i/saved in Chrome and scroll down until all items have loaded. Then open Chrome Dev Tools and navigate to the //*[@id="section0_column0"] nested div. Right click and Copy > Copy element. Paste this into a file feedly-saved.html Run feedly_to_pinboard.py to generate feedly-bookmarks.html - import this into Pinboard.

class QueryDebugger(object):
def __init__(self, engine, query):
with engine.connect() as connection:
try:
sqlalchemy.event.listen(engine, "do_execute", self.receive_do_execute)
connection.execute(query)
finally:
sqlalchemy.event.remove(engine, "do_execute", self.receive_do_execute)
def receive_do_execute(self, cursor, statement, parameters, context):
<?xml version='1.0' encoding='UTF-8'?>
<mlt>
<producer id='background'>
<property name='mlt_type'>producer</property>
<property name='mlt_service'>colour</property>
<property name='colour'>0x000000ff</property>
</producer>
<producer id='producer-red-4x3.mov-0'>
<property name='mlt_type'>producer</property>
<property name='resource'>media/red-4x3.mov.r0.lossless.mov</property>
class MetadataValue:
field1 = Field(order=1)
field2 = Field(order=3)
@rectalogic
rectalogic / mongo_index
Last active April 1, 2016 20:25
regex prefix on unique and nonunique indices
cureatr:PRIMARY> use test
cureatr:PRIMARY> db.foo.createIndex({prefix: 1, unique: 1}, {unique: true})
cureatr:PRIMARY> db.foo.createIndex({prefix : 1, nonunique: 1})
cureatr:PRIMARY> db.foo.explain().find({prefix: "a", nonunique: /^a/i})
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "test.foo",
"indexFilterSet" : false,

sh-session hiliting

user@vpn$ dd if=/dev/random count=32 bs=1 2>/dev/null | base64
N/5y0EkgCFevc9uvJv1GsMG14BwbknCERoyJKZatoh0=
user@vpn$ dd if=/dev/random count=32 bs=1 2>/dev/null | base64
eb3W4WYXuHsnc0KVzg65G3XFQUD/I69/pYqFCYb5+iQ=

console hiliting