Skip to content

Instantly share code, notes, and snippets.

View adiroiban's full-sized avatar
🇺🇦
Slava Ukraini!

Adi Roiban adiroiban

🇺🇦
Slava Ukraini!
  • VGR, La Gomera
  • 18:03 (UTC +01:00)
View GitHub Profile
@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 / gist:ae6b6d738173a30f77b1
Created November 7, 2015 10:50
Twisted py2.7 errors
===============================================================================
[FAIL]
Traceback (most recent call last):
File "/home/adi/chevah/twisted/twisted/internet/test/test_unix.py", line 449, in test_avoidLeakingFileDescriptors
expectedEvent, pformat(events,)))
twisted.trial.unittest.FailTest: Expected event ({'protocolName': 'ConnectableProtocol', 'format': '%(protocolName)s (on %(hostAddress)r) does not provide IFileDescriptorReceiver; closing file descriptor received (from %(peerAddress)r).', 'hostAddress': UNIXAddress(None), 'peerAddress': UNIXAddress('./tmpAMIQ3S.sock')}) not found in logged events ([{'format': '%(log_legacy)s',
'isError': 0,
'log_format': u'{log_text}',
'log_legacy': <twisted.logger._stdlib.StringifiableFromEvent object at 0x7fb94404eb50>,
'log_level': <LogLevel=info>,

Computer Science Courses that Don't Exist, But Should

CSCI 2100: Unlearning Object-Oriented Programming

Discover how to create and use variables that aren't inside of an object hierarchy. Learn about "functions," which are like methods but more generally useful. Prerequisite: Any course that used the term "abstract base class."