Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2015/05/19

01010100 01101000 01100001 01110100 00100111 01110011 00100000 01110111 01100101 01101001 01110010 01100100 00101110 00101110 00101110

Slight language warning.

The PaleoFuture blog on Gizmodo had a review of Tomorrowland from a Robot from the Future today, and of course it's in binary. I saw that shortly after coming in, and I thought "Hey, that'd be an interesting exercise to use to prime my programming pump, get my head in the right mindset."

So, I wrote code to decode it. I read perldoc -f pack and thought "Nope", so I found Data::Translate, which I now know is a very simple wrapper.

Once I wrote that, I decided the thing to do was to write b2a.pl and a2p.pl, because why not? But I found that this
a2b.pl Bite my shiny metal ass
gave me this
01000010 01101001 01110100 01100101 00100000 01101101 01111001 00100000 01110011 01101000 01101001 01101110 01111001 00100000 01101101 01100101 01110100 01100001 01101100 00100000 01100001 01110011 01110011
but this
b2a.pl 01000010 01101001 01110100 01100101 00100000 01101101 01111001 00100000 01110011 01101000 01101001 01101110 01111001 00100000 01101101 01100101 01110100 01100001 01101100 00100000 01100001 01110011 01110011
gave me this
Bitemyshinymetalass
So, what went wrong? Where did the spaces go?

This will take some time with me trying to grok pack, which is so unrelated to my daily responsibilities that I installed Data::Translate simply so I wouldn't have to learn a thing, but it seems that, if you pass pack the space character in binary (00100000), it returns an empty string. This is a somewhat strange thing, but once you understand the behavior, you can react to it.


(The catchphrase for Bender seemed the most appropriate text to use.)


2015/05/18

Some Wisdom From Twitter

2015/05/14

There are Two Javas

So, this happened...

On the one hand, I wrote this on a day when I woke up after watching this fantastic conference talk on Neo4J and RNeo4J from Nicole White before bed. This had served to stoke the fires of my Big Data / Data Science jones and had moved graph databases from the corner of NoSQL that I just didn't get to something I had the concepts for but needed to play with to understand.

On the other hand, I wrote this on a day where a tech in my lab was upgrading an instrument machine (a computer that controls a data-generating scientific instrument), and in the process, upgraded Java. This lead to that corner of the lab to enter a time of complete shutdown while nothing worked.

I told someone that day, saying "one of my users updated Java", and without any further explanation, he knew exactly what the problem was, exactly how bad it could be. "They didn't", he said.

This is not a case of me hating Java as a language. I mean, I do, but nobody is asking me to write it, at least not in this context. With Neo4J, I there are modules such as RNeo4J, serving as an interface between the database and the language you're doing your work in. I don't care what language MySQL or MongoDB are written in; I just care that they'll store my data and give it back when I need it.

The one thing that distinguishes Java is "write once, run anywhere"; you write it and compile it so it runs in a VM, abstracting away all connections to underlying systems. Except, there are systems created years ago, where the software was written for a version of the JVM that has been replaced and abandoned a long time ago, where they even deploy computers running XP that were built for Windows Vista or even Windows 7. These exist to some extent because for schools of engineering and computer science, you have to teach the basics of computing using something, and somewhere along the line, the go-to something for introductory courses became Java. So, if you're making complex, computer-controlled scientific instruments, you're needing to design for what students know, rather than spend time and money teaching them a new language as well as the interface to your science. And, because once you sell it, you don't get money for upgrading the interface, so you just don't.

That is my biggest fear. That running a big program to run a big program will tend to choke a computer is an issue, but not as big an issue in this case. It'd run on an older computer, but it's a far newer computer than I started to develop my Java hate on, decades ago. I mostly think that, in context of modern, well-backed projects like Neo4J and Cassandra, I wouldn't end up where I can't upgrade the JVM because it'll break my tools and but every time I use the mouse, a popup shows up saying I'm several major versions behind, and I couldn't download and store the "right" version for my software if I wanted to.

Those are the two Javas: The bright shiny one that promises a good future, and the previous version that keeps you stuck in the past.

2015/05/13

Being Open, Being Wrong, Being Corrected, Being Smarter: Response about MongoDB

