Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

ax003d

🏠
Working from home
View GitHub Profile
View ali_iot.py
#!/usr/bin/python3
"""
requirements:
paho-mqtt==1.2
"""
import hashlib
import hmac
View docker-compose.yml.zabbix
version: '2'
services:
mysql:
image: mysql:5
environment:
MYSQL_ROOT_PASSWORD: 'root'
volumes:
- /data/volumes/mysql:/var/lib/mysql
server:
View errorcodes.py
"""
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')
View ddns_client
import os
import socket
import requests
SERVER = ''
ZONE = ''
def public_ip():
try:
resp = requests.get('http://httpbin.org/ip')
@ax003d
ax003d / ssl_client.py
Last active Aug 29, 2015 — forked from DanielleSucher/ssl_client.py
gevent (py3) test ssl server and client
View ssl_client.py
# 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)
@ax003d
ax003d / echo_server.py
Created Aug 13, 2015
tornado echo server
View echo_server.py
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
@ax003d
ax003d / https_server.py
Created Aug 12, 2015
tornado https server
View https_server.py
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")
@ax003d
ax003d / websocket_client.py
Created Aug 10, 2015
tornado websocket client
View websocket_client.py
import tornado
from tornado.websocket import websocket_connect
class WSClient(object):
def __init__(self, url):
self.url = url
self.ioloop = tornado.ioloop.IOLoop.current()
@ax003d
ax003d / websocket_server.py
Created Aug 10, 2015
tornado websocket server
View websocket_server.py
import tornado
import tornado.websocket
class EchoWebSocket(tornado.websocket.WebSocketHandler):
def open(self):
print("WebSocket opened")
def on_message(self, message):
print message
@ax003d
ax003d / hello.g4
Created Oct 27, 2013
sample codes
View hello.g4
// 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