finding files by date

I got tired of looking this up every time, and I’ve not seen anyone write about this specific use case. When dealing with dev servers in the cloud, sometimes I forget the use case for one. I find it useful to be able to find all the changed files on a system by date.

find / -mount -printf ‘%T@\t%T+\t%s\t%p\n’ | sort -nr

This shows me config files which recently changed, log files which recently changed. I can examine those and get an idea of the state of the system.

I use ls -alrt often enough, but this uses find so I get a view of the entire filesystem at once instead of a single directory.

Book Review: BeagleBone Robotics Projects

I was asked by Packt Publishing if I would read and review this book. I’ve owned a BeagleBoneBlack for a little while now. My use case was not robotics. This book might shed some new light on my old Black, so I agreed to review it.

The book starts off very accessible. Chapter 1 covers just about everything I did with my BBB when I first received it, hooking it up like a PC, replacing the default distro, making sure I could SSH to it were all in there. The author, Richard Grimmett, goes a step further and installs XFCE gui and vncserver and walks through connecting from a Windows PC using vncclient. All in all, chapter 1 is a great super basic tour.

Chapter 2 dives into programming on the thing and introduces Python. It does it in a really weird (to me) way. It has the reader running emacs in a putty window remote connected to the device. This must just feel weird to me because I do a lot of remote programming and its never with emacs (I’m a vim guy) and its rarely remote. For a new user, it seems to me like it would have been simpler and more friendly to say “use an editor of your choice” and “here is notepad2 or sublime” along with “here is how you copy files to and from the device.” I think this is mostly my background causing me to see things differently. The emacs in putty walk-through is very adequate.

Its not a programming book, so this is really a nit pick, but technically some of the descriptions of python aren’t really true. For example, if __name__==”__main__”: does not “tell the program to begin its execution at this point.” Again I’m nit picking, but I do feel like a different phrase that isn’t so very false to someone who knows python could have been found. Still, its not a programming book. The beginning of the chapter does list many resources for learning python.

Ugh, and then the book moves on to C++ and has quotes like this, “C++ is the original language of Linux” I’ve used Linux for almost as long as I’ve programmed C, and I am very (perhaps overly?) sensitive to the difference between C and C++.

OMG what do you mean Speech Input and Output? Really?  Chapter 3 tackles it. Really. For real. Speech Input and Output on that tiny little board. I can make my own Siri! This is a really cool topic; espeek is something I’ve only played with a little bit prior to reading this. It looks fun.

Speech recognition is done with software I’ve never used before called PocketSphinx. It isn’t packaged and so one has to compile it. Pretty sweet BBB being able to compile stuff like that. (I’m thinking of iOS and Android where I’ve not seen a compiler run on device.) The demo walks through limiting the grammar of speech input so that you don’t have to train the recognizer.

I’m a programmer, so I’m going to nitpick programmer things. I really wish authors wouldn’t do this, “I like to make a copy of the current file into continuous.c.old, so I can always get back to the starting program if it is required.” I really do wish authors would just say “go read about version control systems.”

Whew, speech is fun. Next step is video. Hook up a webcam and let’s do some image recognition. The book walks through OpenCV and it is as this point that we are forced to do a bunch of Linux sysadmin stuff to make our SD have enough free space to have a dev environment. This really could have gone anywhere in the book. I kind of like that it put it off until it was necessary.

The python image tracking example using OpenCV looks pretty cool. It is a complete example without going too deep or going off in the weeds.

Making the Unit Mobile introduced me to mobile platforms. The Magician Chassis that the book shows first, I found online for under $20! I knew that this stuff was accessible, but this is downright cheap. I feel almost guilty NOT getting one and trying it out.

The motor controller tutorial looks very straightforward. I already have ideas for code changes. Immediately after the simple time based tutorial it goes into speech controlled movement, which is pretty sweet.

After the wheeled robot tutorial is a walking robot example. The author makes a compelling argument for this type of robot, and the Pulse Width Modulation servo motors are cool, but I have to admit, this type of robot just doesn’t excite me. The book also punts on the PWM, using a controller which interprets serial USB commands into the PWM for the servos. For beginners, this is certainly the right choice.

