Skip to content

Instantly share code, notes, and snippets.

var socket;
if (window.location.protocol !== 'https:') {
socket = io.connect('http://' + document.domain + ':' + location.port + '/stream');
}
else {
socket = io.connect('https://' + document.domain + ':' + location.port + '/stream');
}
initSocketIO = function() {
$("input[data-table-id]").change(emitChange);
@socketio.on("user presence", namespace = '/stream')
def first_event(message):
the_date = message['data']['the_date']
name = "%s %s" % (current_user.first_name, current_user.last_name)
print "Connected 01 %s" % name
emit('broadcast user', {'data': {'user':name, 'date':the_date }}, broadcast = True)
@socketio.on("disconnect", namespace='/stream')
def user_left():
print ("Disconnect detected - Recalling all users")
@cisko3000
cisko3000 / crypto_exchange_notify.py
Created June 18, 2018 04:48
Notifies system users of new crypto prices.
@app.route('/notify-all', methods=['POST'])
def notify_all():
if request.form.get('admin_key') == app.config['NOTIFY_KEY'] or current_user.has_role('admin'):
# https://api.gemini.com/v1/pubticker/ethusd
# {
# "ask": "977.59",
# "bid": "977.35",
# "last": "977.65",
# "volume": {
# "BTC": "2210.505328803",
'''
This code uses bar plots to compare the percentages of women (ShareWomen) from the 10 first and last rows of a sorted dataframe.
'''
import pandas as pd
import matplotlib as plt
%matplotlib inline
@cisko3000
cisko3000 / test_api.py
Created June 18, 2018 04:29
Unit testing for containers API
# This file is part of a larger set of unit testing scripts that ensures an API works properly. The API that this file tests is mod_api uploaded here on my github account as a gist named __init__.py
# tests/test_api.py
import unittest
from tests.base import BaseTestCase
from app.models import db, User, Account, Location, Department, Room, Bracket, \
ContainerType, Unit, ScanSet, Container
from flask_security import current_user
@cisko3000
cisko3000 / __init__.py
Created June 18, 2018 04:27
mod_api module for containers system
'''
This is the __init__.py file of an API module for a system built using the Flask micro framework and the extension Flask-RESTful.
This file is only a small piece of a larger system and is only here partially to showcase coding ability and style.
There is another file here on my github account that implements unit testing for this API.
'''
from flask import Flask, Blueprint, request, url_for, \
jsonify, current_app, g
from flask_restful import Resource, Api, reqparse
@cisko3000
cisko3000 / twitter_location_trend_getter.py
Created June 11, 2017 21:33
This is some code that uses twitter API to get trending hashtags by location. Locations are yahoo locations.
import requests
import urllib
import json
import base64
class TrendGetter():
@staticmethod
def get_trending_hashtags():
@cisko3000
cisko3000 / controllers.py
Created February 29, 2016 06:23
Returns a data set for display by chart.js
from flask import Blueprint, request, render_template, \
flash, g, session, redirect, url_for, jsonify
from app import db
# Import models
from app.mod_auth.models import User
from app.mod_greg.models import Building, Floor, Suite, Visit, \
Visitor, visitors
from app.mod_rep.forms import ReportForm