Skip to content

Instantly share code, notes, and snippets.

🏠
def F(n)

Craig Derington craigderington

🏠
def F(n)
Block or report user

Report or block craigderington

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@craigderington
craigderington / strings_compare.py
Created Jul 12, 2019
Python while True loop updating Incoming Message UUID when Certain Conditions Exist
View strings_compare.py
import os
import time
import uuid
import random
from datetime import datetime, timedelta
def get_message():
return uuid.uuid4()
@craigderington
craigderington / hash_file.py
Created May 6, 2019
Create a Hash of a File
View hash_file.py
import os
import hashlib
def sha256sum(filename):
"""
Create a file hash
:param: str (file path)
:return: str (md5 hash)
"""
h = hashlib.sha256()
View asyncio-async-await.py
import asyncio
loop = asyncio.get_event_loop()
async def hello():
await asyncio.sleep(3)
print('Hello!')
if __name__ == '__main__':
loop.run_until_complete(hello())
View decorators_example.py
#! usr/bin/python3.6
# coding: utf-8
import time
from functools import wraps
def my_logger(func):
import logging
logging.basicConfig(filename='{}.log'.format(str(func.__name__)), level=logging.DEBUG)
@craigderington
craigderington / analyze.py
Created Mar 14, 2019
Python - Check Array Frequency
View analyze.py
the_list = [1, 3, 7, 9, 12, 3, 9, 12, 9, 10, 14, 23, 12]
def analyze_list(l):
counts = {}
for item in l:
if item in counts:
counts[item] += counts[item]
else:
counts[item] = 1
View xor.py
# -*- coding: utf-8 -*-byte1 ^ byte2 ^
# xor_final.py
# vars
checksum = 0
checksum_xor = 0
n = 2
# raw data
radio_09010 = '02040d3031000010723320000a100000363303'
@craigderington
craigderington / client.py
Created Mar 12, 2019
Python3 Socket Server Client
View client.py
#!.env/bin/python
# -*- coding: utf-8 -*-
import socket
import sys
import binascii
# client vars
host = '0.0.0.0'
port = 8060
@craigderington
craigderington / decoder.py
Created Mar 12, 2019
Python3 Socket Server Data Packet Decoder
View decoder.py
# .env/bin/python
# coding: utf-8
from collections import namedtuple
from datetime import datetime
def pad_reading(_reading):
"""
Return a full binary representation of the individual bytes
@craigderington
craigderington / server.py
Created Mar 12, 2019
Python3 Socket Server - Main App
View server.py
#!.env/bin/python
# -*- coding: utf-8 -*-
import socket
import sys
from db import db_session
from decoder import inspect_header, decode_header, decode_readings
from datetime import datetime
from models import Tx, TxHeader, TxReading
from sqlalchemy import exc
@craigderington
craigderington / db.py
Created Mar 12, 2019
Python3 Socket Server SQLAlchemy
View db.py
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('mysql://user:pass@localhost/RadioData', convert_unicode=True, pool_pre_ping=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
session = db_session()
You can’t perform that action at this time.