My blog has moved!

You should be automatically redirected in 6 seconds. If not, visit
http://www.mattdturner.com/wordpress
and update your bookmarks.

AdSense

Pages

Monday, April 25, 2011

Useful .bashrc Functions

For those of you that read my other post about useful .cshrc functions, you know that I like to automate as many processes as possible.  If there is something redundant that I do frequently, I will script it or make a function to take care of it.

In an effort to assist those of you out there that like to automate processes but use bash instead of C-Shell, I have compiled a list of some useful functions to stick in your .bashrc file.  Here is a list of the functions that this post will contain:

  1. Extract:  This function will determine the type of archive you are dealing with, and issue the corresponding command to extract it.
  2. Compress:  This function will create a .tar.gz archive of whatever files you give.
  3. Swap:  This function will swap the names of 2 different files.
  4. Clock:  This is just a random function that will display a digital clock in your terminal window and update every second.
  5. Cpg:  This function will copy a file to a directory, and also cd you to a directory.
  6. Mvg:  This function works like Cpg, but moves the file instead of copying it.
  7. Findit:  This function will search for a file with the given pattern in the name.

Finding Text on Any Website on the iPad, iPhone, and iPod

One rather frustrating thing that I have noticed with the iPad (and iPhone) is the inability to search for text within Safari.  Well as it turns out, a simple javascript bookmark is all you need to add this functionality to any iOS device (just like my post on viewing source code).

To enable finding text within any website, follow the below instructions:

  1. Open Safari (pretty self explanatory).
  2. Create a new bookmark.
  3. In the Title window, write whatever you want your bookmark to be named (I chose "Find on Page")
  4. In the address bar add the following javascript code:  
    javascript:void(s=prompt('Find text:',''));s='('+s+')';x=new RegExp(s,'gi');rn=Math.floor(Math.random()*100);rid='z' + rn;b = document.body.innerHTML;b=b.replace(x,'$1');void(document.body.innerHTML=b);alert('Found ' + document.getElementsByName(rid).length + ' matches.');window.scrollTo(0,document.getElementsByName(rid)[0].offsetTop);

NOTE: As with the post on viewing source code, I did not develop this javascript bookmark. All credit goes to Matthew Panzarino.

Friday, April 22, 2011

How to View HTML Source Code on iOS | iPad, iPhone, iPod

Occasionally, when browsing the web I have a need to view the source code for a certain page.  However, there is no intrinsic way to do so on the iOS version of safari.  Well, using some simple javascript bookmark you can view the source code for any webpage.

To view the source code, follow the below instructions:

  1. Open Safari (duh!)
  2. Click the "Add Bookmark" button in Safari.
  3. Give the bookmark whatever name you wish; I chose the title "View Source".
  4. In the address bar of your new bookmark, paste the following code: 
    javascript:var%20sourceWindow%20%3D%20window.open%28%27about%3Ablank%27%29%3B%20%0Avar%20newDoc%20%3D%20sourceWindow.document%3B%20%0AnewDoc.open%28%29%3B%20%0AnewDoc.write%28%27%3Chtml%3E%3Chead%3E%3Ctitle%3ESource%20of%20%27%20%2B%20document.location.href%20%2B%20%27%3C/title%3E%3C/head%3E%3Cbody%3E%3C/body%3E%3C/html%3E%27%29%3B%20%0AnewDoc.close%28%29%3B%20%0Avar%20pre%20%3D%20newDoc.body.appendChild%28newDoc.createElement%28%22pre%22%29%29%3B%20%0Apre.appendChild%28newDoc.createTextNode%28document.documentElement.innerHTML%29%29%3B
  5. Now just navigate to whichever page you wish to view the source of, click the bookmarks button, and select your new View Source bookmark.
NOTE: I did not create this javascript bookmark.  I only discovered it while browsing the internet.  For the source of the javascript bookmark, please see Rob's Blog.

Thursday, April 21, 2011

My Top 10 iPhone Jailbreak Apps | April 2011

About once a month or so, I search around online for the best iPhone jailbreak apps.  I don't usually have the time to search through all of the new released in Cydia, so I tend to rely on other people's posts.

In an effort to provide some app ideas to new jailbreakers, below is a list of my 10 favorite jailbreak apps for the iPhone (in no particular order).


1. LockInfo

To me, this is an absolute must have app for the iPhone.  What this app does is puts many iPhone notifications together into a single user-friendly UI.  There are many different plugins for LockInfo, such as a plugin that displays RSS Feeds, a plugin that displays tasks from the AppStore 2do app, etc.

