bryanculver.com

December 9, 2008 @ 19:41

A Better is_int()

There is one big problem with the PHP function is_int(). Should the digit come in as a string, either by a URI function or a text input, it will not pass. This is fairly annoying when you are either unaware of it or not thinking about it.

Example:

$var = (string) 4;
if(is_int($var))
{
	echo "Is integer.";
}
else
{
	echo "Is not integer.";
}

Would result:

Is not integer.

Even intval() won’t work either because letters also return a value.

Example:

$var = (string) "4";
echo intval($var);

Would result:

4

That would work, no? Yes as long as you don’t plan to use the number 0 because letters return 0.

Example:

$var = (string) "b";
echo intval($var);

Would result:

0

So I sought to come up with a better way to determine if something is an integer.

Example:

$var = (string) "2";
if(preg_match("/[^\d]/", $var) === 0)
{
	echo "Is integer.";
}
else
{
	echo "Is not integer.";
}

Would result:

Is integer.

And anything containing a character will not pass.

Example:

$var = (string) "2b";
if(preg_match("/[^\d]/", $var) === 0)
{
	echo "Is integer.";
}
else
{
	echo "Is not integer.";
}

Would result:

Is not integer.

Digg this
November 30, 2008 @ 19:39

Move A Folder, Don’t Lose Links

So I had a problem with a couple Mac mini’s a few months ago. Their internal drives are tiny and I had a mass of music and pictures to move onto an external drive. But I didn’t want to lose the library information in iTunes or iPhoto. So I had to come up with a way to have OS X look onto the external drive for all this content without telling iTunes or any other app. The *nix back end of OS X provided me with such tools, I just had to get it right.

So after having to remember the individual Terminal commands to not lose any data and get seamless links, a friend called me up with a similar problem where we wanted to store all of his DVDs digitally and use just Front Row and connect his iMac to his TV. Sadly his internal HD wouldn’t be big enough over time and explaining to him the process of the Terminal commands without screwing it up. So I wrote this little app to do it all. Just download the app, open, select the original folder, the future location folder, enter your password (to preserve details while copying, it needs admin privileges and let the script do it’s job.

Download moveLink.app


Digg this
November 29, 2008 @ 13:23

GMail’s IMAP and Mail.app

Using Gmail’s IMAP is a little bit different than most IMAP access on other servers. They put everything in a [Gmail] folder, what we would call folders, they call tags. Flagged? Starred. As well deleting messages can be rather difficult. But with the advent of Google Apps, I really wanted to be able to use it effectively.

Enable IMAP

This one is pretty straight forward. Log into Gmail, go to Settings > Forwarding and POP/IMAP and select Enable IMAP.

Enable IMAP

Wait A Few Minutes (optional)

I have found that sometimes Gmail’s IMAP doesn’t always work the best RIGHT when you enable it but it might depend on the number of messages in your inbox.

Walk Through The Setup, Except For Two Steps

The configuration is pretty standard. But we need to alter two steps. You can find the default configuration setting here: Configuration Instructions

The two steps we want to alter are this step:

GMail Auto Configure

Don’t let Mail automatically set up the account. This option isn’t available if you are using Google Apps. Mostly I suggest this because Mail will default to using Google’s POP instead of IMAP.

The last step we want to alter is the last screen:

Do Not Take Online

This is the most important step because we need to make some account setting modifications before Mail brings the folders over.

The Key to Bliss

Go to the Advanced tab of the account and set the IMAP Path Prefix to “[Gmail]” (without the quotes)

IMAP Prefix

Now close the Mail Preferences. It will ask you if you’d like to save the changes.

Designate Folders

If Mail didn’t automatically start downloading emails, click Get Mail and wait for Mail Activity to stop. Now go though each folder that should now appear in your sidebar. Select the folders and then click Mailbox > Use This Mailbox For and select the appropriate folder type (Ex: “Junk” for “Spam”). Obviously there won’t be one for Starred or All Mail.

The beauty of this set up is that when you delete email, it’s sent to the trash on Gmail. Now if you would like to remove the feature so that all of your email is kept in the All Mail folder of Gmail, open the account preferences again, select the account, go to the Mailbox Behaviors tab and uncheck “Move deleted messages to the Trash mailbox.

And that’s all!


Digg this
November 25, 2008 @ 12:54

Top Gear is Awesome

The Stig

The Stig ~ Pro Driver

The best show, ever. That is all. And for your enjoyment, a clip.


Digg this
November 24, 2008 @ 15:08

I’m Back?

So over the past few weeks I have been working hard on new ideas I had. The first of that being the Sane Syntax Initiative. It’s just been put in place and I have been working extensively to get the gears turning. Basically I would like it to be a place where all developers and programmers look unto for links, examples and tools for the language they are working on. It’s also a place for the same people to share with others some of the things they have come up with. It’s bold, I know but I feel it’s a needed addition to the development community.

As well, under the same name, I am starting the Sane Syntax Lib (SSLib). This is initially going to be a syntax highlightor but might spread out into more. As of yet, nothing has been set in stone. You might ask why I would want to “reinvent the wheel” so-to-speak but as of right now I haven’t found anything to be valid right off the bat, output wise as well as easier to style.

So to document my days, I’ve decided to reopen my blog. If I can find any of my old posts that are frequently linked from other sites, I will post them.


Digg this
Previous Posts »
Wordpress v2.7 | This has been a 5MinuteDesign | XHTML | CSS | RSS2 | 0.084