Mar 5 10

MySQL - Custom ORDER BY field

by Jason Grimme

Today at work I had to pull a large set of data out of a database. The data needed to be displayed in a particular order by multiple fields/columns.
Normally this is as simple as using ORDER BY column_name ASC, etc.
However I needed to sort by ticket status IDs which were not in numerical order. I needed 10 to be first, followed by 2, and then 6.

Rather than having PHP do the sorting, I found a MySQL function that allows you to sort by a custom order. The function is named FIELD(). The first parameter is the field name, and all subsequent parameters are the order you want to sort by. You may attach ASC or DESC as you would usually to reverse.

Example:

1
2
3
4
5
6
7
SELECT
    *
FROM
    tickets
ORDER BY
    FIELD(tickets.status_id, 10, 2, 6),
    tickets.date_created ASC

You do not have to only use numbers, you can use strings as well.

1
2
3
4
5
6
SELECT
    *
FROM
    tickets
ORDER BY
    FIELD(tickets.day, 'Tues', 'Sat', 'Mon', 'Fri') DESC
Jan 26 10

Peachtree - “No company data location”

by Jason Grimme

One of my favorite programs to administer is Peachtree Accounting. </sarcasm>

Recently while trying to install Peachtree Quantum 2010 on a computer, I had trouble getting it to use a central server containing the data.
When selecting the mapped network drive, I would get an error:

There is not a valid Peachtree Complete Accounting 2010 centralized company data location on that computer. Either install Peacthree on that computer first or select another computer.

Now, this software has already been installed on twenty other machines and I know it works fine.
I tried rebooting, disabling anti-virus, Windows firewall, etc with no luck.
Here is the fix:
Go back to the install and this time when it asks if your local machine will store the data locally, select ‘Yes’.
Go through the rest of the install, but don’t start Peachtree when the install is complete.
Edit the file C:\WINDOWS\ptx170.ini
Look for the line:

1
DATAPATH=C:\Program Files\Sage\blahblahblah

Replace this path with the path to your shared network folder. In my case:

1
DATAPATH=I:\peachw\

Start Peachtree and you should be on your way! I hope this helps some other lucky Peachtree admin.

Jan 26 10

Windows Explorer - New Folder - ‘Shortcut’

by Jason Grimme

One of my most frequent actions in Windows Explorer is creating a new folder.
The most obvious ways to do so are to right click and click ‘New Folder’ or go File -> New -> Folder. Both of these are not complicated, but could be faster.
Why Microsoft couldn’t have made Ctrl+N make a new folder I will never know.

Thanks to an article by HowToGeek, I have started to use a common sense method that is much quicker.

When in Explorer, simply press Alt + F, W, F. You can now create a folder as fast as your fingers can press those four nearby keys. Nothing advanced but I figured I’d share my tip.

Jan 3 10

Search bar plugin for Mozilla Firefox

by Jason Grimme

In most Firefox layouts, there is a search bar in the upper-right corner that allows you to type in a term and use GET to make a search request.
At work we have a ticket system with ticket IDs and I frequently need to go to the home page, enter the ticket ID, and then click a button to view it. I thought it would be nice to change the usage of the search plugin so that I could enter the ticket ID and jump right to it. I had a few experiences I would like to share.

First, the search plugin is a basic XML file that follows Amazon’s OpenSearch standard. The structure is pretty basic.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="UTF-8"?>
<!-- Ver 1.0 jGrimme Dec 16 09-->
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
                      xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Ticket Jumper</ShortName>
<Description>Jump to a Ticket</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,AAABAAEAEBAQAA [ .. Shortened ..] CP//gBj////4////+P/</Image>
<Url type="text/html" method="GET" template="http://www.example.com">
  <Param name="QueryTermName" value="{searchTerms}"/>
  <Param name="AdditionalParameter" value="Additional_Value"/>
</Url>
<SearchForm>http://www.example.com</SearchForm>
</OpenSearchDescription>

You may chose to provide an image file that will be displayed next to the search bar, or you can base64 encode the PNG file so that you can distribute the search plugin in one file (This is the standard).

Save this as an XML file and you have two options. You can either copy it into your Mozilla directory (Windows ~= C:\Program Files\Mozilla Firefox\searchplugins\) or host it so that others may install it.
To do the second option, make a HTML file and place it in a public directory with the XML file.
In the HTML file, have a link that calls a Javascript function as follows:

