Skip to content

Instantly share code, notes, and snippets.

@an01f01
an01f01 / tornado_launch.py
Last active December 20, 2020 16:52
Creating and launching a tornado server
def main():
app = make_app()
return app
app = main()
if __name__ == '__main__':
print("starting tornado server..........")
app.listen(tornado.options.options.port)
tornado.ioloop.IOLoop.current().start()
@an01f01
an01f01 / requirements.txt
Created December 20, 2020 16:56
Tornado basic requirements
tornado==6.1.0
fun isOnline(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val n = cm.activeNetwork
if (n != null) {
val nc = cm.getNetworkCapabilities(n)
//It will check for both wifi and cellular network
return nc!!.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || nc.hasTransport(
NetworkCapabilities.TRANSPORT_WIFI)
import os
import json
import datetime
import psycopg2
import psycopg2.extras
from psycopg2.extras import Json
import tornado.httpserver
import tornado.options
import tornado.ioloop
import tornado.web
# Define web app
# (The only routes that contain "." should be static files, the "." is neccessary for the extension
# dont make new, non-static routes containing "." or else the static file handler will attempt to handle the request)
application = tornado.web.Application([
(r"/", StatusHandler),
], **settings)
application.listen(80)
http_server = tornado.httpserver.HTTPServer(
application,
"""
Overriding the prepare method of the RequestHandler to redirect based on protocol
"""
def prepare(self):
if self.request.protocol == 'http':
self.redirect('https://' + self.request.host, permanent=False)
@an01f01
an01f01 / asyncio.py
Last active October 1, 2021 16:04
tornado/platform/asyncio.py
import concurrent.futures
import functools
from threading import get_ident
from tornado.gen import convert_yielded
from tornado.ioloop import IOLoop, _Selectable
import asyncio
class CTreeCtrlX : public CTreeCtrl
{
protected:
HTREEITEM m_hItemFirstSel; // Init to NULL in constructor
DWORD m_dwDragStart;
void ClearSelection();
BOOL SelectItems(HTREEITEM hItemFrom, HTREEITEM hItemTo);
HTREEITEM GetFirstSelectedItem();
#include "mfc_multi_select_ctree_ctr.h"
BEGIN_MESSAGE_MAP(CTreeCtrlX, CTreeCtrl)
ON_WM_LBUTTONDOWN()
ON_WM_KEYDOWN()
END_MESSAGE_MAP()
void CTreeCtrlX::OnLButtonDown(UINT nFlags, CPoint point)
{
// Set focus to control if key strokes are needed.
@an01f01
an01f01 / bamboo_shell_script.sh
Created April 27, 2022 19:42
Bamboo shell script for deployment
rm -rf "${bamboo.local_repo_name}"
echo "Deleted existing ${bamboo.local_repo_name}"
echo "Pulling git.collab repo"
git clone https://${bamboo.collab_usr}:${bamboo.collab_tap}@git.mycompany.com/scm/myproject/azure-server.git
echo "Moving into local repo"
cd "${bamboo.local_repo_name}"
echo "Switching to Azure local git"