Android 3.x and 4.x NumberPicker Example

I was working on a new, yet to be released, Android app that necessitated the need for the new NumberPicker widget introduced in Android 3.0. Unfortunately, there are almost no examples of its use floating around and the documentation in the Android API is extremely lacking. Thus, I spent a few hours of trial and error figuring out how it worked.

My goal: Use a NumberPicker to allow a user to select a multiple of 5 in the range 0-100.

First up: The XML.

1
2
3
4
<NumberPicker android:id="@+id/np"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:width="100dip"/>

The XML for our NumberPicker looks very similar to any other Android widget. By default the NumberPicker is set up for displaying two digit numbers, but our last number in this case, 100, is three digits. Hence, the leading 1 in 100 will be cutoff and only 00 is displayed in the NumberPicker. To remedy this, the width is set to 100dip which is wide enough to allow for three digit numbers.

Because of the lack of XML properties for the NumberPicker, we must do all of the configuration for it in code. Speaking of which…

Making the iRobot Create Command Module Play Nicely with Linux

As a club project, the ACM recently bought an iRobot Create. It comes with some software for programming in Windows, but, honestly, the GUI application that it comes with is junk. It barely works at all. Add that with the fact that it’s a Windows application meant that I was on the hunt for making this guy work under Linux.

Well, a quick Google session later and I come across this wonderful Instructable. However, I did have to jump through one more hoop to get it working than was in the guide. Thus, here’s my whole version of getting the iRobot Create’s command module to work in Linux.

Listserv Auto-Subscribe Form

In my never ending quest to make the Penn State ACM’s website as automated and as useful as possible, I wanted a page that allowed a user to enter his name and email and automatically be added to our listserv. With a little HTML, PHP, and a touch of the Drupal API (our website runs on Drupal), it was up and running in a little under an hour. Code incoming.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

if (isset($_POST["name"])) {
   $name = $_POST["name"];
   $email = $_POST["email"];

   if(mail("listserv@lists.psu.edu", "Listserv Subscription",
            "SUBSCRIBE L-PSU-ACM " . $name, "From: " . $email)) {
      drupal_set_message("Subscribe confirmation sent to " . $email . ". Thanks for signing up!", "status");
   } else {
      drupal_set_message("Error sending subscribe request to " . $email .
                         ". Email webmaster@acm.psu.edu if problem persists.", "error");
   }
}

echo '
<form method="POST" action="">
   <b>Name:</b>
   <input type="text" class="form-text" name="name" size="60" value="" />
   <b>Email:</b>
   <input type="text" class="form-text" name="email" size="60" value="" />

   <input class="form-submit" type="submit" value="Submit"/>
</form>

';
?>

As you can see all it is an HTML form that calls the PHP mail function which sends an email to Penn State’s listserv server on behalf of the user requesting that he be added to our listserv. From there, the ListServ server sends a confirmation email to the user and all that need be done is to click a confirmation link. That’s it! Simple, no?

One note however. I would have preferred to have put the PHP in a separate file in order to keep the HTML and PHP away from one another, but I needed to use the drupal_set_message function meaning it had to be called from within a Drupal node. I’m sure there are ways to call it from outside a Drupal node, but given the scope of this project, this solution works just fine.

TEDxPSU 2011 Reflections

After the incredible show put on by TEDxPSU 2010 last year, I was compelled to volunteer for TEDxPSU 2011 this year. So over the past few months I had been in charge of organizing the student expo, or Xpo as we branded it. The goal was to showcase some of the groups and clubs around campus that do cool stuff to the attendees of TEDx before the main event starts. At first, I had trouble getting enough interest from clubs to want to participate in the Xpo. However, given enough time and persistence that changed. From there, everything was fairly straightforward. On the day of TEDx I show up, the groups show up, they present their work to the attendees, and they pack up, all while I simply supervise and take care of any problems that arise. The Xpo went so smoothly that I actually had plenty of time to help other volunteers with their jobs. After everything was said and done, the speakers had presented their topics, and Alumni Hall fell silent all the volunteers and I had the task of tearing down the entire hall (see below pictures!) in just over three hours.

Floating Point Precision in Bash

I wanted to add a timer to my Linux compile script so I could see how it took to compile the kernel. However, Bash does not support floating point precision. Now seeing as kernel compiles take some time this shouldn’t matter. I could use the date command to get the hour, minute, and second before and after the compile and subtract them, adjust for difference in hours, days, etc. This way I wouldn’t need any type of precision. But that’s a lot of work, and I want to know exactly how long it took; not rounded to the nearest minute.

Rather, why not just get the seconds from 1970 before and after the compile, subtract the two, and divide by 60? Much easier! Except, I need floating point precision. The solution: the bc program. It’s like a command line calculator that supports all the precision I could ever need. Let’s take a look: