Toggle Hidden Folder for Finder

I don’t know about you, but personally, I rather hate having to remember how to view hidden folders in Finder. In case you don’t know what a hidden folder is: sometimes your (Mac) computer creates folders that are not really meant to be seen by you. So if you don’t know what they are and have never needed to use them, you should probably stay away! However there are times when important files lie within (Ya’ll Lion geeks know what I’m talking about, right? That damn ~/Library/ folder amiright!?)

If you’re looking for a quick fix:

  1. Open up Terminal (Applications | Utilities)
  2. Paste/Type in: 
    defaults write com.apple.finder AppleShowAllFiles -bool YES
  3. Hit Enter
  4. Paste/Type in:
    killall Finder
  5. Hit Enter

Finder will restart (say bye and hi to your dock) and you’re in!

But I assure you, you’ll hate seeing them again so go back in and follow the steps above again, just be sure to replace YES with NO during step 2.

Feeling lazy? Me too! I built an AppleScript for it so I’ll never have to remember that long command again… You can add this to your menu bar  by opening up the AppleScript editor (under Applications | Utilities), going to AppleScript Editor | Preferences, and checking off “Show Script Menu in Menu Bar” then you’ll have a hand page symbol like this:

User Scripts

 

Click the script icon and go to the open scripts folder, then choose Open User Scripts Folder (as I was doing) this takes you directly to the folder that holds your personal scripts (remember this one kiddies, it’s pretty useful). Then download the Finder Hidden Folders.scpt from the GitHub link below and copy and paste that sucker in there. As you can see from my screenshot, I can now toggle hidden folders by clicking that icon and then “Finder Hidden Folders” which will prompt

Finder Hidden Folders Prompt

 

This will go a long way as to never having to google or save that command when you most need it.

Download from GitHub

Upgraded to Xcode 4.6.1 Build Failed?

If you’ve recently upgraded to Xcode and your build failed with the following error:

error: PCH file built from a different branch 
((clang-425.0.24)) than the compiler ((clang-425.0.27))

Solution 1: Go to your menu bar and select Product | Clean and try building your package again.

Explanation:
This occurs because Xcode is confused as to where all of your Precompiled Headers are.

Solution 2: If the above doesn’t work, hold the Option Key down when clicking on Product and you’ll see Clean Build Folder instead.

Solution 3: In a really dire situation you’ll have to go and delete the SharedPrecompiledFolders that’s in your log. Typically this will occur if you’re using a command line driven build like I was. Look for this in your log:

/var/folders/YOURUNIQUESTRING/ANOTHERUNIQUESTRING/C/com.apple.Xcode.502/SharedPrecompiledHeaders

Delete the folder (not just the contents) and rebuild your product.

Creating a Simple Form Validation Messages in JavaScript

There are a ton of ways to validate forms through ASP, PHP, ColdFusion, etc. Servers are usually pretty good at handing you a way to validate forms with an error page. However, sometimes it’s nicer to prompt the user prior to going to an error page, wiping out your fields after all that hard work, or just plain confusion them with something they don’t understand. This simple JavaScript function will display an alert window with all the required fields listed that the user has left out.

<script type="text/javascript" language="JavaScript">
function validateForm(){
	var valid = true;
	var msg = "INCOMPLETE FORM FIELDS!\n\n ERRORS DETECTED:\n\n";
	if (document.myForm.fname.value == "") {
		msg += "You need to fill the First Name.\n";
		valid = false;
	}
	if (document.myForm.lname.value == "") {
		msg += "You need to fill in the Last Name.\n";
		valid = false;
	}
	if (document.myForm.age.value == "") {
		msg += "You need to fill in the age.\n";
		valid = false;
	}
	if (!valid) 
		alert(msg);
	return valid;
}
</script>

Let’s take a look at how the accompanying user form could look like:

<body>
   <form name="myForm" action="demo_form.asp"" onsubmit="return validateForm()" method="post">
   <table>
      <tr>
         <td>First name: </td>
         <td><input type="text" name="fname"></td>
      </tr>
      <tr>
          <td>Last name: </td>
          <td><input type="text" name="lname"></td>
      </tr>
      <tr>
          <td>Age: </td>
          <td><input type="text" name="age"></td>
      </tr>
   </table>  
   <input type="submit" value="Submit">
   </form>
</body>

Here’s the Form:

The HTML Form

Here’s the Error:

The Error Message

There are many ways to expand this out to help guide your application user. For example you can pull focus to the first error field, or highlight the box it’s encompassed in with CSS classes. This is just a demonstration of how a simple JavaScript alert can prove useful.

Update:
My buddy Mike hates HTML tables. Although the point was to illustrate how to validate a form… I thought I would include his form entitled “HTML Tables Bad!”

<form method="post" name="myForm" action="demo_form.asp">
<fieldset>
 
	<div>
		<label for="fname">First name:</label>
		<input type="text" name="fname" />
	</div>
 
	<div>
		<label for="lname">Last name:</label>
		<input type="text" name="lname" />
	</div>
 
	<div>
		<label for="age">Age:</label>
		<input type="text" name="age" />
	</div>
 
	<div>
		<input type="submit" value="Submit" />
	</div>
 
</fieldset>
</form>

What is SQL Injection and Does it Effect You?

In developing your web applications, it’s easy to get caught up in the hustle and bustle of just making it work. But in as you start out pulling queries to view, add, delete, modify data have you checked to see if you’ve left yourself open to SQL injection attacks?

In a nutshell SQL injection is allowing users to create, modify, view data without going through the intended channels. For example, let’s say your website has a view that displays a subset of the customer database. So you create some fancy code that queries out and shows a doctor their active patients, perhaps even modify/add the patient data. Perhaps with just a simple change of the URL, an attacker can do something as damaging as changing all the data for a patient, or view all the patient data!

So how do you prevent it?

  • Create roles within your application and use those roles as checkpoints and validations. Give minimal access.
  • Make sure you’re not exposing any statements that allow the use of the SA SQL account.
  • Use Parameter Queries, Use Parameter Queries, Use Parameter Queries

There are lots of ways to prevent this, but mostly just be careful and analyze your statements as you go. Look at your application from the hacker’s standpoint. Enjoy this infographic:

Veracode SQL Injection Tutorial Infographic

By Veracode

Day 012 – Life

Today’s theme was LIFE. It’s not that often that you get to see a rainbow. But how often is it that you get to see a rainbow that goes end to end? This may have been my first. I had about 2 minutes to take as many shots as I could, before it started to disappear.

There’s only a small bit of cropping and some light adjustments so that you can make it out.