Skip to content

Instantly share code, notes, and snippets.

View bradmontgomery's full-sized avatar

Brad Montgomery bradmontgomery

View GitHub Profile
@bradmontgomery
bradmontgomery / example.py
Created January 29, 2019 16:55
Illustrating sys.argv in python
"""
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 June 13, 2022 20:00
Hack to get the uncompressed size of a gzip file without reading the whole thing.
#!/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 August 21, 2018 02:38
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.
#!/usr/bin/env python
"""
process some data
"""
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from joblib import Parallel, delayed
import os
import statistics
@bradmontgomery
bradmontgomery / main.py
Created June 18, 2018 21:11
Simple Twython streaming search
"""
See Streaming API: https://twython.readthedocs.io/en/latest/usage/streaming_api.html
"""
import os
import sys
from twython import TwythonStreamer
class TweetPrinter(TwythonStreamer):
def on_success(self, data):
@bradmontgomery
bradmontgomery / test.cpp
Created April 30, 2018 20:02
An experiment in file writing.
/**
*
* Experiment: Trying to see how an output file could possibly be corrupted
* by failed program....
*
*
* e.g. https://trello.com/c/7F9VWd2s/980-error-in-vincsv-from-the-logger
*
* Experiment:
*
@bradmontgomery
bradmontgomery / api_toy.py
Created March 16, 2018 00:30
An example of using Python to talk to an API
import json
import requests # 3rd-party lib, "pip install reqeusts" to install.
from pprint import pprint
def get_stuff(payload="hello"):
"""
This function will talk to httpbin.org, via a GET request. It will send
the provided payload, and print out the http status code and the arguments
it receives from httpbin.
@bradmontgomery
bradmontgomery / oo_example.py
Created October 25, 2017 00:37
Example code illustrating some simple Object-Oriented Programming concepts.
class Animal:
# This is our base class that describes an Animal.
sound = "..." # The default sound an animal makes.
def __init__(self, sound=None):
# This is a constructor method. It will
# set up an animal's sound.
if sound:
self.sound = sound
@bradmontgomery
bradmontgomery / pointers.c
Last active October 8, 2019 23:50
A simple example of the * and & operators.
/* Pointers!
*
* Address of and value at...
*
* See this great stack overflow answer for an additional
* discussion on the topic.
*
* https://stackoverflow.com/a/2094715/182778
*
*/
@bradmontgomery
bradmontgomery / LICENSE.txt
Last active December 1, 2023 21:01
A python decorator that logs execution time.
Copyright 2020 Brad Montgomery
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
@bradmontgomery
bradmontgomery / wheeee.c
Last active October 25, 2018 23:45
Pointers are powerful! But don't forget... with great power comes great responsibility!
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0; i < 10000000; i++) {
*&i = 10;