1
2
3
4
5
6
<script type="text/javascript">
function install()
{
    window.external.AddSearchProvider(SearchPlugin.xml");
}
</script>
1
<a href="#" onclick="install();">Install Search Plugin</a>
Nov 2 09

Using Alpine to Check Your Email/Gmail in Linux Terminal

by Jason Grimme

In further effort to learn how to do things the most complicated way possible on Linux, I wanted to be able to access my Gmail account when using SSH to log onto my computer from anywhere.

First Method: Using Lynx

The first method I thought of to access my Gmail was to use Lynx, a text only web-browser. Using Lynx would allow you to read nearly all web-based email accounts. This method is easy and works great, but it can be frustrating to navigate a web page in Lynx.

Second Method: Perl and cURL

This first and rather simple method uses cURL to grab an Atom XML feed of your Gmail inbox. It then pipes that to Perl to parse and display them in Terminal.

1
2
3
# Author: Dipin Krishna
# Replace username with your gmail username (including @gmail.com)
$ curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if //; print "$2\n" if /&lt;(title|name)&gt;(.*)&lt;\/\1&gt;/;'

Third Method: Alpine Messaging System

Alpine Messaging System is a terminal-based program written by the University of Washington that includes IMAP support. With IMAP, we can browse folders, delete, and compose. This is the best solution for having terminal access to your email.

Note: You will have to enable IMAP support in your Gmail account. Settings -> Forwarding and POP/IMAP -> Enable IMAP.

1
sudo apt-get install Alpine

Start Alpine and you will be presented with the main menu.
To set Alpine up with your Gmail information, press M (Main) -> S (Setup) -> C -> (Config).

Personal Name: (Your name)
User Domain: gmail.com
SMTP Server: smtp.gmail.com:587/tls
Inbox Path: {imap.gmail.com/ssl/user=username@gmail.com}inbox

Now if you navigate back to the main menu and press L (Folder List), you should see a ‘Mail’ folder. Select the ‘Mail’ folder and then the ‘INBOX’ folder, and you will be asked for your password. Once you enter that, you will be able to read your inbox.

This is great until you realize that if you have use Gmail filters to push emails in labels, you can’t see them in the inbox view. To support the labeling system, we must add a collection list.
Go back to the menu and press S (Setup) -> L (Collection List) -> A (Add) and enter the following.

Nickname: Labels ( or whatever you want)
Server: imap.gmail.com/ssl/user=username@gmail.com
Path: (empty)
View: (empty)

Now when you go to your folder list, you will see your new view with all of your labels. You can view each one individually.

One last thing that I did was create another view with ALL of my emails, regardless of the labels. To do this:
Go back to the menu and press S (Setup) -> L (Collection List) -> A (Add) and enter the following.

Nickname: All Emails ( or whatever you want)
Server: imap.gmail.com/ssl/user=username@gmail.com
Path: [Gmail]/
View: (empty)

That is all today on Alpine, but perhaps I will find some more interesting features and share them as well! Please let me know if you do.

Oct 22 09

Backing Up Your Gmail With Gmail Backup

by Jason Grimme

A few years ago I created a Gmail account for my Firefox extension Craigzilla. A few weeks ago, that Gmail account was gone completely, as if it had never existed (and for no apparent reason or notification). I contacted Google, supplied the password and provided additional information, but all I got was an instant “There is nothing we can do” email. This is the first time I have been let down by Google, my favorite company in the world.

This was a problem because I have used my primary Gmail account since two weeks after Gmail was privately released… this account holds my life and I need information from it.  What happens if Google deletes that account?  Boy would I be in trouble.   This led me to find a program to archive a Gmail account on your computer.  Sollution: Gmail Backup.

Gmail Backup Screenshot

Gmail Backup Screenshot

Gmail Backup is a simple and free program where you provide your username, password, and it backs it up for you with relative speed.  It runs on Windows, Linux, and Macs. While I obviously would prefer my account to not be deleted, I wouldn’t feel as terrible.

Oct 21 09

[PHP] Sort Multi-dimensional Array Based On Two Values

by Jason Grimme

Normally when working with data that needs to be sorted, one uses the most efficient way: letting the database do it for you.  I was recently in a situation where that wouldn’t work, yet I still needed to do some complex sorting. Specifically, I needed to sort a 2d array by one key’s value, and then by another key’s value.

The solution was to utilize PHP’s usort function which accepts a callback function.  This callback function is a custom function that returns 0 or 1 depending on how parameter A compares with parameter B.  To sort by two, three, or more, you can include multiple comparison function within your callback function.

Example - Sort an array containing arrays with keys ‘timeCreated’ and ‘age’.

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
28
// Sort by the timeCreated key in ASC order
function sortByTimeCreatedAsc($a, $b)
{
    if ($a['timeCreated'] == $b['timeCreated'])
    {
        return 0;
    }
    return ($a['timeCreated'] < $b['timeCreated']) ? 1 : -1;
}

// Sort by the age key in DESC order
function sortByAgeDesc($a, $b)
{
    if ($a['age']==$b['age'])
    {
        return 0;
    }
    return ($a['age'] > $b['age']) ? 1 : -1;
}

// The function usort calls.  Sorts by time then age.
function sortByTimeThenAge($a, $b) {
    $t = sortByAgeDesc($a, $b);
    return ($comp==0) ? 0 - sortByTimeCreatedAsc($a, $b) : $t;
}

// Sort the cleverly named array multiDimensionalArray
usort($multiDimensionalArray, 'sortByTimeThenAge');

It is important to note that usort takes a pointer to the array you give it and not a value, meaning it modifies the actual array you give it and does not return a new array. Also, if the first level of your array is associative, you can use uasort to preserve your keys.

In case it is not obvious, you can change from ascending to descending and vice-versa by switching the comparison operators around. Also, you can compare strings by using strcmp, a binary string comparison function.

1
return strcmp ($a['State'], $b['State']);

It would be really neat if somebody wrote a class where you could just supply an array and an order field, and it sorted it out no matter how many levels deep you went. Perhaps if I have time some day…

Sep 15 09

Ubuntu: Buffer I/O error

by Jason Grimme

Today I tried to install Ubuntu 9.04 (Jaunty Jackalope) on a rack server at work that did not have a CD drive.  The easiest thing to do was to use an external USB CD drive.  Unfortunately I was getting an error once Ubuntu started loading:

Buffer I/O error on device sr0, logical block xxxxxx
end_request: I/O error on device sr0, sector xxxxxx

A little research into this problem revealed that it’s usually not something wrong with the distribution, but rather something wrong with how the CD was burned, the drive, or the hard drive.  I did a MD5 check on the disk and that was fine, and I knew the disk had already been used before and was burned at a low speed (Always crucial when writing an ISO)

I also tried adding some parameters to the boot option (Which didn’t work, but I’d give it a try, and get rid of the ‘quite’ flag):

  • irqpoll
  • noapic
  • nolapic

Finally, I pulled a SATA DVD drive out of my desktop and plugged it into the server’s motherboard.  Popped the CD in and it worked just fine.

Lesson learned: If you get an error with an external CD drive, try connecting a SATA or IDE drive and using that.

Sep 14 09

Controlling Audio balance(Left/Right) in Windows Vista

by Jason Grimme

My computer’s audio goes through a stereo and then to two nice speakers on both sides of my desk.  One of said speakers is right next to the wall of my neighbor, which from time to time he complains about.  If I’m watching a movie or something, I’d like to be able to hear the audio completely out of the right speaker than only somewhat out of both.  Rather than unplugging the left speaker, I decided to set the balance of the audio more in favor of the right speaker.

It may be different depending on your audio card / driver, but I was able to control the balance by going:

Start -> Control Panel ->Sound -> Speakers -> Levels -> Balance.

I dragged the left slider to 10 and the right slider to 90.  Problem solved, hope this helps others!

Jul 19 09

Apple OSx Leopard 10.5.7 on a Dell D610

by Jason Grimme

What kind of developer would I be if I did not develop something for my iPhone?
The main issue keeping me from this was that developing iPhone applications require the iPhone SDK, which only runs on a Mac. Macs are expensive and I cannot afford to buy one simply to write a free application. The solution was to pull my hair out getting OSx86 installed on my old Dell D610 Laptop. This task was a major pain in the butt and I’d like to help anybody else out in the same boat I was in.

There are a few general guides on getting OSx on non-Apple computers, but I could not find any information on version 10.5.7, which the SDK requires.

The process took me about thirty hours of sitting in front of a computer, so have some nice music readily available. I ended up using iATKOS_v7, simply because I got furthest with it. If you have any problems with the install, which you will, Google your problem with the String “OSx86” in front of your problem.
I’d encourage you to verify the MD5 checksum is correct to avoid wasting time. It is also very important that you burn the image at a very slow speed. I used 1x speed on a high quality DVD. Trust me, it matters.

In you BIOS, disable as many devices as you can. Parallel, Serial, Wireless, etc.

Insert your disk, boot from disk, press F8
Use the Boot flags: -v -x
Wait about ten minutes. The longest part should come shortly after it says “Jettisoning kernel linker”. If you get errors, Google is your friend.

Note:
For the section ahead, I found that if you take your time the system freezes. Go as fast as you can through the prompts and get your hard drive formatted quickly to avoid freezes.
If it loads the plain blue screen but freezes, try plugging in an external monitor or try this Paper Clip hack
If it brings up the nice wallpaper, this is a good sign. Hopefully the ‘Continue’ and ‘Preparing’ prompts will appear. Continue through said prompts.

Once at the installation location prompt, go up top: ‘Utilities’ -> ‘Disk Utility’
Click on the hard drive / partition you want, click erase, and format as HFS Journaled.

Note:
When I got this far and wasn’t able to successfully install the OS, my hard drive would be bricked and I would receive boot errors. Most disk formatting tools would not recognize the drive. The best solution was to boot with a Windows install disk, format it with NTFS-quick, and then then turn off the computer once it starts copying the files. I then took the drive out of my laptop and connected it to my Windows machine with an IDE to USB connector.

In Windows, start the device manager. Right click on your hard drive and delete it.
Then, in command prompt, enter the following commands:

1
2
3
4
5
6
diskpart
list disk
select disk n (where n is your disk number.  Make sure you have the right disk!)
create partition primary id=af
list partition (Verify your new partition is there)
exit

Remove the hard drive and you should be set! If at any point during the setup process you get a hard drive error, format as NTFS and repeat these steps. I bricked and unbricked my hard drive countless numbers of times trying to get this to work.

Back to the Leopard install:
Exit out of the disk utility and go back to your hard drive selection screen.

Click on your hard drive, click install, and then click ‘Customize’. Now, customize. Select the appropriate kernels and drivers for your machine. After a day of guess-and-check, this configuration ended up working for me:
(In addition to the pre-selected options)

  • Kernel - Voodoo 9.7
  • VGA - Intel - GMA 950 - GMA 950 Laptop
  • VGA - Intel - GMA 950 - GMA 950 Rare
  • System - SATA/IDE - Intel SATA/IDE
  • System - USB
  • Network - Wireless - Broadcom BCM43xx
  • PS/2 Mouse/Keyboard - Voodoo PS/2 Driver with Trackpad Plugin

Go back to the install, click install. Skip the disk verification disk. If there is something wrong with it, you’ll find out during the install. I found that the installation takes about thirty minutes. At one point my status bar doesn’t move for about 15 minutes. Unless you get an error, don’t assume it is frozen!
Once it completes, click restart. You will go back to the DOS-like prompt and it will look like it’s frozen. Once again, let it run it’s course and shut down.

When it boots back up, you should get the chameleon/Darwin loading screen. Press any key and then enter in the flags -v -f. You should only need to enter in those flags the first time you boot.

Note: If it stalls and you get the “No” sign (as in, no smoking symbol), you might have included the wrong items in the ‘Customize’ part of the install. Before you start back from scratch, try using -f, -v, and -s for boot options. You can also specify your hard drive with rd=disk1s3 or whatever yours was. I got around this by having the install DVD in, booting off the DVD (Yes, it sounds silly) and after pressing F8 entering Boot: cpus=1 rd=disk0s1 -v -x . For some reason, this allows you to boot the OS on the hard drive. You should probably start over and reinstall Leopard with the correct drivers, but this does get you around the problem.

If Leopard loaded properly, you will be guided through the setup. Once in OSx, enjoy! Make sure to enable what you disabled in the BIOS (Especially the Wireless).

My audio did not work out of the box, even though we installed the VoodooHDA driver. The process of patching the OS involves installing ‘kext’ files, which are basically single-file archives. Rather than using the terminal to move them around, a great tool called Kext Helper does it for you. For the audio, you will need two kexts: AppleHDA(~2.4MB) and HDAEnabler(~30KB). Install them with Kext Helper, reboot, and boot the the flags -v -f. If your audio still does not work, try installing the kext AppleAC97Audio(~600KB). The volume control buttons on the D610 will work.

As with most installs, Ethernet did not work for me - but I did not spend a single minute trying to get it to work. As long as I have wireless, I am happy. I was able to install the iPhone SDK, VLC, and Firefox on Leopard and I think that is all I will need.

Please post any experiences or success stories you have!