Sunday, July 22, 2012
Desktop Deleted in Ubuntu 12.04
While trying to save files to ~/Desktop yesterday, I had the misfortune of saving a file as ~/Desktop. I wasn't actually aware at the time, and went about my usual business for several days. Then I restarted my computer and my desktop was loaded up with all the documents and directories located in my home directory. In addition to the items I expected to see in my home directory was a PDF named Desktop.
Deleting this file and restarting one's computer is not enough to fix this problem. The fix:
1. Open up ~/.config/user-dirs.dirs
2. Modify the line XDG_DESKTOP_DIR to say XDG_DESKTOP_DIR="$HOME/Desktop"
3. Save and close that file.
4. Open up a terminal
5. `killall nautilus`
Voila! Far easier than I anticipated.
Note that if you're one of those people who stores non-temporary files in ~/Desktop, you will not recover those files using this method.
Monday, July 2, 2012
Why I've Grown To Love C#
I admit, I'm somewhat of a Linux programming snob. Why? Mostly ease, somewhat because it was how I was taught in school, and partially because I love the idea of FOSS.
But times change quickly, and I was thrown onto a C# project with a bunch of folks who were quite used to a Windows environment. Despite the obvious hassle of having to use Windows and deal with Visual Studio, .NET has some pretty cool things to offer.
Take the example where I have a class of students; my goal is to find their averages and get the student with the highest grade so I can single them out to the rest of the class. Let's first do this in vanilla C++:
That's a mouthful. Not including intialization code, there are 7 lines of "useful" code, 5 auxiliary variables, 1 division, and a bit of array indexing. Let's perform a literal translation to C#:
Pretty much the same code. We are utilizing the foreach operator, which lets us get away without any array indexing. Still 7 lines of "useful" code, still 3 auxiliary variables. Assuming the Tests property in the Student class is a array of ints, we can find the average in a much more succinct fashion:
The same functionality in a single contiguous line of code! Not to mention these Average, ForEach, and Max functions can be better optimized by our compiler than what we had before. But is that as far down as we can squish it? What if we dropped the entire ForEach statement and just compared the averages:
And that's why I've grown attached to C#. LINQ is probably my favorite thing to ever come out of Microsoft
But times change quickly, and I was thrown onto a C# project with a bunch of folks who were quite used to a Windows environment. Despite the obvious hassle of having to use Windows and deal with Visual Studio, .NET has some pretty cool things to offer.
Take the example where I have a class of students; my goal is to find their averages and get the student with the highest grade so I can single them out to the rest of the class. Let's first do this in vanilla C++:
Vector<Student> Students; // contains a short int array of test scores called Tests
...
short highestGrade = -1;
Student teachersPet;
for (int i=0; i<Students.Size(); i++)
{
unsigned int sum = 0;
for (int j=0; j<Students[i].Tests.Size(); j++)
{
sum += Students[i].Tests[j];
}
sum /= Students[i].Tests.Size();
if (sum > highestGrade)
{
highestGrade = sum;
teachersPet = Students[i];
}
}
That's a mouthful. Not including intialization code, there are 7 lines of "useful" code, 5 auxiliary variables, 1 division, and a bit of array indexing. Let's perform a literal translation to C#:
List<Student> Students;
...
Student teachersPet;
short highestGrade = -1;
foreach (student in Students)
{
int avg = 0;
foreach (score in student.Tests)
{
avg += score;
}
avg /= student.Tests.Count();
if (avg > highestGrade)
{
highestGrade = avg;
teachersPet = student;
}
}
</code></pre>
Pretty much the same code. We are utilizing the foreach operator, which lets us get away without any array indexing. Still 7 lines of "useful" code, still 3 auxiliary variables. Assuming the Tests property in the Student class is a array of ints, we can find the average in a much more succinct fashion:
foreach (student in Students)
{
if (student.Tests.Average() > highestGrade)
{
teachersPet = student;
highestGrade = student.Tests.Average();
}
}
Four lines of functional code, two auxiliary variables. Why stop there? Using a LINQ-based approach and adding an Average property to the Student class, we can get rid of all auxiliary variables and find the max using the average in one line of code:var teachersPet = Students.ForEach(x => x.Average = x.Tests.Average()).MaxBy(x => x.Average);
The same functionality in a single contiguous line of code! Not to mention these Average, ForEach, and Max functions can be better optimized by our compiler than what we had before. But is that as far down as we can squish it? What if we dropped the entire ForEach statement and just compared the averages:
var teachersPet = Students.MaxBy(x => x.Tests.Average());
And that's why I've grown attached to C#. LINQ is probably my favorite thing to ever come out of Microsoft
Friday, June 15, 2012
What's with Who Moved My Cheese?
Who Moved My Cheese?
Johnson, Spencer
Who Moved My Cheese? was a "required" book to read for new employees at my current company. Although the story is very short, the message is very straightforward: Don't get stuck in a rut. That's it. It took about 40 minutes to read through it.
I must admit I wasn't a fan of this book. It seems to have been written for a career path where getting into a rut was easy and relatively safe, but the world of software development is certainly not like that. Now that it's 2012, fewer and fewer people are still programming in COBOL, FORTRAN, BASIC, or even C for that matter. We are frequently given opportunities to learn new technologies that are more powerful and make our lives easier.
Having graduated from university recently, the message was somewhat lost on me. As students take different college courses every semester, they are frequently thrown for a loop and forced to "find cheese" for each new class in its own way.
Don't get me wrong. I don't think Cheese? is completely useless. I think a great demographic for this book would be the recently laid-off employee who may need some motivation to get back out in the work force. However, I don't think this book is a must-read for everyone. In particular, there was a line included in my version of the book which said that anyone who disregards the story is a know-it-all. I take offense to that statement; it has yet to be proven whether or not I actually "know it all."
If your coworkers have all read this book, read it because it only takes about an hour to read and no one wants to feel left out. If you need some motivation to get out of a rut, you don't need to read a book to tell you to get off your rump and do something about it; just do it.
Tuesday, June 5, 2012
Link: Researcher reveals how “Computer Geeks” replaced “Computer Girls”
Below is a link to an interesting article on what are called the first programmers (link courtesy r/programming). Unfortunately, women were booted out of the programming sector once the world realized how complex the job was. Now, 50 years later, we no longer tell women they can't be intellectuals and yet software development is still a male-dominated career path. Maybe the "Computer Girls" will make a comeback. Maybe Cosmo will have articles about software aimed at visionary young women. Just imagine the right answers to the sex quizzes leading you away from the brawny athlete and instead to the programming dreamboat!
Researcher reveals how “Computer Geeks” replaced “Computer Girls”
Researcher reveals how “Computer Geeks” replaced “Computer Girls”
Friday, June 1, 2012
Having Read The Passionate Programmer
The Passionate Programmer (2nd edition): Creating a Remarkable Career in Software Development |
|
| Chad Fowler |
The Passionate Programmer is essentially a book about self-motivation. It is neatly wrapped up into several sections about marketability and rekindling the passion for software development, and these sections are broken up into delightfully bite-sized chapters which make the book a breeze to go through.
This book preaches that we should be happy with our jobs but not complacent. The author, Chad Fowler, believes that, at all times, we should be looking for ways to better ourselves as professionals and as individuals. This is certainly a tall task. I've been having trouble finding time to do very many extracurricular activities lately, what with moving to a new city, starting my career, buying a car, and planning a wedding, but what this book really makes me want to do is search the internet for some new software technology I don't understand and learn everything I can about it. It's all about branching out from the norm and doing things one may be uncomfortable doing. I'm fortunate to have started a job at a company where I have the opportunity to frequently switch projects and do things that are completely different fairly regularly.
I also see it as a good thing that I was thrown into technologies I'd never had to deal with before during my first day on the job (Windows programming, .NET, WPF, TestStand, CruiseControl...). All jobs should be like this. Companies hiring people for their potential to do anything instead of their potential to do a specific task.
Fowler also mentions being social as an important step in a passionate career. Managers, programmers from other companies, managers of managers, developers at conferences, managers of managers of managers, and even folks in online forums or blogs may be the link to an opportunity. I normally just live under the thought chain of "If I write it, it's good, and I'm efficient, I'll get noticed." But Fowler insists this is not true! Talking to these kinds of people and letting them know what you've been up to is beneficial in that it gives managers a sense of how the project's going, it may give other developers ideas or inspiration to solve problems, and it can help you feel more accomplished. It's a good mindset to be in, and it simply involves climbing out of the cubicle every once in a while and finding the right people to talk to.
This book provides good motivation to continue pushing oneself and it provides inspiration for how to better manage one's non-working life.
Wednesday, May 16, 2012
Programming for FTIR - A Starting Point
I recently finished a large project which involved creating a sizable touch surface. The results surprised a lot of people, and what we accomplished was no small feat.
It's no Microsoft Surface, but it cost us less than $800 to build and we ended up with a lot of spare parts. All the applications shown were written by me or my teammates in this project.
I utilized a lot of amazing open-source software to get to this end, including Ubuntu, reacTIVision, and TUIO. When I first started researching the technology I'd be using, I had no idea what I was getting myself into. It all started with this article by Maximum PC.
All applications were written in C++ using the SDL and TUIO libraries. For SDL, I started by following the tutorials found here and expanded to fit my needs. The reacTIVision software was used to track touches from a modified Playstation Eye and send them to TUIO.
To get all these tools working on your machine may not be easy. For my build, I started with a fresh install of 32-bit Ubuntu 10.04.2. I used this version for its stability and the Linux kernel was still within version 2.6.x which has a patch available to allow the Playstation Eye to run at maximum speed. The steps to patch the Linux kernel for optimal use of the Eye are detailed on many websites, but the one I followed (several times for several fresh installs) was found in a blog post of Multitouch Dev.
Many people use touch-tracking software called CCV on their hobbyist FTIR projects. CCV (also known as tBeta) is an open-source touch-tracking program. The UI was slick, but this application did not fit my computational needs. I was running on an Intel Atom board, and CCV used up 100% of one of my hyperthreaded cores no matter what I tried to do, forcing me to search for alternatives.
This was when I found reacTIVision. reacTIVision was a more mature IR touch-tracking software that achieved very similar goals to CCV. The best part about reacTIVision was that it used much less of my CPU: somewhere around 20-30% as opposed to 100%. With this software, I was able to run my modified Playstation Eye at 60 FPS with a 640x480 resolution. Fortunately for Ubuntu users, a .deb package is available for easy installation of reacTIVision.
The SDL packages can be found in the Synaptic Package Manager. Additionally, I used SDL_image to load .png images and SDL_mixer to load sounds into my applications. One should also have the build-essential packages installed on their machine for programming.
Finally comes interpreting of the tracked data from the reacTIVision software. For this, I used libTUIO. TUIO is a wonderful library with client implementations in many modern languages, including C++, Java, C#, and Flash. You can download these libraries from the TUIO website. For my purposes, I used the C++ libraries. Once downloaded, I performed a make on these files and got some build errors. These build errors tend to occur for some of the sample applications included with the library. Luckily, the library itself was already built, and so I moved the .so, .a, and header files to appropriate locations in my filesystem.
From there, one can start making their own touch programs and use the TUIO simulator to perform testing. To actually get touches to work, you should follow the MaximumPC article's section on setting up the LED array. We packed the LEDs in about 3/4" apart on all sides of our 34"x26" screen and were able to get relatively accurate touches. Be warned that the bigger the screen, the less accurate the touches tend to be. Due to our projector size, we also had to use an angled mirror to get the image size we desired, which caused some slight distortion in our display.
In the future, I'd like to go over actually writing a C++ touch application using TUIO.
Subscribe to:
Posts (Atom)