Incidentally, the –help output from UscCmd includes Version, Culture, PublicKeyToken values like a Mono program might. I wonder if it is written in C# and running via Mono. I’m going to assume it is. That is pretty sweet. Indeed the linked download page mentions C#. http://www.pololu.com/docs/0J40/3.b

The sonar sensors section is a straightforward and great introduction to the use of them. I never knew how those things worked or what kind of value they returned. Now I do. Mounting the sensor to a survo makes for a nice subsystem on the bot.

Next, a fully remote control system is built. I don’t know if I like the choice of using an LCD monitor. It seems like overkill, but depending on the particular robotic application it would be a good choice. For the applications I have in mind, I think I’ll skip it. A wireless usb keyboard and mouse makes for an obvious choice. At this point, I just keep thinking about bluetooth and using an extra Wiimote, mostly because I think it would be a more fun control.

Oh, a GPS receiver! This could be necessary for when I lose my robot in a parking lot or the woods. As with the LCD Monitor and KB chapter, I kind of feel like I know how to do this since I’ve looked into it before. It is great coverage and good intro to the topic.

Much of my day job is what would traditionally be called Systems Programming so Chapter 10 is kind of a duh to me. I’d have started there, but that is just how I think about coding these days. Its great to have this in a chapter to tie some things together. In other words, read this chapter!

Using the BBB in sea, air and submarine applications is an interesting idea. I don’t think it is for me yet, but the book gives introduction to some ideas on the topic. The introduction to feedback control is very welcome.

Overall this is a great book. It really gave me a lot of ideas. It also showed me how easy it is to get started, something which I’d been a little hesitant to do. I’m actually a little excited to dive in now. I’ll be doing a bunch of this stuff with my 6yo over the next few years.

Blocking Unwanted Internet Traffic 101

I recently came across this very suggestion on serverfault which starts with blocking spoofed packets. I’m addressing on the first block of rules here.

http://serverfault.com/a/410618/79028

It is a simple iptables ruleset which blocks most of the common rfc1918 addresses. You have probably heard of these, the 10/8, 192.168/16 and 172.16/12 address ranges. What might be new to you, is that there is a whole great many more ranges which one should never observe on the internet.

You might add to your list:

  • TEST-NET(192.0.2.0/24) from rfc3330
  • benchmarktest(198.18.0/25) from rfc2544
  • protocol assignment(192.0.0.0/24)
  • testnet2(198.51.100/24) and testnet3(203.0.113/24) from rfc5736 and 5737
  • carrier grade nat(100.64/10) from rfc6598

Blocking addresses of these ranges is completely valid. IANA has not and will not assign them for use on the internet. They are reserved and non internet route-able.

 

Converting your existing ssh rsa key for use with Windows Azure

Oh Microsoft, it seems like you make simple things complex.

I could not find anything on converting an existing ssh key for use with Azure. Once I figured out what was needed and the commands available to me, it was easy. It only took me hours of fiddling with ssh-keygen and openssl.

The magic was learning that openssh stores its id_rsa in a format which openssl can read. This means I can use openssl directly to convert this private key.

openssl req -x509 -new -days 365 -key id_rsa -out id_rsa.x509req.pem

Type in your password for your private key (if you are not using a password, you should be.) Then fill out the certificate request fields.

Now you can boot your azure vm using id_rsa.x509req.pem

azure vm create jrwtest b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-12_04_3-LTS-amd64-server-20130916.1-en-us-30GB jwren –location “East US” -e -t id_rsa.x509req.pem

Now you can secure shell to your azure vm.

ssh jrwtest.cloudapp.net

SWEET. :)  No generating new ssh keys for me.

I recently read a post by someone lamenting the thanklessness a programmer gets. I once worked in IT where services are really considered a utility. No one calls the utility company unless there is a problem. Have you ever called your electric, phone, or gas company to thank them for the great service? I didn’t think so. This was my response:

Sounds like a bad environment. For a long time now, I’ve worked on teams where we are our own worse critic and where I’ve received more thank you emails than criticizing emails. That said, I don’t consider error reports to be criticizing emails. They are just that, a report of something which went wrong. Things always go wrong, not just in programming. In business and in life, something will always go wrong. How you respond to the wrong doing can largely influence your happiness as a human being.

