Skip to content

Instantly share code, notes, and snippets.

@afreerunner
afreerunner / qapplication_about_to_quit_signal.py
Created May 23, 2021 14:11 — forked from metalman/qapplication_about_to_quit_signal.py
QThread graceful exit before QApplication quit.
'''
see: http://pyqt.sourceforge.net/Docs/PyQt4/qcoreapplication.html#aboutToQuit
'''
import threading
from PyQt4 import QtCore, QtGui
class Thread(QtCore.QThread):
# http://stackoverflow.com/questions/19542333/websocket-server-sending-messages-periodically-in-python
import tornado.httpserver
import tornado.websocket
import tornado.ioloop
from tornado.ioloop import PeriodicCallback
import tornado.web
class WSHandler(tornado.websocket.WebSocketHandler):
def open(self):
import asyncio
import json
import logging
import websockets
import aioredis
logging.basicConfig(level=logging.INFO)
# STATE = {'value': 0}
USERS = set()
@afreerunner
afreerunner / consumer1.py
Created March 4, 2021 11:58 — forked from 17307/consumer1.py
redis stream consumer #redis
import redis
import time
pool = redis.ConnectionPool(host='192.168.137.3', port=6379, password='', decode_responses=True)
r = redis.Redis(connection_pool=pool)
STREAM_NAME = "consumer"
GROUP_NAME = "g1"
CONSUMER_NAME = "c1"
"""
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@afreerunner
afreerunner / Dockerfile
Created October 10, 2019 01:33 — forked from PurpleBooth/Dockerfile
Create a static binary in go and put it in a from scratch docker container
FROM golang:1.9
WORKDIR /go/src/github.com/purplebooth/example
COPY . .
RUN go build -ldflags "-linkmode external -extldflags -static" -a main.go
FROM scratch
COPY --from=0 /go/src/github.com/purplebooth/example/main /main
CMD ["/main"]
@afreerunner
afreerunner / main.cpp
Created January 9, 2019 02:20 — forked from micjabbour/main.cpp
QSettings sqlite format
#include <QtWidgets>
#include <QtSql>
//to ensure the database connection is closed and removed at the end
//of the write/read func call
class SQLConnectionRAIIWrapper{
public:
SQLConnectionRAIIWrapper(QString fileName){
//use a unique connection name, to ensure thread safety
connectionName = QString("SQLSETTINGS%1").arg((int)QThread::currentThreadId());
import asyncio
loop = asyncio.get_event_loop()
async def hello():
await asyncio.sleep(3)
print('Hello!')
if __name__ == '__main__':
loop.run_until_complete(hello())
@afreerunner
afreerunner / mosquitto.conf
Created August 24, 2017 08:25
MQTT Broker mosquitto config files
# Config file for mosquitto
#
# See mosquitto.conf(5) for more information.
#
# Default values are shown, uncomment to change.
#
# Use the # character to indicate a comment, but only if it is the
# very first character on the line.
# =================================================================
@afreerunner
afreerunner / app.py
Created August 13, 2017 11:46 — forked from miku/app.py
Minimal flask + eventlet example.
#!/usr/bin/env python
# http://stackoverflow.com/questions/14180179/eventlet-spawn-doesnt-work-as-expected/14180227#14180227
from flask import Flask
import time
import eventlet
eventlet.monkey_patch()
app = Flask(__name__)