For a list of all native plugins, please see Plugins.

Mac Bluetooth Keyboard/Mouse Battery Level in Terminal

There are a few reasons why somebody might want to check the current battery percentage of a bluetooth mouse and/or keyboard within Terminal on a mac.  Some that come to mind are for use in GeekTool, if you are connected to the computer remotely through ssh, etc.

Well as it turns out, its actually very easy to do.  The tool that we will use to check the battery percentage is called "ioreg".  The Mac OS X manual describes ioreg as a tool that "displays the I/O Kit registry. It shows the hierarchical registry structure as an inverted tree."

There are many options available with the ioreg tool, however this article will just be discussing how to check the battery percentage of different devices.  See the below text for the code to view the battery percentage:

matthewturner/~:  ioreg -n "IOAppleBluetoothHIDDriver" | grep -i "batterypercent" | sed 's/[^[:digit:]]//g'
49
matthewturner/~:  ioreg -n "BNBMouseDevice" | grep -i "batterypercent" | sed 's/[^[:digit:]]//g'
45
matthewturner/~:  ioreg -n "BNBMouseDevice" | grep -i "batterypercent"
    | |   |     | | |   |   "BatteryPercent" = 45

There are a few things that should be noted about the above commands.

Wednesday, April 20, 2011

Automatically Make Shell Scripts Executable

I strongly believe that a script should be created to handle any repetitive process in the terminal.

By default, when you create a new script, it does not have executable permissions.  So for each script that you create, you then have to chmod the file to be executable.  However, its kind of hypocrital to say that a script should be created to replace any repetitive process and then not figure out a way to automate the 'chmod' command when creating a script.

Well, as it turns out, a simple addition to your vimrc file will automatically make any newly created script an executable (so long as you have the '#!' in the file).

" automatically give executable permissions if file begins with #! and contains
" '/bin/' in the path

au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod a+x <afile> | endif | endif
au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/usr/bin/" | silent !chmod a+x <afile> | endif | endif

So just copy the above code into your .vimrc file (each uncommented line ends in 2 endif commands) and now you can create scripts that are executable by default.
 

Tuesday, April 19, 2011

How to Fix "Output Conversion Error"

As part of my research for my Ph.D. I am on a team that is currently developing an adjoint of the EPA's CMAQ air quality model.  In the process of integrating all parts of the model into the full adjoint model, I ran into an error that was rather difficult to resolve.

Running the model would result in many occurances of the following error:

forrtl: error (63): output conversion error, unit -5, file Internal Formatted Write
Image              PC                Routine            Line        Source             
ADJOINT_FWD        00000000009B34BD  Unknown               Unknown  Unknown
ADJOINT_FWD        00000000009B1FC5  Unknown               Unknown  Unknown
ADJOINT_FWD        0000000000969210  Unknown               Unknown  Unknown
ADJOINT_FWD        000000000092AADF  Unknown               Unknown  Unknown
ADJOINT_FWD        000000000092A312  Unknown               Unknown  Unknown
ADJOINT_FWD        000000000095305A  Unknown               Unknown  Unknown
ADJOINT_FWD        00000000005D9F94  ckdesc3_                  138  ckdesc3.f
ADJOINT_FWD        00000000005A9FD1  open3_                    216  open3.F
ADJOINT_FWD        000000000047B395  chk_files_impl_mp         170  CHK_FILES_IMPL.F
ADJOINT_FWD        0000000000485060  chk_files1_mp_chk         347  CHK_FILES.F
ADJOINT_FWD        00000000005666CB  vdiff_                    369  vdiffacm2.F
ADJOINT_FWD        0000000000496B7E  sciproc_                  228  sciproc.F
ADJOINT_FWD        000000000048DDB5  MAIN__                    205  driver_fwd.F
ADJOINT_FWD        0000000000404A1C  Unknown               Unknown  Unknown
libc.so.6          0000003FE9E1D994  Unknown               Unknown  Unknown
ADJOINT_FWD        0000000000404929  Unknown               Unknown  Unknown


     >>> WARNING in subroutine CRTFIL3 <<<
     Error creating netCDF variable for file ADJ_VDIFF_CHK   
     Illegal data type    0

      
     *** ERROR ABORT in subroutine CHK_FILE_CREATE_
     Could not open ADJ_VDIFF_CHK file
     Date and time  13:00:00  July 22, 2001   (2001203:130000)


I spent a lot of time searching online, however I was unable to find a solution for my problem.  After days of debugging, I finally found the source of the problem.