Sometimes mind shift has to happen to really make this effective. Things like http://www.c2.com/cgi/wiki?EgolessProgramming can help you remember that you are not your code. Error reports mean that someone care about what you created and wants to help you make it better. That is awesome. I’d love much but maybe not too much of that kind of feedback.

git svn terrible trouble

I use git svn.

I recently somehow (I do not recall) put git svn into a strange state.

The symptom was that from master, git svn info would show a branch to which I once committed instead of trunk. I could not figure this out. My solution was to rm -rf .git/svn/ ; git svn fetch -r latesttrunkrev to let git svn recreate the refs. Then all worked.

Now git svn info from master tells me trunk, like I expect it to.

 

xpath from command line

I’m curious how often someone has written the equivalent of this. I wonder why there isn’t just some tool, and yes, I’ve used xmllint shell to do the same thing.

 1 using System;
 2 using System.Xml;
 3 
 4 public class Program {
 5     public static int Main(string[] args) {
 6         var  doc = new XmlDocument();
 7         doc.Load(args[0]);
 8         foreach (XmlElement n in doc.SelectNodes(args[1])) {
 9             Console.WriteLine(n.InnerXml);
10         }
11         return 0;
12     }
13 }

When Reversing the Interview Process becomes How Would You Do Fun Things in C

My boss’s boss’s pals wrote this: http://blog.exodusintel.com/2012/09/18/reversing-the-interview-process/

Its a story about how someone was asked a crazy fun C question in an interview and how the new team decided to try it.

After reading this and discussing it with coworkers, I decided to try it and of course the first thing that came to my mind was a way to use tail recursion to do it.

 1 #include <stdio.h>
 2 
 3 int c;
 4 //auto func0 = [&] () -> int { c++; _strlen(s+1);};
 5 //auto funcn = [&] () -> int { return c; };
 6 int rs(char* s);
 7 int go(char* s) { c++; return rs(s+1); }
 8 int ret(char* s) { return c; }
 9 int rs(char* s) {
10     int (*func[2]) (char *s) = {ret,go};
11     char i = (*s>>7 | *s>>6 | *s>>5 | *s>>4 | 
        *s>>3 | *s>>2 | *s>>1) & 1;
12     return func[i](s);
13 }
14 int _strlen(char* s) {
15     c = 0;
16     return rs(s);
17 }
18 
19 int main(int argc, char* argv[]) {
20     printf("_strlen(%s): %d\n", argv[1], 
        _strlen(argv[1]));
21     return 0;
22 }

After writing it, I went and looked at the other fella solutions for the second time. I should also mention that I haven’t written C on the job in 11 years, and when I did then, it was one tiny program which was quickly replaced with perl. I have never been anything other than an intro beginner C programmer.

Things I noticed after going back is that my solution is somewhat similar to Brandon and Zef’s solution, but I think both my use of function pointers and bit shifting are more elementary. I’m still not sure about how some parts of their solution works.

Installing iWork09 from CD without a Mac

You’d think you could just use Apple’s nice CD Sharing program, aka Remote Disc http://support.apple.com/kb/HT1777?viewlocale=en_US

But sadly, the iWork09 CD is not an iso9660 disc. Instead it has an Apple style partition table, which was not readable by fdisk and crashed parted in linux, with an HFS+ filesystem. When you insert the disc into a Windows PC it simply will not read it.

So, I booted to Linux, used dd to rip the cd and started analyzing the contents of the disc. What I came up with was a way to extract the HFS+ filesystem from the disc image. Since I don’t really care about the filesystem being perfect – I only care about being able to install iWork on a new Mac Book Air – I only care about where it starts and I run a fsck tool to repair the end of filesystem.

The filesystem begins at an offset of 72blocks (36864bytes):
$ if=iwork09.img bs=512 skip=72 of=iwork09-1.img

Repair the filesystem:
$ fsck.hfsplus iwork09-1.img

Mount it and copy the iWork directory or install it from there
$ mount -t hfsplus iwork09-1.img /mnt

A little extra work, but it beats a trip to the Genius Bar.

 

babblings of a computer loving fool