SensorTag Temperature Readings in Python

I wanted to wrap up my previous post (TI SensorTag Temperature Readings ) with a little python example, thus this write is going to be short and sweet. Using the bluepy python library (written by Ian Harvey) I’ve been able to to capture temperature readings, then covert them to Fahrenheit. To demonstrate I captured a couple temperature samples, a few while sitting on my desk, and a few held up to my air condition vent:

Python traceroute style tool

Recently, while talking with a some techies I was asked to explain how traceroute works. I was quick to answer what results I expect back from the command, and how to understand that data, but for the life of me I was having issues recalling how TTL works at the foundation. Later that week I spent some time reading up on it, and click, it all came back. To reinforce this I decided to write some code.

PostgreSQL vacuum script

PostgreSQL does have a built in auto vacuum , but sometimes you just want a small script that can be ran through Jenkins to perform the vacuum for you. Wanted to share with you guys a small Python script I wrote that will perform a VACUUM VERBOSE ANALYZE on every table within a database. You will need to get psycopg2 installed from PyPi first: pip install psycopg2 At which point you should be able to use the below script with the correct environment variables to vacuum your database:

Raspberry Pi – cleverbot voice communication

Using my first generation Raspberry Pi and a few USB / analog devices, i’ve been able to create (a rather slow) cleverbot voice communicator. The reason for the slow down is initialization and listening on the USB microphone, but other than that everything works as expected. #!/usr/bin/env python import speech_recognition as sr import pyttsx import cleverbot print 'Initializing, please wait...' # define our cleverbot cb = cleverbot.Cleverbot() # speech recognizer setup r = sr.

Janky Lego stop motion

Well the kids have lost interest in Raspberry Pi Python programming for now, but look who’s still at it! The jankyiest of Lego stop motions. Here was the code I tossed together to make the gif above: #!/usr/bin/env python2 import os import time import shutil import datetime import tempfile import pygame.camera import pygame.image import RPi.GPIO as GPIO save_dir = '/usr/share/nginx/www' GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.cleanup() GPIO.setup(17, GPIO.IN) pygame.camera.init() camera = pygame.camera.Camera('/dev/video0') def make_picture(filename): raw_input('Ready for picture?

GeoDjango and Taco Bell

I’ve been at it again with GeoDjango , this time I’ve pulled data on all Taco Bells locations from a popular social media site, took that data and added to a Django project, and finally plotted them in a view using Google Maps : Wow, that is a lot of Taco Bells ! Since this is Django, we are also able to view and edit from the admin :

Using GeoDjango to filter by Points

Just recently I found myself playing with GeoDjango , I’ve been using it on both a Ubuntu 14.04 cloud server and a Macbook Pro (OS X El Capitan). GeoDjango allows us to query by geographic points directly on the data model. We are then able to extend the model, and add a custom method to search by zipcode. Using the Django shell we can easily check data in our favorite interpreter :

TV Style Computer Hacking!

My son asked the other night if hacking computers really worked like on television, and if numbers/words really flashed across the screen. I explained to him a bit, then told him we could make something that looked like he seen on television. Below is a print out I wrote for him. Keep in mind I tried to dumb it down a bit for my 10 year old son. Hacking MD5 Hashes What is a MD5 Hash?

Split Python List by Nth Item

This has been one of the processes I’ve normally not solved in a clean or readable way. In []: a = [1,2,3,4,5,6,7,8] Taking the top output I want to return something similar to below. Out[]: [(1, 2), (3, 4), (5, 6), (7, 8)] Using a Pythonic approach this task isn’t to difficult, but there is some explaining to do. First lets look at the code: In []: a = iter([1,2,3,4,5,6,7,8]) In []: [ i for i in zip(a, a) ] Out[]: [(1, 2), (3, 4), (5, 6), (7, 8)] First we need to pass our list to the iter function, this turns our list into a iterator object:

Linux /proc/net/route addresses unreadable

So you may have looked at /proc/net/route before and thought how the heck am I suppose to read this. Well here is the low down. This file uses endianness to store the addresses as hexadecimal, in reverse; for example 192 as hex is C0 : In []: hex(192) Out[]: '0xc0' So lets take a look at our route file: Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT eth0 00087F0A 00000000 0001 0 0 0 00FFFFFF 0 0 0 eth0 0000FEA9 00000000 0001 0 0 1002 0000FFFF 0 0 0 eth0 00000000 01087F0A 0003 0 0 0 00000000 0 0 0 Now the first entry has a destination of 00087F0A , lets go ahead and chunk these in to hex characters: