Skip to content

Instantly share code, notes, and snippets.

Avatar
😵
...

Brad Montgomery bradmontgomery

😵
...
View GitHub Profile
@bradmontgomery
bradmontgomery / list_gists.py
Created Oct 19, 2019
Quick & dirty hack to list a user's gists, sorted by stars
View list_gists.py
#!/usr/bin/env python
"""
A quick & dirty hack to list all of your Gists sorted by stars.
This script lists your gists, the number of stars, the number of comments,
a truncated description, and the url for the gist.
"""
@bradmontgomery
bradmontgomery / config.ini
Last active Sep 27, 2019
Python config parsing / access experiment.
View config.ini
[DEFAULT]
num = 42
pi = 3.141312301928312039810
debug = no
on = yes
sleep = 2
[mqtt]
host = localhost
port = 1883
@bradmontgomery
bradmontgomery / main.py
Last active Aug 5, 2019
Playing with RQ priorities
View main.py
#!/usr/bin/env python3
"""
Experiment to show how rq priorities might work with jobs that will complete in different amounts of time...
IF you run a single worker (rqworker high low), this may do what you expect, but if you run multiple workers,
the low-priority tasks that take less time may complete before some of the high-priority tasks.
$ python main.py
Enqueued work for 0 in HIGH
@bradmontgomery
bradmontgomery / publishers.py
Created May 13, 2019
Simple example of MQTT publishers / subscriber using paho.mqtt
View publishers.py
#!/usr/bin/env python
"""
Spawn a lot of publishers.
"""
import json
import os
import random
import sys
View pytables_cheatsheet.md

On using pytables; how do I...

A lot of this info is in the docs for Tables.

Open the file for reading, and get a reference to a table:

>>> with tables.open_file(path, mode='r') as f:
...     table = f.root.some_columns.table
@bradmontgomery
bradmontgomery / get_accel_data.py
Last active Mar 5, 2019
Example code to fetch accelerometer data from the Preteckt API.
View get_accel_data.py
"""
This example python code shows how to appropriately query the Preteckt
accelerometer API for data over a date range.
Run with:
$ python get_accel_data.py
@bradmontgomery
bradmontgomery / friendly.py
Created Feb 4, 2019
A function to enumerate and print a list of items horizontally using the space available in your terminal (optionally, without wrapping text).
View friendly.py
"""
A function to enumerate and print a list of items horizontally using the
space available in your terminal (optionally, without wrapping text).
Example:
>>> friendly.test()
1. a cat 2. a dog 3. Three pairs of socks 4. A kick-ass bicycle
5. chickens 6. A quick brown fox 7. and a lazy dog
8. Lorem ipsum dolor sit amet, consectetur
@bradmontgomery
bradmontgomery / example.py
Created Jan 29, 2019
Illustrating sys.argv in python
View example.py
"""
This script illustrates how to use sys.argv to
capture command-line arguments.
Dowload & run this file like so:
python example.py
OR like this:
@bradmontgomery
bradmontgomery / main.py
Last active Sep 17, 2018
Hack to get the uncompressed size of a gzip file without reading the whole thing.
View main.py
#!/usr/bin/env python
"""
Test if we can reliably figure out the uncompressed size of .gz file...
"""
import gzip
import os
import subprocess
@bradmontgomery
bradmontgomery / main.py
Created Aug 21, 2018
Examples of using concurrent.futures with Threads & Processes and the joblib library to read data from a bunch of files & do some simple parallell processing.
View main.py
#!/usr/bin/env python
"""
process some data
"""
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from joblib import Parallel, delayed
import os
import statistics
You can’t perform that action at this time.