## Better Old Programs

May 14, 2011

Long story short, well more like short story even shorter, I got a new laptop and reinstalled Ubuntu 10.04 on my external hard drive.
Don’t worry I had a separate home partition so most of my important files were saved. However, I still have to get back some programs and libraries that I liked using. So this post is going to document what I did to get them each back. Mainly this is for my own personal use since I know that I will most likely have to solve this problem again at some point in the future.

## Mozilla Firefox

Now there is nothing wrong with the version that Ubuntu supplies, that is until a new version of Firefox is released. So all you really need to do is to your repository with the following commands:
 sudo add-apt-repository ppa:mozillateam/firefox-stable sudo apt-get update && sudo apt-get upgrade 

## Amarok 1.4

This is just a personal thing. I’m sure that the new Amarok is a wonderful program, I am just more familiar with the old version. That being said, getting this to work is a little more complicated that ‘fixing’ Firefox.
 sudo gedit /etc/apt/source.list 
Well you can actually use whatever text editor you want, I just put gedit since it will most likely be what most people (non-linux users) are used to.
Then add the following lines to the file (I added them to the bottom but don’t see why you can’t add them anywhere else)

 deb http://ppa.launchpad.net/bogdanb/ppa/ubuntu jaunty main deb-src http://ppa.launchpad.net/bogdanb/ppa/ubuntu jaunty main 

If you have any other version of Amarok installed you will need to remove it.
 sudo apt-get remove amarok* && sudo apt-get autoclean 
Now you can install what you want
 sudo apt-get install amarok14 

Hopefully there were no errors. If you got something about a mysqlclient15 file then go to this site, download the file, then run the last command again.
http://packages.ubuntu.com/hardy/i386/libmysqlclient15off/download

## Getting a Boost

March 11, 2011

Most of you that use C++ (and some of you that don’t) are sure to have heard of Boost C++. I won’t go into what it is, since if you want to know that just follow the previous link. I will however talk about the “installation” process. This is mainly for me, in case I ever feel like putting it on another computer, but I suppose some people might find this useful.

## Step 1

Download Boost, I would recommend the latest version but it’s your call. You can find download links by going to the Boost website and doing a little “read-n-search”, aka using your brain. I will assume that you have downloaded the file (let’s call it FILE, and assume it is has extension bz2) to your desktop. Open a terminal and move to where you would like the Boost files/libraries/binaries to be located, call this $BOOST. In short you just run the following in the terminal:  cd$BOOST tar --bzip2 -xf ~/Desktop/FILE 

## Step 2

At this point you are more or less done and are able to use quite a few of the provided libraries. However, there are some libraries that need to be built. So let’s go ahead and build them all, since you never know when you’ll need one, and you aren’t that strapped for space on your system.

## Step 4

Hopefully, you have made it this far without any errors. So it is time to test that everything actually works.

//ASSUME THIS FILE IS CALLED test.cpp
#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}


Use the following to compile
 g++ -o test test.cpp -I $BOOST/boost_1_46_0 -L$OTHER_PATH -lboost_regex ./test 

If there are any mistakes or if you have any suggestions let me know. I know this isn’t the best walk through but I think it’s better (for beginners) than the one presented at the Boost website.

## Learning CaCO3

December 1, 2010

In case you are wondering, and are too lazy to head over to Google, CaCO3 is the chemical formula for a pearl. With that tidbit of information in hand it shouldn’t be too hard to guess that in this post I am going to tell you that I have decided to start learning Perl.

This all started a few days before (American) Thanksgiving when I was a little bored and didn’t feel like doing course work. Originally the plan was to learn Python, but somehow I ended up reading stuff about Perl and was hooked. There are quite a few online tutorials out there to help you get started, some better than other in my opinion. For me the problem was finding one that was targeted at my level and could keep my interest. Sure I didn’t know how to program in Perl but I knew C++ and some Java and after seeing a few examples of Perl realized that the syntax wasn’t all that different. So the tutorials that held your hand while explaining what a variable was got boring rather quickly.