Just heard a podcast from Developer Tea where Ben Lesh of Netflix explain how he likes it when he makes mistakes, because then he learns, and we should always be learning. (I listened to it when driving, so I didn't write down the quote, and I'm not sure if it's in part 1 or part 2 of the interview.)

Yesterday, I posted on issues I had with MongoDB and Perl. I had done what I had wanted before, I was sure, but my code no longer reflected it, and Shub-Internet was not responding with the answers I desired. If you don't recall:

# This worked to get one value:
my $find_one = $collection->find_one( { date => $today }) ;

# but if I wanted the whole thing, this didn't work:
my $find = $collection->find ;

As it turns out, there's a specific piece of information I did not find, but David Golden of MongoDB set me straight.

# but if I wanted the whole thing, this didn't work:
my $find = $collection->find ;
my @all = $find->all ;
# and in the case I'd want:
my %all =
    map { $_->{ date } => $_ } #map, grep and sort are all-powerful
    $find->all ;
say Dumper \%all ;

This is great. Wonderful, even. I had a failure in understanding, I was open about it, I was corrected, and now I am a better programmer for it.

I do sorta wish I had given Stack Overflow a deeper search first, though....

2015/05/12

Having an issue with MongoDB and Perl

I've learned to love SQL. At first I had lots of functions that did SELECT * FROM table, then I would put everything together at the last moment, with big slow programs. Slowly but surely, I found myself trusting my tools more and more, writing more and more complex SQL queries to give me exactly what I needed, in as close to the right form as I could.

Now that I have some level of expertise with SQL, we have it as a core of our infrastructure at work, so any experimenting with NoSQL databases. It's mostly for my toy bits and administrivia, not really holding any real data, but I am keeping my current FitBit step count in it.

I am currently finding that I can find_one() all I want, but I can't find(). I am sure I used to. I'm also sure that I'm doing something stupid, not the MongoDB Perl module, but I can't tell what I'm doing wrong.

Help?


2015/05/04

Putting Current Temperature into my Bash Prompt

my life as drawn by phdcomics.com
I work in a sub-basement. I've been lead to understand that this is desirable for us because the lab equipment is on the solid cement of the foundation, so that we don't have to worry about footsteps shaking it, but I honestly don't know.

The problem at least for me, is that it I'm well-isolated from the outside world, so that it could just as easily 9° or 90° outside, and I wouldn't know. I've felt apprehension to wander upstairs, only to find that, once I got there, it wasn't all that bad.

With a previous printer, I would write the current conditions to the front-panel LCD, because Perl, but we've moved from HP to Xerox, and I no longer have that ability. I now have it tell the time and temp at the top and bottom of the hour, to keep from being so deep in the zone that I think it's lunchtime when it's really quittin' time. I also had code to generate notify balloons, but a recent switch from Ubuntu to Debian made that unusable.

I've been playing with NoSQL databases and have found that I spend most of my time with MongoDB, but once I started thinking about the weather problem — I need it to be available to any of my n terminals, I don't need structure — I decided that Redis was the way to go.

Each NoSQL database works in a different way. MongoDB works as a Document Store, holding a piece of structured data until you call it back. I have code to record daily status updates and send it to bosses where each day holds an array full of objects holding a timestamp and status report, and at 6pm, if the day's array holds data, it formats that data and sends the mail. This is more structure than I really need in this context.

What I really need is essentially a hash table that I can access from many different programs. If it falls down, that's fine; I don't need to remember what the temperature was at 4am, I just need to know what it is now, or within the last 10 minutes. Redis works like that, and (unless you have it commit to disc), it's only in memory, so fast. (I think; I've only played with Redis, not put production data into it.) I think this feature would be good in, for example, Raspberry Pi uses, where excessive access could prematurely kill your SD card.

Anyway, here's my code to store the temperature, to pull it back out, and a replacement $PS1 to show you how to add it to your prompt. It backends to forecast.io, my most recent go-to for weather information. The API is very useful and easy to use. (I don't put "Powered by Forecast" in my prompt but I do put it in the program that uses notify-osd and Pushover.) Use it in good weather.

2015/05/01

Explaining the Schwartzian Transform

#!/usr/bin/env perl

# what is a schwartzian transform?

# http://en.wikipedia.org/wiki/Schwartzian_transform

use feature qw{ say } ; 

# notice how all of these are not in any order?

my @tedx_feeds = qw{
    tedx
    tedxboston
    tedxindianapolis
    tedxiu
    tedxpurdueu
    tedxlafayette
    tedxohiostateu
    tedxpsu
    tedxuiowa
    } ;

# we'll read this backwards. 
my @sorted = 
    map { $_->[0] } 
    # ... and then we just use the words, jettisoning
    # the lengths and creating the final array.

    sort { $a->[1] <=> $b->[1] }
    # ... which we sort numerically by the length
    
    map { [ $_ , length $_ ] } 
    # ... becomes an array of arrays, being all
    # the words and their lengths, starting 
    # with [ 'tedx' , 4 ] ...

    @tedx_feeds ; # the array in unsorted order ...

# Start here and go up <-----------------<<<<<

say join "\n" , @sorted ;

# output looks like:
# tedx
# tedxiu
# tedxpsu
# tedxuiowa
# tedxboston
# tedxpurdueu
# tedxlafayette
# tedxohiostateu
# tedxindianapolis

It took me quite a long time to get the Transform, and the use of map and grep. But they aren't hard. Once you get them, you'll use them everywhere. Maybe too much....