Skip to content

Instantly share code, notes, and snippets.

@MercuryRising
MercuryRising / arduinoPlotter.py
Created June 24, 2012 01:40
Threaded Arduino Reader / Plotter / Writer
'''
I adapted the live plotting code from somewhere but I cannot remember where.
If you know where, I would be happy to add it to the comment here.
'''
'''
I adapted the live plotting code from somewhere but I cannot remember where.
If you know where, I would be happy to add it to the comment here.
'''
import threading
@MercuryRising
MercuryRising / bodyInformation.py
Created June 26, 2012 06:21
Calculating the information the body receives over a lifetime
def humanize_bytes(bytes, precision=1):
# taken from http://code.activestate.com/recipes/577081-humanized-representation-of-a-number-of-bytes/
abbrevs = (
(1<<60L, 'EB'),
(1<<50L, 'PB'),
(1<<40L, 'TB'),
(1<<30L, 'GB'),
(1<<20L, 'MB'),
(1<<10L, 'kB'),
(1, 'bytes')
print("Hello master chef, and welcome to MeatTemp Version 1.0!")
print("Please type your name and press ENTER: ")
name = input()
print("Welcome,",name+"! Please select the number corresponding to the type of meat you will be working with and press ENTER: ")
print("1. Beef (Ground)")
print("2. Beef (Non-ground)")
print("3. Chicken")
print("4. Turkey")
import sys
def printIt(meatType, temp):
meatType = ' '.join(meatType)
print("I recommend cooking your {0} to an internal temperature of {1} degrees Fahrenheit.".format(meatType, temp))
print("Thank you for using MeatTemp Version 1.0! Bon appetit!")
sys.exit()
while True:
print("Hello master chef, and welcome to MeatTemp Version 1.0!")
@MercuryRising
MercuryRising / flask_redis_cache.py
Created October 12, 2012 00:14
Flask Redis Cache
import redis
import time
def cache_or_get(fp, expiry=300, r=redis.Redis(db=5)):
'''
Input fp: file to cache or get
Input expiry: time to expire for file (default 300 seconds)
Input r: redis instance (default new instance with db set to 4)
Usage:
@MercuryRising
MercuryRising / rcl.py
Created November 6, 2012 04:27
Reddit Command Line
#! /usr/bin/env python2
# Requests is much easier to use than urllib
import requests
# needed for sys.exit()
import sys
# Wrap it in a function you can, you might find a use for it later
# We're adding subreddit functionality, but still providing a default
#/usr/bin/python
import serial
import time
import sys
extruderSetPoint = 345
bedSetPoint = 6300
ser = serial.Serial("/dev/ttyUSB0", 115200)
''' This is adapted from an example I found somewhere, if anyone knows what it is let me know and I'll credit the original '''
import threading
import time
import math
import gobject
import matplotlib
matplotlib.use('GTKAgg')
import matplotlib.pyplot as plt
import random
@MercuryRising
MercuryRising / easyalias.py
Last active December 15, 2015 11:09
Easily alias your bashrc file (a 'step through' of making the program)
'''
We are going to make a program that lets us run something like:
python easyalias.py sl ls
or
python easyalias.py I_want_my_python_now python
and adds the alias to our .bashrc file, letting us easily add aliases that persist without directly editing the file.
@MercuryRising
MercuryRising / easyalias.py
Last active December 15, 2015 17:29
Easy aliaser for bash. If you keep navigating to directories to run files, easyalias them.
#!/usr/bin/python
'''
Bash RC aliaser
Usage: easyalias aliasName aliasPath
Outputs: run source ~/.bashrc for commands to take effect
Configuration: If you have a different shell or your bashrc is somewhere other than ~/.bashrc, you'll need to change it.
It wouldn't be a bad idea to use ~/.bash_aliases instead of your bash file directly (changing config will do it).