In the ended I chose to follow one that skipped all the “baby stuff” and just said, “Suppose you had problem X to solve. This is one way you could attack it.” Then it would provide some lines of code explain what a few key words meant and leave you to figure out why and how it worked. The only time the tutorial didn’t stick to this format was when they introduced regular expressions. The first paragraph for that section explained what a regular expression was and did a little hand holding. But after that it was back to “figure it out yourself from example code” business as usual.

The one thing that was beat into me was that there is always more than 1 way to do something. Also whenever in doubt of if something is possible I remember this quote “Can I do that? OF COURSE, THIS IS PERL!”

Well off to learn more Perl and write more scripts.

## Smart Phone Data

November 21, 2010

At this point I am sure that you have heard about cell phone companies trying to limit data use (at least in the US).  Sure I’m not a huge fan of this move but I understand why the change is underway. Some providers (like T-Mobile) still offer unlimited plans.  However, to limit use even for these user T-Mobile supposedly reduces transfer rates once you exceed 5GB of data use.  This shouldn’t bother too many people since getting close to that limit is very hard.

When I read that last bit of info about T-Mobile it got me to thinking, why not charge for speed and not amount? The strain on the networks is coming from the large bandwidth demand which is slightly related to the amount of data a person uses.  If instead of partitioning individuals based on amount of data used, instead do so based on how much they are willing to pay for speed.  Cable and DSL providers have been doing this and it seems to be working just fine.  Furthermore, with capped speeds you in some ways have also set a theoretical limit on data usage. Plus I don’t think you’ll lose money if you use a reasonable pricing model. Most of the high data users will want the faster/fastest speeds, as it will be the only way they can continue  doing what they have been doing.  The real bonus is that some more moderate users will be willing to pay for higher speeds resulting in a gain for the company.  This won’t put anymore strain on a network since as things are, everyone is getting “premium” speed.  So why not cut some “dead weight”?

This post was typed on my Nexus One so please excuse any spelling errors. I have tried my best to eliminate as many as possibe.

## Inclusion Exclusion

August 22, 2010

I am sure that most of you have heard of the inclusion exclusion principle.  If not then I suggest that you either head over to Google or Wikipedia.  It is a really useful technique with many applications; even to this day I am still discovering new ways in which it can be used.

In this post I will outline a partial solution to the following problem located on SPOJ, PGCD.

The first thing you should notice is that the answer to (a,b) will be the same as the solution to (b,a).  This is because of the symmetry of the $gcd(\cdot,\cdot)$ operation, thus suppose that $a\le b$.

Suppose that there are $a$ columns in our gcd table.  We will find how many primes there are in each column.  Suppose that there are $m$ rows, and we are looking at column $n=p_1p_2\cdots p_r$, where $p_1,p_2,\cdots,p_r$ are distinct primes.  I’m not going to consider the case where a prime factor is repeated, though I have a feeling that the solution below should still work.

First we find how many multiples there are of each prime between $1\ \mbox{and}\ m$.  This is just

$\displaystyle\sum_{i=1}^r\left\lfloor\frac{n}{p_i}\right\rfloor$

But what about the multiples of say, $p_1p_2$?  Well they were counted twice, and their entry in the table is not going to be a prime (you can easily convince yourself of this fact).  So we just subtract them out twice, leaving our answer as

