Monday, May 9, 2011

OSX Slow Boot / Can't Change Boot Volume

I recently had a very odd problem with my iMac. I have a after market SSD in it and have Boot Camp set up with Windows 7. It has been working fine for about a year now but all of the sudden my boot time tripped and I was no longer able to switch OS's with BootChamp nor set a startup volume in System Preferences.

After some investigation I found the following symptoms and error messages:
  • There were some scree rendering issues / I could mouse the mouse but not click or type.
  • I was able to use Remote Desktop / VNC to connect and interact with the computer properly.
  • In Activity Monitor the kernel_task process was using 100% of the CPU on one of the cores.
  • I could boot to Windows at startup and had no problems, errors, or lag there.
Could not find IODeviceTree:/options
EFI found at IODeviceTree:/efi Mount point for /Volumes/BOOTCAMP is /Volumes/BOOTCAMP
flushing fs disk buffer returned 0x5
IOHIDSystem: postEvent LLEventQueue overflow.
Can't access "efi-boot-device" NVRAM variable
no bootx creation request
nvram: nvram is not supported on this system

One of the messages when I was testing the Unix bless command indicated that the "efi-boot-device" NVRAM variable was not accessible. I then tried to examine it with the Unix nvram command only to get the "nvram: nvram is not supported on this system" error. I found the NVRAM error very odd And was surprised the computer was even booting if the nvram was defective. I then tried to reset the NVRAM as it was not operating properly.


Solution:
As it turned out the problem all along was that the NVRAM had corrupted and was non-functional. I did a hard reset of the NVRAM and all the problems went away immediately. To reset the NVRAM you just reboot and hold down Command, Option, P, and R as the computer boots, or see this Apple Document.

Friday, April 15, 2011

Reading .NET JSON Date's in jQuery

ASP.Net writes out date objects to a JSON stream in the format { "\/Date(x)\/" } but jQuery will not automatically convert this to a JavaScript date but rather keeps it as a string. To fix that this simple converter script can be included in your global JavaScript header.

Note that this does requite jQuery 1.5+.

$.ajaxSetup({
    // Add a custom converter to convert ASP.NET JSON dates to JS Date object
    // That is convert { "\/Date(...)\/" } to { new Date(...) }
    converters: {
        "text json": function( textValue ) {
            return jQuery.parseJSON(textValue.replace(/"\\\/Date\((-?\d*)\)\\\/"/g, "new Date($1)"));
        }
    }
});

Wednesday, April 13, 2011

Adding Better Ajax/JSON methods to HighCharts

I recently started using Highcharts as the charting options in Crystal Reports are rather limited. Here is a small patch I made to simplify the loading of chart data from JSON server calls via AJAX. This does not do anything incredibly unique, just simplifies the code to do so by adding an ajaxSource property to the chart and series configurations that is loaded on init and a reloadAjax method to automatically reload the data.

05/03/2011 - Rewrote the code as a extension instead of a patch and added support for setting multiple series via options.chart.ajaxSource.

Thursday, August 12, 2010

Mass rename files in Midnight Commander

Here is another script for Midnight Commander to allow for mass renaming of flagged files. To use it you will need to add it to your MC menu file in /etc/mc/mc.menu or ~/.mc/menu.

+ t t
e       Rename tagged files
        set %t; CMD=%{Enter regex}
        while [ -n "$1" ]; do
          echo rename -\"s"$CMD"e\" "$1"
          rename -\"s"$CMD"e\" "$1"
          shift
        done

first you will need to flag the files toy want to rename then execute the user operation. When you do so you will be prompted for the regular expression you with to execute.

Some examples:
 /oldword/newword/   # Change a word.
 /_/ /g   # Replace all _'s with spaces.
 /_\[.*\]//   # Remove _[CRCHASH] tags.
 /\(.*\)//   # Remove (...) sections.

Comapring files with md5 Checksums in Midnight Commander

I wrote a few scripts for Midnight Commander to easily compare multiple copies of a directory via checksums.  There are a few variations listed below along with a bash script that does the same thing.



First off is this simple bash script that can be used stand alone but is also required for the MC menu entries. 

/usr/local/bin/md5compare
#!/usr/local/bin/bash
echo -n "Comparing $1 to $2: "
if [ ! -e "$1" ] || [ ! -e "$2" ]
then
 echo File Missing
 exit 1; 
fi

if [ $(md5 -q "$1") = $(md5 -q "$2") ]
then
 echo Files Match
 exit 0;
else
 echo Files Different
 exit 1;
fi

You may need to tweak the bash and script paths for your installation. Also remember to make it executable.

sudo chmod +x /usr/local/bin/md5compare

To execute this command directly just run the following.

md5compare file1 file2



Next up are two comparison scripts that can be added MC's user menu.  To do this append them to the mc.menu file in your system /etc or users ~/.mc/menu.

This script will compare the currently highlighted file with one of the same name in the other panel.

+ t n
w       Compare files via MD5 checksum
        /usr/local/bin/md5compare %f %D/%f
        echo Press any key to continue
        read key

This script on the other hand will compare all tagged files to any matching files in the other panel.

+ t t
W       Compare tagged files via MD5 checksum
        for i in %t
        do 
          /usr/local/bin/md5compare "$i" %D/"$i"
        done
        echo Press any key to continue
        read key

Finally here is a menu item to simply dispaly the checksum of the selected file.

+ t n
s       Calculate MD5 checksum
        echo Calculating checksum of %f
        md5 -q %f
        echo Press any key to continue
        read key