Skip to content

Instantly share code, notes, and snippets.

View adiroiban's full-sized avatar

Adi Roiban adiroiban

View GitHub Profile
@adiroiban
adiroiban / test.py
Created April 8, 2015 15:39
Unicode os.stat
-> os.stat(path)
(Pdb) path
u'/tmp/4b385cfb-f96c-4eca-81c9-70d1223353d6-cp\u021b/3741-cp\u021baaaaaaaaaaaaaaaaaaaaaaaa'
(Pdb) os.stat(path)
*** UnicodeEncodeError: 'ascii' codec can't encode character u'\u021b' in position 44: ordinal not in range(128)
(Pdb) os.stat(path.encode('utf-8'))
*** OSError: [Errno 2] No such file or directory: '/tmp/4b385cfb-f96c-4eca-81c9-70d1223353d6-cp\xc8\x9b/3741-cp\xc8\x9baaaaaaaaaaaaaaaaaaaaaaaa'
(Pdb) os.environ.get('LANG')
'C'
(Pdb) os.stat(path)
@adiroiban
adiroiban / ssl_country_codes.js
Created April 9, 2015 18:20
SSL country codes and country names mapping
var countries = [
{'name': 'Afghanistan', 'code': 'AF'},
{'name': 'Albania', 'code': 'AL'},
{'name': 'Algeria', 'code': 'DZ'},
{'name': 'American Samoa', 'code': 'AS'},
{'name': 'Andorra', 'code': 'AD'},
{'name': 'Angola', 'code': 'AO'},
{'name': 'Anguilla', 'code': 'AI'},
{'name': 'Antarctica', 'code': 'AQ'},
{'name': 'Antigua and Barbuda', 'code': 'AG'},
def test_resumeFromResumeOffset(self):
"""
If given a resumeOffset argument, L{DccFileReceive} will attempt to
resume from that number of bytes if the file exists.
"""
fp = FilePath(self.mktemp())
fp.setContent("Twisted is awesome!")
protocol = self.makeConnectedDccFileReceive(fp.path, resumeOffset=11)
self.allDataReceivedForProtocol(protocol, "amazing!")

Simple Twisted H2 Client

This gist contains a really stupid implementation of a Twisted HTTP/2 client. It opens a connection, uses ALPN/NPN to negotiate HTTP/2, and then sends a single HTTP/2 GET request to the /ip endpoint.

To execute this:

  1. Create a clean virtual environment.
  2. Install the requirements: pip install -r requirements.txt.
  3. Install the development version of Twisted that contains the nextProtocols code.
  4. Execute the code using python h2test.py.
@adiroiban
adiroiban / tls_protocol_negociation_twisted.py
Created June 8, 2015 09:15
code to help testing NPN support in Twisted
from OpenSSL import SSL
from twisted.internet import ssl, protocol, defer, endpoints, reactor, task
def main(reactor):
options = ssl.optionsForClientTLS(
hostname=u'http2bin.org',
extraCertificateOptions={'nextProtocols': [b'h2', b'http/1.1']}
)
Jun 28 22:05:48 vremea weewx[3245]: engine: Caught unrecoverable exception in engine:
Jun 28 22:05:48 vremea weewx[3245]: **** /lib/arm-linux-gnueabihf/libusb-1.0.so.0: undefined symbol: libusb_strerror
Jun 28 22:05:48 vremea weewx[3245]: **** Traceback (most recent call last):
Jun 28 22:05:48 vremea weewx[3245]: **** File "/home/weewx/bin/weewx/engine.py", line 836, in main
Jun 28 22:05:48 vremea weewx[3245]: **** engine.run()
Jun 28 22:05:48 vremea weewx[3245]: **** File "/home/weewx/bin/weewx/engine.py", line 187, in run
Jun 28 22:05:48 vremea weewx[3245]: **** for packet in self.console.genLoopPackets():
Jun 28 22:05:48 vremea weewx[3245]: **** File "/home/weewx/bin/weewx/drivers/fousb.py", line 1091, in genLoopPackets
Jun 28 22:05:48 vremea weewx[3245]: **** for p in self.get_observations():
Jun 28 22:05:48 vremea weewx[3245]: **** File "/home/weewx/bin/weewx/drivers/fousb.py", line 1156, in get_observations
@adiroiban
adiroiban / txsyslogd.py
Last active September 10, 2015 12:51 — forked from gleicon/txsyslogd.py
minimalistic syslog daemon written with twisted.
#!/usr/bin/python
#
# Simple syslog collector used for testing.
#
from twisted.internet import address, reactor, stdio, defer
from twisted.internet.protocol import DatagramProtocol, Protocol, Factory
from twisted.protocols.basic import LineReceiver
import time, re, math, json
#<22>Nov 1 00:12:04 gleicon-vm1 postfix/smtpd[4880]: connect from localhost[127.0.0.1]
@adiroiban
adiroiban / Depth first non blocking traversal
Last active October 28, 2015 18:48
Depth first non blocking traversal - use task.deferLater to allow other callbacks to execute
Errors for running the recursive version
['37']
['36']
^CUnhandled error in Deferred:
Traceback (most recent call last):
File "/home/adi/chevah/twisted/twisted/internet/defer.py", line 1184, in gotResult
_inlineCallbacks(r, g, deferred)
@adiroiban
adiroiban / report.rst
Last active November 2, 2015 16:21
Twisted Fellowship 2015 - October Report

October 2015 - TSF Sponsored Development

This is my first post from a series of post dedicated to my work as part of the 2015-2016 Twisted Maintainer Fellowship program.

The Twisted project via Software Freedom Conservancy were kind enought to contract me as a consultant to help with the review queue and the Git migration.

I am sharing this Twisted Maintainer Fellowship program with Amber aka Hawkie aka hawkowl.

Below is the report for October 2015.

@adiroiban
adiroiban / Glyph's IRC feedback
Last active November 29, 2015 16:04
Twisted SVN to Git migration - Work Plan
11 Nov
(23:40:19) glyph: adiroiban: hey, so, regarding the git migration. You sent a proposal to the TSF but then you mentioned hawkowl had another proposal. I said to discuss amongst yourselves and submit a single proposal so I can organize an approval vote. Then you asked if there was any news :)
(23:40:40) glyph: adiroiban: The news is "please submit a final proposal for approval when you are done deciding which it is" :)
(23:40:48) adiroiban: ok
(23:41:08) glyph: adiroiban: I can guarantee the PLC is going to do exactly _zero_ work in helping you figure out what to do; it is hard enough for me to get them all to answer their email for a vote :)
(23:41:31) glyph: keturn: maybe you should feel a little bad about that, but since you are the _second_ most responsive member (and the _only_ one actually here) maybe don't feel too bad
(23:42:04) adiroiban: glyph: ok. no problem
(23:42:17) adiroiban: will get in touch with Amber
(23:42:43) adiroiban: I am not aware of receiving an email in which I am asked to