When writing a method in .NET (C# or VB), you typically have to overload that method if you want to provide default or optional parameters. Now, thanks to C# 4.0 and VB 10, you can use optional parameters.

For example, prior to C# 4.0, you had to do the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
// Assume we're using a class and the following stuff is from our class

// no parameters
public void myMethod()
{
    myMethod("optional");
}

// one parameter
public void myMethod(string str)
{
    // STUB
}

As you can see from the preceding code, you need to type more than one function. To each their own. Some people like doing this, some people don’t. I like how it works in PHP:

1
2
3
function myFunc($optional="hello world!") {
// STUB
}


CONTINUE READING


I’m researching how to get pop ups to not be blocked using flash, and in that research, I found out how to check and see if a popup was blocked or not. It’s such a simple solution I don’t know why I haven’t consciously noticed it before. I’ve created many popups in the past, just never thought about how I would check if a popup was blocked.

The Solution

Using JavaScript, put something like this in your code:

1
2
3
4
5
6
7
8
// this is sample code so replace
// wurl = the url you want opened
// wname = name given to the window so you can reference it again programmically
// wfeatures = optionally you can give it scroll bars, make it resizeable, etc.
var win = window.open(wurl, wname, wfeatures);
if(win == null || typeof(win) == "undefined") {
   alert("Please enabled popups for this site to continue.");  
}

That’s it! That’s all you need to do to test if someone has blocked your popup. Now you need to decide if it’s worth the hassle of working with popups and how to handle when a popup is blocked.

The three simple ways around using popups are:
CONTINUE READING


I’m working on a web page thumbnail generator and a new blog post (a good one this time) about web page thumbnail generation. A topic for another day; however, when making the preloader for it…I don’t like the flash preloaders that you see every where, and I thought giving progress back wouldn’t be worth it because how am I going to know how to calculate the percentage done. You know how it says 60%, 70%, 80% percent in normal preloaders? Well, in this situation it wouldn’t be accurate to do something like that because I’m doing a whole bunch of different calculations, etc.

So what did I do? I thought, “Hey, why not just use an animated gif, like what I see on ajaxload.info?” I get back to coding and I load in my gif right? Wrong.

CONTINUE READING


I found a site for you that lists some of the best jQuery Lightbox Scripts. If you don’t already know, lightbox scripts are pretty much just javascript files that create modal pop ups. A lightbox can be used to show images, videos, and/or web pages inline without having to open a new browser window.

Keep an eye out for the colorbox, it’s a good one.

Visit Source

I installed yet another install of phpMyAdmin, and every time I forget how to configure it to force SSL. All phpMyAdmin installs should do this (use SSL). You never want to login without SSL unless you’re on a secured network.

2 ways to force SSL with phpMyAdmin

1) Using Apache .htaccess (this can also be put in the httpd.conf if you don’t use .htaccess files):

1
2
3
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/directory(.*)$ https://%{HTTP_HOST}/directory$1 [L,R]

Note: I don’t like this way but I this is a way some people do it.

2) Using phpMyAdmin’s config.inc.php file:

1
2
// place this at the bottom somewhere
$cfg['ForceSSL'] = true;


CONTINUE READING


This is amazing. Somebody finally put this together:

http://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers

Bookmark it because you’re going to need it if you’re a web developer. It’s helped me. Well, it hasn’t yet but I’m sure it will. And that’s also why I’m blogging about it. I want to remember it and I want it somewhere I’ll be sure to find it.


Been out of the game a little while, my apologies. I know there isn’t much I can do to make it up to you (my fans); however, I’ll give you this in hopes of trying to win you back.

Format phone function using PHP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function format_phone($country, $phone) {
$function = 'format_phone_' . $country;
if(function_exists($function)) {
return $function($phone);
}
return $phone;
}

function format_phone_us($phone) {
// note: making sure we have something
if(!isset($phone{3})) { return ''; }
// note: strip out everything but numbers
$phone = preg_replace("/[^0-9]/", "", $phone);
$length = strlen($phone);
switch($length) {
case 7:
return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
break;
case 10:
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
break;
case 11:
return preg_replace("/([0-9{1})([0-9]{3})([0-9]{3})([0-9]{4})/", "$1($2) $3-$4", $phone);
break;
default:
return $phone;
break;
}
}

// usage
$phone = '111 111 1111';
$phone = format_phone('us', $phone);
echo $phone;


CONTINUE READING


I still see on a lot of sites the copyright date being outdated. Shoot, it was even outdated on mine. How embarrassing. Easy fix though. Something I do at work all the time, but since I’m not getting paid for this site, it wasn’t done.

Now, let’s forget the past and move onto the future.

The solution (in PHP):

1
2
3
4
function copyright_year($year = '2009', $sep = '-') {
$current_year = date('Y');
return ($year == $current_year) ? $year : $year . $sep . $current_year;
}

OR, for those that need more lines (I do too. I like to be able to READ my code):

[cc lang="php"]
function copyright_year($year = ’2009′, $sep = ‘-’) {


CONTINUE READING