Skip to content

Instantly share code, notes, and snippets.

from formencode import Schema, ForEach
from formencode.validators import Email, UnicodeString, RequireIfMissing
class TestSchema(Schema):
recipients = ForEach(Email(not_empty=True), convert_to_list=True)
service = UnicodeString(not_empty=False, if_missing=None)
chained_validators = [RequireIfMissing('service', missing='recipients')]
print TestSchema.to_python({})
@rectalogic
rectalogic / ClothMesh.cs
Created September 14, 2016 13:44
Unity3D 5.x component to generate a mesh and control a vertex on the new Cloth component
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[RequireComponent(typeof(SkinnedMeshRenderer), typeof(Cloth))]
public class ClothMesh : MonoBehaviour {
public float width = 5;
public float height = 5;
public int xSize = 20;
public int ySize = 20;
@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)