Deleting Safari Cookies in iOS Simulator

If you are doing any kind of development that involves cookies and need to be able to delete them while testing iOS you will likely need to delete them as well.

The iOS simulator (Launched from Xcode by going to Xcode > Open Developer Tool > iOS Simulator) stores data for the simulator in the following directory on the host Mac OSX file system:  /Users/<uid>/Library/Application Support/iPhone Simulator/

First, quit out of the iOS Simulator.

To find the cookies and delete them open up a terminal and cd to the iPhone Simulator directory.

$ cd /Users/<uid>/Library/Application\ Support/iPhone\ Simulator/

Then execute the following find command to find the cookie data file:

$ find ./ -type f -iname ‘*binarycookies*’ -exec ls -l {} \;
-rw-r–r–  1 ryanchapin  staff  2503 Nov  6 08:32 .//7.0-64/Applications/630F9FE9-87B2-4A6D-8C60-CA70EBC5FD8A/Library/Cookies/Cookies.binarycookies

You can then update the find command to the following to delete the file.

$ find ./ -type f -iname ‘*binarycookies*’ -exec rm {} \;

Executing Dynamically Generated SQL Queries from a Shell Script

Following is how to generate dynamic SQL in a shell script and then execute those queries.

Let’s say, for instance, that you have a list of tables that you want to flush regularly during development and don’t want to type in the SQL queries each time.  Moreover, you just want to maintain a list of the table names and add and remove from it when necessary and have your script dynamically generate and execute the delete statements.

For the purposes of this tutorial we are running these commands as root to avoid the additional complication of authentication.

The first thing you need is your text file with the list of your tables:

table_list.txt:

table_a
table_b
table_c

delete_data.sh:

table_list.txt:

table_a
table_b
table_c

delete_data.sh:

#!/bin/bash

for i in `cat tables_list.txt`
do

   mysql -u root dbase_name << END_SQL
   delete from ${i};
END_SQL
#
# It is imperitive that the END_SQL redirect identifier
# be on its own line without any leading or trailing spaces
#

done

The script will run, will make a connection to MySQL and then execute the command with the dynamically generated target table.

This will work with other databases other than MySQL as well.

Setting Up Android SDK and Plugin in an Existing Install of Eclipse

To set up an existing install of Eclipse to do some Android development do the following:

  • Go to http://developer.android.com/sdk/index.html and look for and download the ADT bundle for your OS (in my case I was using Fedora Core 18 at the time)
  • Unpack it as the user that is going to be running Eclipse and/or after you unpack it make sure that your user has read/write/execute permissons for the files in this directory (obviously, you don’t need execute permssion for non executables).  To make things easy, I just created an ~/sdks directory and unpacked it in there.
  • Fire up eclipse and go to Help/New Software.
  • Add the following repository: https://dl-ssl.google.com/android/eclipse/
  • Check off both the Developer Tools and NDK Plugins.
  • After those plugins install go to Window/Preferences/Android, and click the ‘Browse’ button next to ‘SDK Location:’, selecting the /path-to/adt-bundle-linux-x86_64-20130917/sdk.  When setting this up you might get a dialogue box that indicates that the version of the Android SDK Tools and/or Android SDK Platform Tools is not compatible with the version of the adt-bundle you are attempting to use.  In my case, I was prompted to update it via the Android SDK Manager and was able to download an updated version.

If you have an existing project that you are working with you might have to update the project.properties to update the sdk level number.

You might see an error like:

Unable to resolve target ‘android-17’ until the SDK is loaded

If so, update the ‘target=android-17’ property in the project.properties file to match the value of ‘Platform.MinPlatformToolsRev’ in the /path-to/adt-bundle-linux-x86_64-20130917/sdk/tools/source.properties file.

In my case, I updated the project.properties to:

# Project target.
target=android-18

Getting the value ’18’ from the source.properties:

Platform.MinPlatformToolsRev=18

Showing Hidden Files and Folders Under Mac OSX

By default the Mac hides a number of different Folder as well as any file or folder that starts with a “.” character.

To show all of these files/folders in the Finder open a terminal and enter teh following commands:

$ defaults write com.apple.Finder AppleShowAllFiles TRUE

$ killall Finder

The Finder should restart and you should be able to see all of the files and folders on the machine.

Do Not Use Symlinks in Jetty’s webapps Directory

I set up a development instance of Jetty on my local machine and have been happily coding, compiling and deploying via a shell script.  The script copies the war from my user’s target directory to the jetty users’s home dir changes the permissions and then moves it to the /webapp dir creating a symlink to the name of the .war that is referenced in a number of config files.

This was working just fine until I did a merge with another developers code and a significant portion of it changed that Jetty had problems determining whether or not is should dump it’s local cache of .class files and configs and got into a very funky state.  Unfortunately, not one in which it was obviously funky, but where, all of the sudden I could not look up defined DataSources in JNDI.

Ultimately, after looking through many other different things, I decided to delete the symlink and, rename the .war in the /webapps dir.

Bingo, worked right away.

Getting Markdown Viewer To Display HTML Formatted Markdown Content in Firefox Under Linux

I recently installed the Markdown Viewer 1.3 in Firefox 23.0 under Fedora Core  18.  When I went to open a .md file in the browser it prompted me to download it.

To configure Firefox to display the markdown in the browser do the following:

Edit the ~/.mozilla/firefox/*default/mimeTypes.rdf file.

If there is not yet an existing RDF node for ‘text/plain’ add it, and add “md” as a file extension.

<RDF:Description RDF:about=”urn:mimetype:text/plain”
        NC:value=”text/plain”
        NC:fileExtensions=”md”
        NC:description=”Text Document”>
    <NC:handlerProp RDF:resource=”urn:mimetype:handler:text/plain”/>
</RDF:Description>

Internet Explorer Not Deleting Session Cookies

If you are trying to delete session cookies, those cookies with an expires or max-age value of -1 or no value set for that property, in Internet Explorer, you will probably notice that deleting them from the controls in the browser, does not actually delete them.

Evidently, the IE cookie implementation only writes persistent cookies to the file system and maintains the session cookies in RAM.  Moreover, when telling the browser to delete the cookies, it only deletes the cookies from the file system and does not delete them from RAM.

To delete session cookies in IE, you will need to restart the browser.

Use CookieSpy to View and Manage Internet Explorer 9 Cookies on Windows 7

I am doing some client-side testing of IE 9 on Windows 7 and need to be able to view cookies and their associated data.

The F12 developer tools is insufficient for this task as using the Cache/View cookie information selection only shows the cookies for the current domain that you are browsing in the current tab.

Moreover, when going to Internet Options, General Tab, clicking on the Settings button under ‘Browsing History’, and then clicking on the ‘View files’ or ‘View objects’ button does not show the cookie files.

I ended up installing CookieSpy and with it am able to easily view and manage the cookies for all of the (supported) browsers on the machine.

Splitting a String into an Array with a Custom Delimiter in a Bash Shell Script

Most high level languages have some sort of String.split([delimiter]) method to create an array of Strings tokenized by a user specified delimiter.  This is a simple way to convert a CSV into an array.

Here is a quick way to do that in a bash shell script:

#!/bin/bash

SOURCE_STRING='foo|blah|moo'
# Save the initial Interal Field Separator
OIFS="$IFS"
# Set the IFS to a custom delimiter
IFS='|'

read -a TOKENS <<< "${SOURCE_STRING}"
for i in "${TOKENS[@]}"
do
  echo "$i"
done

# Reset original IFS
IFS="$OIFS"