Skip to content

Instantly share code, notes, and snippets.

View introom's full-sized avatar

introom

View GitHub Profile
#!/usr/bin/env python2.7
import parsley
import ometa.runtime as runtime
SIPGrammar = """
msg = firstline headers crlf body
firstline = ('\r' | '\n')* nospace:a ' ' nospace:b ' ' remaining:c
-> parser.doFirstLine(a, b, c)
class NoCSRFLoginView(View):
def get(self, request):
return HttpResponse("Please post your info.")
@never_cache
def post(self, request, authentication_form=AuthenticationForm):
form = authentication_form(data=request.POST)
if form.is_valid():
# Okay, security check complete. Log the user in.
@introom
introom / rdiff-backup memo
Created June 6, 2013 15:04
some settings for rdiff-backup
useradd -d /dir_for_backup -m databackup
su - databackup
ssh-keygen -t rsa
content:
host A_Backup
hostname Server_A_Address
user root
Last login: Thu Jun 20 18:27:30 on ttys000
➜ ~ kz
zsh: command not found: kz
➜ ~ ls
Applications Desktop GradProj Movies Pictures README.md Transient
Audiu Documents ImpBack Music Projects Temp Twisted
Books Downloads Library Persistent Public Tools
➜ ~
@introom
introom / gist:5830674
Created June 21, 2013 11:41
parsley reference problem
# this one works, I can repeat the expr in query {times}
byte = anything:b -> ord(b)
query = byte:times expr{times}
# however, if the byte CANNOT return ord(b), how can I refer to the value of 'ord(anything:b)' when I am in query?
# one workaround is to store it in a temporary place.
# for example
byte = anything:b -> temp.update(b)
query = byte expr{temp.b}
@introom
introom / parsley dns
Created June 21, 2013 15:27
DNS Parse Structure
class Message:
pass
class Query:
pass
class Name:
pass
@introom
introom / parsley obj.attr obj[index]
Created June 22, 2013 06:01
parsley obj.attr obj[index]
from parsley import makeGrammar
data = b'\x01\x013'
grammarSource = r"""
byte = anything:b1 anything:b2 -> ord(b1), ord(b2)
start = byte:b anything{b[0]}
"""
parser = makeGrammar(grammarSource, {})
@introom
introom / grammar.py
Created June 23, 2013 00:52
payload
"""
byte, short and other C types are serialized in network/big endian
"""
grammarSource = r"""
byte = anything:b -> ord(b)
short = byte:high byte:low -> high << 8 | low
int = short:high short:low -> high << 16 | low
https://gist.github.com/anonymous/5864002#comment-851824
comment = '#' (~'\n' anything)*
hspace = ' ' | '\t' | comment
vspace = '\r\n' | '\r' | '\n'
ws = (hspace | vspace | comment)*
emptyline = hspace* vspace
indentation = emptyline* hspace+
noindentation = emptyline* ~~~hspace
number = ws