This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
""" | |
requirements: | |
paho-mqtt==1.2 | |
""" | |
import hashlib | |
import hmac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
mysql: | |
image: mysql:5 | |
environment: | |
MYSQL_ROOT_PASSWORD: 'root' | |
volumes: | |
- /data/volumes/mysql:/var/lib/mysql | |
server: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Common JSON error response for RESTful APIs. | |
Usage: | |
1. define your own _ERROR_CODES | |
2. import and render errors | |
from errorcodes import render_errors | |
# some where you want to render errors | |
render_errors('BODY_JSON_INVALID', detail='detail error message') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import socket | |
import requests | |
SERVER = '' | |
ZONE = '' | |
def public_ip(): | |
try: | |
resp = requests.get('http://httpbin.org/ip') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import gevent | |
# import gevent.socket as socket | |
# import gevent.ssl as ssl | |
# from gevent import spawn | |
import socket | |
import ssl | |
import pprint | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tornado.tcpserver import TCPServer | |
from tornado.ioloop import IOLoop | |
from uuid import uuid4 | |
class EchoConnection(object): | |
def __init__(self, stream, address): | |
self.address = address | |
self.stream = stream |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ssl | |
from tornado.httpserver import HTTPServer | |
from tornado.web import Application, RequestHandler | |
from tornado.ioloop import IOLoop | |
class TestHandler(RequestHandler): | |
def get(self): | |
self.write("Hello, World!\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado | |
from tornado.websocket import websocket_connect | |
class WSClient(object): | |
def __init__(self, url): | |
self.url = url | |
self.ioloop = tornado.ioloop.IOLoop.current() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado | |
import tornado.websocket | |
class EchoWebSocket(tornado.websocket.WebSocketHandler): | |
def open(self): | |
print("WebSocket opened") | |
def on_message(self, message): | |
print message |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define a grammar called Hello | |
grammar Hello; | |
r : 'hello' ID ; // match keyword hello followed by an identifier | |
ID : [a-z]+ ; // match lower-case identifiers | |
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines |