Skip to content

Instantly share code, notes, and snippets.

View danieljfarrell's full-sized avatar

Daniel danieljfarrell

View GitHub Profile
@danieljfarrell
danieljfarrell / environment.yml
Created January 11, 2019 16:41
Conda environment
name: asyncstuff
channels:
- defaults
- krisvanneste
- david_baddeley
- conda-forge
- danieljfarrell_teraview
- teraview
- pkgs/main
- pkgs/free
@danieljfarrell
danieljfarrell / test_traitsui_quamash.py
Last active February 22, 2020 13:31
An example of asynchronous programming with TraitsUI using QT5 backend with Quamash event loop to work with asyncio.
"""
This code was helpful,
https://stackoverflow.com/questions/32141623/pyqt5-and-asyncio-yield-from-never-finishes
"""
import os
import sys
import quamash
import asyncio
import traceback
import PyQt5
@danieljfarrell
danieljfarrell / reset_timer.py
Created January 28, 2019 12:27 — forked from aeroaks/reset_timer.py
Reset Timer in Python
from threading import Thread, Event, Timer
import time
def TimerReset(*args, **kwargs):
""" Global function for Timer """
return _TimerReset(*args, **kwargs)
class _TimerReset(Thread):
"""Call a function after a specified number of seconds:
@danieljfarrell
danieljfarrell / async_slot.py
Created March 20, 2019 12:44 — forked from ericfrederich/async_slot.py
Example of using an asyncio coroutine as a Qt slot
import math
import sys
import asyncio
from functools import partial, wraps
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QGridLayout, QProgressBar, QErrorMessage
from PyQt5.QtCore import Qt
from quamash import QEventLoop
import traceback
@danieljfarrell
danieljfarrell / DoubleSlider.py
Created April 1, 2019 07:30 — forked from dennis-tra/DoubleSlider.py
PyQt - QSlider for float or double values + tests
from PyQt5.QtWidgets import QSlider
class DoubleSlider(QSlider):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.decimals = 5
self._max_int = 10 ** self.decimals
super().setMinimum(0)
if __name__ == "__main__":
from PyQt5.QtCore import QAbstractItemModel, QFile, QIODevice, QModelIndex, Qt
from PyQt5.QtWidgets import QApplication, QTreeView
import sys
from tree_model import TreeModel, TreeNode, RefNode
class NamedElement(object): # your internal structure
def __init__(self, name, subelements):
@danieljfarrell
danieljfarrell / state_transitions.py
Created June 7, 2019 13:41
Using an @visits decorator with an async generator to monitor and enforce state transitions
import asyncio
import traceback
import enum
import functools
class InvalidVisitedState(Exception):
""" Raised when an state change sequence is incorrect.
"""
pass
@danieljfarrell
danieljfarrell / treeview_test.py
Last active April 26, 2022 02:36 — forked from nbassler/treeview_test.py
PyQt5 TreeView with QAbstractItemModel
"""
Reworked code based on
http://trevorius.com/scrapbook/uncategorized/pyqt-custom-abstractitemmodel/
Adapted to Qt5 and fixed column/row bug.
TODO: handle changing data.
"""
import sys
@danieljfarrell
danieljfarrell / docker-compose.yml
Last active May 16, 2020 14:23
This is a single file docker-compose.yml version of tutorial https://medium.com/@containeroo/traefik-2-0-docker-a-simple-step-by-step-guide-e0be0c17cfa5 where all static config. is also done in the compose yaml file
version: "3"
services:
traefik:
image: traefik:v2.0
container_name: traefik
restart: unless-stopped
security_opt:
- no-new-privileges:true
networks:
@danieljfarrell
danieljfarrell / solve_ode_sys.nb
Created June 30, 2020 14:06
Solve chemical reaction for steady-state using Mathematica
ClearAll["Global`*"];
eqns = {X'[t] == P - (k1 + k2) X[t] + A k1 X[t], Y'[t] == k1 X[t] - A k1 X[t] - k3 Y[t], X[0] == 0, Y[0] == 0}
s = Assuming[k0 > 0 && k1 > 0 && k2 > 0 && k3 > 0 && P > 0 && A >= 0 && A < 1, Limit[DSolveValue[eqns,{X[t], Y[t]}, t], t -> \[Infinity]]]