It’s easy to use:
b = Beacon() print b.last_record() print b.previous_record() #and so on
There’s also a handy generator for getting a set of n random numbers.
(One of the best gifts I ever got was a copy of 1,000,000 Random Numbers, and I’ve been intrigued ever since.)
Please note that this the randomness beacon is not intended to be a source of cryptographic keys — indeed, it’s a public set of numbers, so I wouldn’t recommend doing anything that could be compromised by someone else having the access to the exact same set of numbers. Rather, this is interesting precisely for the scientific opportunities that are possible when you have a random but public set of inputs.
I gave the opening keynote this morning at PyCon.
The one thing that everyone in the room at PyCon has in common is that we all love to code. I used that as the central theme of the talk, spoke about the constructs that give us joy, the history of some of our favorite patterns (they date as far back as the 60s!) and proposed that we think about the way we’ll compute fifty years into the future. There’s also a bit of fun data hacking, of course.
Enjoy the slides. The video is up!
Please let me know here or on Twitter if you have any questions or comments.
Over at NYC Resistor, it was getting cold, and we needed a doorbell so visitors wouldn’t be stranded outside when the building was locked. A standard wireless model didn’t work reliably (the space is on the fifth floor, just out of range), so various members generally resorted to writing their phone numbers on a sign on the front door when they were expecting guests.
Since almost everyone has a mobile phone already, and SMS-based solution seemed appropriate. In order to implement this we need two things:
- An SMS shortcode
- A system to notify when the shortcode is triggered
It’s irritating and expensive to acquire your own shortcode, but there are several services that will allow you to use one in exchange for a small fee or advertisements in your messages. TextMarks is my favorite (I used TextMarks for my WhereAmI project). While TextMarks markets their service as a system for mobile mailing lists, they allow you to reserve a keyword and define a behavior (that can include pulling data from a URL!) to occur when that keyword is triggered.
Sign up for TextMarks and choose a keyword. Configure the keyword to respond with the “First 120 characters on web page”, and point it at the future home of your script (you can always come back and modify this later).
Note the � as the value of the msg parameter — this instructs TextMarks to send along any additional message contents as the value of that parameter. That means if someone were to text 41411 “doorbell hi this is hilary”, TextMarks would call the script with the param msg=hi this is hilary. This can be quite useful.
This script is written in Python, but you can use any scripting language you like. This particular script just sends an e-mail to an account when the ‘doorbell’ is rung, but you could have it do pretty much anything up to and including ringing a real bell (which may be coming soon!).
#!/usr/bin/env python # encoding: utf-8 """ doorbell.py Created by Hilary Mason, feel free to use this code in your own projects. """ import sys, os import smtplib import cgi import cgitb; cgitb.enable() class Doorbell(object): GMAIL_USERNAME = 'YOURGMAILACCOUNT@gmail.com' GMAIL_PASSWORD = 'YOURPASSWORD' def __init__(self, msg): message = """ From: YOURGMAILACCOUNT@gmail.com To: YOURGMAILACCOUNT@gmail.com Subject: KNOCK KNOCK, someone is at the door! %s """ % msg server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo() server.starttls() server.ehlo() server.login(self.GMAIL_USERNAME, self.GMAIL_PASSWORD) server.sendmail('YOURGMAILACCOUNT@gmail.com', ['YOURGMAILACCOUNT@gmail.com'], message) server.quit() print "You knocked! You can also call us at 347-586-9270. <3, NYC Resistor" if __name__ == '__main__': print "Content-Type: text/plainnn" form = cgi.FieldStorage() if 'msg' in form: w = Doorbell(form['msg'].value) else: w = Doorbell('There is an anonymous monkey at the door.')
And that's it! Provided you have your keyword configured to point at your script, and the script living at an accessible address, you'll get an e-mail whenever your SMS doorbell is rung and the person who sent the message will get back a cute response confirming their action.
This setup can be easily extended such that a message containing 'doorbell hilary' could e-mail only me, or be forwarded to my phone.
I'm curious to see if having a remotely accessible 'doorbell' will encourage pranksters -- we might need to add a password.
The video of my IgniteNYC presentation is up, and has gotten a great response!
I’m working on removing the me-specific bits from the code and I’ll be posting it as open-source very soon!
I gave a talk at the NYC Python Meetup on July 29 on Practical Data Analysis in Python.
I tend to use my slides for visual representations of the concepts I’m discussing, so there’s a lot of content that was in the presentation that you unfortunately won’t see here.
The talk starts with the immense opportunities for knowledge derived from data. I spent some time showing data systems ‘in the wild’ along with the appropriate algorithmic vocabulary (for example, amazon.com‘s ‘books you might like’ feature is a recommender system).
Once we can describe the problems properly, we can look for tools, and Python has many! Finally, in the fun part of the presentation, I demoed working code that uses NLTK to build a Twitter spam filter with 90% accuracy*.
Please let me know if you have questions or comments.
* I’ll post the code and training data shortly