Skip to content

Instantly share code, notes, and snippets.

View alaudet's full-sized avatar

Al Audet alaudet

View GitHub Profile
@alaudet
alaudet / pandas_date_handling_from_excel.py
Last active August 9, 2022 08:43
Converting Excel dates in 5 number format for python
import datetime
# When dumping to csv excel puts date in 5 digit float format (e.g. 39856.0)
# function converts series of dates to date string.
def date_to_string(digit_date):
new_form = []
for d in digit_date:
try:
x = datetime.date(1899,12,30) + datetime.timedelta(days=float(d))
new_form.append(x.strftime('%Y-%m-%d'))
@alaudet
alaudet / nosetests
Created June 8, 2019 12:40
Nose Tests Pydocs
NAME
nose.tools
DESCRIPTION
Tools for testing
-----------------
nose.tools provides a few convenience functions to make writing tests
easier. You don't have to use them; nothing in the rest of nose depends
on any of these methods.
@alaudet
alaudet / toggle_code_jupyter
Created May 29, 2019 11:54
Toggle Code View in Jupyter
# Source: https://stackoverflow.com/questions/27934885/how-to-hide-code-from-cells-in-ipython-notebook-visualized-with-nbviewer
from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
@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 
@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 / 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 / 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 / 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 / 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 / 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