Skip to content

Instantly share code, notes, and snippets.

View alaudet's full-sized avatar

Al Audet alaudet

View GitHub Profile
@alaudet
alaudet / decimal_output
Last active August 29, 2015 14:02
Decimal output
import decimal
number = float(1.787654)
decimal.getcontext().prec = 2
dec_number = decimal.Decimal(number) * 1
print str(dec_number)
@alaudet
alaudet / smtplib_gmail
Last active August 29, 2015 14:02
smtplib gmail
import smtplib
import string
def smtp_gmail():
username = "your smtp username here "
password = "your smtp password here"
smtp_server = "smtp.gmail.com:587"
email_from = "sender email"
email_to = "recipient email or wireless carrier sms #"
email_body = string.join((
@alaudet
alaudet / timelapse
Created July 7, 2014 18:48
Timelapse pictures using Picamera module.
# take snapshots to create a timelapse video
import time
import picamera
method = raw_input("Select timelapse in seconds or minutes (S or M):> ")
if "s" in method or "S" in method:
seconds = int(raw_input("Enter photo interval in seconds: >: "))
@alaudet
alaudet / smtplib_gmail_multiple_recipients
Last active August 29, 2015 14:03
smtplib gmail multiple recipients
import smtplib
import string
def smtp_gmail():
username = "your smtp username here "
password = "your smtp password here"
smtp_server = "smtp.gmail.com:587"
recipients = ["email@somewhere.com", "email2@somewhere.com", "email3@somewhere.com"]
email_from = "sender email"
@alaudet
alaudet / crontab
Last active August 29, 2015 14:05
Crontab
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
@alaudet
alaudet / decimalize.py
Last active August 29, 2015 14:06
Decimalize floats with the python decimal module
import decimal
value1 = 29.458699990
value2 = 0.458699990
decimal_places = 2
def decimalize(value, decimal_places):
"""Round a value to a specified decimal place."""
left_of_decimal, the_decimal, right_of_decimal = str(value).partition(".")
if left_of_decimal == str(0):
@alaudet
alaudet / Dicts_instead_of_if_elif
Created May 4, 2015 14:56
Using Dicts instead of large if, elif statements
# Example of using a dict instead of numerous if/elif statements.
handlers = {
"A": funtion_one,
"B": function_two,
"C": function_three,
"D": function_four,
"E": exit
}
@alaudet
alaudet / 8192cu.conf
Last active June 30, 2016 20:06
Fix Wifi High Latency Issue on Raspberry Pi
1 - Create the file /etc/modprobe.d/8192cu.conf
2 - Add the following line to the file
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
3 - Reboot
4 - Check if power saving mode is switched off (0 = off, 1 = on)
cat /sys/module/8192cu/parameters/rtw_power_mgnt
@alaudet
alaudet / halt.py
Last active February 6, 2018 16:25
Raspberry Pi Graceful Shutdown with gpiozero
#!/usr/bin/python
'''Having a little fun with Raspberry Pi and gpiozero. Small script that uses
a button and leds to indicate a graceful Linux shutdown.
Module at https://github.com/RPi-Distro/python-gpiozero
Wiring your button
https://github.com/RPi-Distro/python-gpiozero/blob/master/docs/inputs.md
@alaudet
alaudet / install virtualenv ubuntu 16.04.md
Created April 14, 2019 11:24 — forked from Geoyi/install virtualenv ubuntu 16.04.md
How to install virtual environment on ubuntu 16.04

How to install virtualenv:

Install pip first

sudo apt-get install python3-pip

Then install virtualenv using pip3

sudo pip3 install virtualenv