$\displaystyle\sum_{i=1}^r\left\lfloor\frac{n}{p_i}\right\rfloor-\sum_{1\le i

Now what about the divisors of $n$ with exactly 3 prime factors?  Their multiples have been removed too many times, thus we need to add them back.  If we continue this way we see that we will be using inclusion exclusion.

So to solve this we can use the following code.


#include bitset
#include vector

int answer=0;
bitset PIE;
for(int i=2 to n;++i)
{
vector prime_factors=factor(i);
int r=prime_factors.size();
for(int cnt=1 to 2^r - 1;++cnt)
{
PIE=cnt;//express cnt in base 2 and store in PIE
int ones=PIE.count();//the number of 1s in our bit string
int p=1;
for(int j=0 to prime_factors.size() -1;++j)
if(PIE[j])
p*=prime_factors[j];
if(ones&1)//there are an odd number of 1s
answer+=(ones*(m/p));
else//there are an even number of 1s
answer-=(ones*(m/p));
}
}

This isn’t totally legal code because I had to paste it into HTML so the less than and greater than signs disappear and I don’t want to waste the time to fix it (even though I know how to).
For those of you that don’t know the bitset is just a string of 1s and 0s. When I did PIE=cnt I basically set it so that the bit string was equal to the base 2 representation of cnt. Using this method we can get all possible combinations of the prime factors.
The code can easily be converted to Java since I think it too has something similar to a bitset. If your language of choice doesn’t have a bit set, no need to worry. You can just get the base 2 representation on your own (it’s not that hard, trust me).
WARNING: This approach will only be feasible if each number doesn’t have too many prime factors. Not the case with the problem on SPOJ since each number can be decomposed into the product of at most 23 primes, and at most 9 distinct primes. So I’m not sure if the time limit will allow you use this method, I haven’t tried, but please let me know if you do.

## Included Files

August 22, 2010

Do you ever wonder where the files you include in your C/C++ programs are located, and how the linker finds them?  Well on a Linux system (unless you have changed things) they are located at /usr/include and /usr/include/c++.  If you go you can see the list of files you can #include in your program.  Additionally, you can view the source code, if you are the kind of person (and I have a feeling that you are) that finds these things interesting.

## Thoughts on my Nexus One

August 4, 2010

Well I’m not the first person to buy a Nexus One in America, but I’m one of the last to do so.  As a responsible consumer it is my duty to share my experiences with you readers.  I’ve had the phone for a little more than a week and thus think I know how I will be using it for the most part. Before I start I would like to mention that the biggest problem I have with the phone is my phone number.  This has nothing to do with Google/HTC, but rather T-mobile, so this little issue won’t be making it into the review.

At first I thought about just having this review be another pros/cons list.  But when I started there were many things that fell into both categories.  So I realized it would be easier, and a little more organized if I just commented on each aspect one at a time.

OPERATING SYSTEM: This is a big plus.  The Nexus One is the only phone currently on the market running a legitimate version of Android 2.2.  Although the phone ships with version 2.1 it starts to download the update soon after activation.  There is a noticeable speed difference between the two versions.  Also the ability to use the phone as a wireless hot-spot is wonderful (in my case it doesn’t cost me any extra for this feature).  The added flash support doesn’t hurt either.  For more information about the update just look on any tech website/blog, or even do a quick search for ‘Android 2.2’.

USER INTERFACE: The screen is usually quick to react to all of touch commands.  When this isn’t the case, it is almost always do to an application freezing, something the phone can’t take all the blame for (I’m looking at you app developer).  The phone comes with 5 screens for you to place icons, for me this is a bit much since I only really use 4.  For those of you that are used to using the HTC Sense UI that comes with 7 screens (or so I have read) this might feel like a downgrade.  Another thing that matters is screen brightness.  You are able to choose between 3 screen brightness levels.  Obviously the brighter the screen the more strain you will be putting on the battery.  I find that the dimmest level is more than good enough when you are inside and the second level (out of 3) is fine when you are in obstructed sunlight.  I don’t know how well the screen manages when you are in direct sunlight but my guess is that even on the brightest setting you will still need to cup your hands over the phone if you want to see more than just large icons (you know…things like text).

KEYBOARD: You should know that I would have preferred the Nexus One to have had a physical keyboard as an option instead of only the on-screen keyboard that is provided.  Since there isn’t much I can do about this (though I think there might be ways to connect to an external keyboard, probably through bluetooth is my guess) I have gotten used to the set up.  If you ever need to type something that is longer than 2 words I suggest that you use the keyboard in landscape mode.  Otherwise your thumbs will accidentally hit wrong keys and increase the number of typos.  The only problem with typing in the landscape mode is that the keyboard takes up most of the screen.  Thus if you need to enter text into more than one area you will have to close the keyboard after each entry.  When using the portrait version you don’t have this problem, but as mentioned before you are more typo prone.

SOFT KEYS and TRACKBALL: I refer to the four keys located right above the track ball as the soft keys.  The trackball is quite useful when the area you need to click is too small for you to accurately do so by touch.  I would prefer that instead of a physical ball it was laser operated, similar to the Droid Incredible.  However, both versions do have their downfalls.  If something goes wrong with the laster/hardware or you damage the physical trackball then you are just SOL in both cases.  As for the soft keys they work well most of the time.  The only time I have a problem is when the phone is parallel to the ground.  When this happens you have to press a button repeatedly for it to perform is designated action.  Sometimes even that isn’t enough if you aren’t pushing the button in the right place (near the top close to the screen edge).  Some other reviews claim that the back button is confusing, but I find it rather intuitive; it will always take you to the previously viewed screen, so this isn’t a problem unless you have horrible short term memory.

BATTERY: Depending on use I can get anywhere between half a day and two days from a full battery.  Removing the batter is rather simple…once you are able to remove the back of the phone, which isn’t quite as simple.

OVERALL: I’ll keep this short, 4/5.  The reason for a 4 and not anything higher is because of the keyboard, screen in the sun, and  the fact that there are more “advanced” phones out there.  Though the Nexus One is “old”, it is by no means irrelevant.  It is still the phone that the Google developers use to do testing (I’m sure it’s not the only phone but it is certainly one they make sure their product works on.  Which is part of the reason this is the only phone running Android 2.2).

## The Android SDK and Development Tools

July 17, 2010

FINALLY!  It only took about 2-3 days for me to get this thing working.  This post is going to outline what I did.  The reason being that I might have to go through this process again sometime in the future and also finding help online was not that easy.

STEP 1: Get the right version of Eclipse. At the time of this post Eclipse 3.6 is out, well you don’t want this version since Google has said that there are problems with this version and their SDK. Instead you want to get Eclipse 3.5.2, just to the download page and select to see older versions of Eclipse, then fine 3.5.2 and download. Depending on your connection this shouldn’t take too long.

STEP 2: Install Eclipse. For this step just see my previous post, all the steps are exactly the same even though you are installing Eclipse 3.5.2 and not Eclipse 3.6.

STEP 3: Download the Android SDK. Just enter Android SDK into Google and the page you want should be the first link. Download the Linux version (I assume you are using Linux, though Mac users might also be able to find some help in this post). It’s a pretty “small” file so it shouldn’t take that long to download. Unpack the file with tar -xzf <filename>. Then save the extracted directory somewhere, we shall refer to this location as SDK_HOME.

STEP 4: Install the SDK. First you will want to add SDK_HOME/tools to you PATH. To do this just open up a terminal and enter, PATH=$PATH:SDK_HOME/tools. Remember that SDK_HOME is the full path of where you saved the extracted directory. Now while you are still in the terminal run; cd SDK_HOME/tools ./android This will open up and SDK manager UI. Select available Software (or something along those lines) and then select everything in the right column. You don’t need to select everything but it doesn’t hurt, since I’m not sure exactly what you need since I didn’t read all the options. Once you have done this click install and then wait a while for everything to be downloaded and installed. At the end of this process you will get a window prompting you to restart the manager, please do so. STEP 5: Open Eclipse. This step might not be necessary for some people but it was for me and I figure that it will be for others. So as to avoid any potential future problem please do as instructed. Go to Help > Install New Software…, then click the Add button to the right of the drop down menu. In the box that appears enter Galileo Software Repository as the name and http://download.eclipse.org/releases/galileo/ as the location, and then hit OK. Then in the filter box (the text box below the drop down menu) enter “server”. You should see an item called “WST Server Adapters…“, select this item (or everything in the same group if you want) and then press next. Agree to the license and then hit finish. If at any point you are asked if you trust the source of the software say yes (or whatever the appropriate option is). STEP 6: Integrate the Android SDK into Eclipse. Once again go to Help > Install New Software…, and click the Add button as before. This time in the name field enter Android Development Plugin (or any appropriate name), and in the location enter https://dl-ssl.google.com/android/eclipse or http://dl-ssl.google.com/android/eclipse. Now select everything and click next. Agree to the license and say that you trust the software source if asked at any point. STEP 7: Tell Eclipse where to find the Android SDK. Go to Window > Preferences. In the left column select Android, if you don’t see Android then a previous step did not work as intended and I’m not sure how to help you (I suggest removing everything relating to Android and Eclipse from you system and starting over). Now select the text box for the location of the SDK, enter SDK_HOME (hopefully you remember where it is). STEP 8: Create an Android emulator. Go to Window > Android SDK and AVD Manager. On the right select New and enter a desired name for your emulator and size for the virtual SD card. If everything went as planned you should now be able to start development. For tutorials just search Google or the Android SDK site. The following site was pretty helpful when I encountered problems installing the Android Development Plugin. Additionally, this YouTube video is pretty useful and documents all the steps, other than the method you should use to install Eclipse. ## Eclipse July 16, 2010 I’m sure that you have heard of Eclise. If not then all you need to know is that it is a very popular (and for a good reason) IDE mainly for Java. However, it does also have C/C++ support, but it is mostly used with Java. As you know, I’m not big on programming in Java. But I recently purchased a Nexus One phone, and the IEEE SECon got me a little interested in Android application development. I don’t plan for anything I make to be widely distributed, but rather just for personal use. In any case, I would still need a place to create my programs. Sure this can be done with a normal text editor and the command line but why bother with that when Eclipse and the Android SDK make it so simple? I’m going to talk about getting and installing Eclipse onto you system (which I will assume to be Ubuntu). Sure you could just run sudo apt-get install eclipse but this way assumes that you are using the OpenJDK version of Java and not Sun’s. So if you are using SunJava, which it seems most people do, then this how-to is for you. First head over to the Eclipse site and download the IDE. To find the site just use Google and then do some reading and clicking, so there is no need for me to post a link. If you can’t get past this step then you probably shouldn’t be thinking about using Eclipse. Next we will open the package you have just downloaded and then move it to the /opt directory. To do this just run the following sequence of commands:  tar xzf <filename> sudo mv eclipse /opt/eclipse cd /opt sudo chown -R root:root eclipse sudo chmod -R +r eclipse sudo chmod +x sudo find eclipse -type d The chown command changes the owner of a file/directory, if you have been reading this blog then you should be able to figure out what the other commands do. Next we will add eclipse executable to your path.  sudo touch /usr/bin/eclipse sudo chmod 755 /usr/bin/eclipse sudoedit /usr/bin/eclipse  then add this to the file  #!/bin/sh #export MOZILLA_FIVE_HOME="/usr/lib/mozilla/" export ECLIPSE_HOME="/opt/eclipse" $ECLIPSE_HOME/eclipse \$*

I’m not all to sure exactly what the touch command does but you can look that up yourself (either online or with man).

Finally, the “most important” part; creating a GNOME-menu icon. This is something that would normally be done when you use the apt-get method.

 cd /usr/share/applications sudo nano eclipse.desktop

And enter the following into the created file;
 [Desktop Entry] Encoding=UTF-8 Name=Eclipse Comment=Eclipse IDE Exec=eclipse Icon=/opt/eclipse/icon.xpm Terminal=false Type=Application Categories=GNOME;Application;Development; StartupNotify=true

All the stuff entered into the file makes perfect sense, so if you ever wanted to make a menu item for any other program you now know how.

All of these steps can be found at http://flurdy.com/docs/eclipse/install.html.

## More on the Linux File System

May 11, 2010

Some of you might remember when I did a few post on the Linux file system.  If not, or you would just like to reread them just follow these links: part1, part2, and part3.  I’ll admit that I didn’t finish this series as I had originally planned, but it does provide a good place to start learning.  Maybe one day I’ll try and finish/improve upon this series, but I won’t hold your breath.

For those of you that would like to learn more about the file system you can either go to Google or you can run the command man hier from the terminal.  This will provide you with a general overview of each of the partitions for the file system.