Gazelle Incorporatedhttp://gazelleincorporated.com
Web Solutions and DevelopmentWed, 29 Jul 2015 21:08:30 +0000en-UShourly1http://wordpress.org/?v=4.2.3Recursive Functionshttp://gazelleincorporated.com/recursive-functions
http://gazelleincorporated.com/recursive-functions#respondThu, 02 Oct 2014 17:22:44 +0000http://gazelleincorporated.com/?p=331It’s always so exciting for a programmer when you realize a problem can be solved with a recursive function. It feels like you only had to find a solution for one simple case instead of solving it for all cases. In essence, that’s true.

A recursive function, by definition, is a function that calls itself. It calls itself again and again unless it finally finds itself in the one situation in which it know the answer to the problem.

You’ll want a function that takes a number, n, and multiplies it by each number below it, down to 1. 1 is the simple case; if n=1, you return n. Otherwise, you multiple n by the factorial of n-1. As you decrease n by 1 each time the function is called, you get closer and closer to having the solution, which you achieve when you hit n=1.

Wow, I just solved n! for any positive integer with a 2-line function! I don’t feel like I did any work except return n when it is 1! See what I mean about the excitement?

Sometimes, calling the function recursively doesn’t get you definitively closer to the solution, but it still gets you there. Recently, I was writing a function that generated a unique password for a user. There are two parts to it: 1) generating a random password and 2) ensuring it is unique. Turns out, a recursive function fits the bill:

]]>http://gazelleincorporated.com/recursive-functions/feed0When Simplicity Prevails: How to Calculate Age from Date of Birth in PHPhttp://gazelleincorporated.com/how-to-calculate-age-from-date-of-birth-in-php
http://gazelleincorporated.com/how-to-calculate-age-from-date-of-birth-in-php#respondWed, 24 Sep 2014 23:17:00 +0000http://gazelleincorporated.com/?p=323Sometimes, the solution is much much simpler than it initially appears to be. When tackling the problem of calculating someone’s age based on birth date, I first tried to take the birth date and convert it into seconds, and go from there. In reality, however, this opens up a can of worms, due to leap years, etc. Also, we are looking for a round number of years, so it’s messy to convert all the way down to seconds.

The solution is this simple:

Take the current year and subtract the year of birth.

$age = $currentYear - $birthYear;

If the current month is prior to the birth month, roll it back a year:

if($currentMonth < $birthMonth) $age--;

OR, if the current month is the SAME as the birth month, but the current DAY is prior to the birth DAY, roll it back a year:

Website for Phoenix Fighting Challenge, an MMA and kickboxing promotion based in Johnson County, KS, designed and launched in September 2014.

]]>http://gazelleincorporated.com/phoenix-fighting-challenge/feed0Decreasing the Chances of a Hacker “Guessing” your Passwordhttp://gazelleincorporated.com/decreasing-the-chances-of-a-hacker-guessing-your-password
http://gazelleincorporated.com/decreasing-the-chances-of-a-hacker-guessing-your-password#respondTue, 02 Sep 2014 20:03:34 +0000http://gazelleincorporated.com/?p=314Hackers don’t sit at a computer and try to guess your password by entering an educated guess one at a time into the login form for your bank account, Facebook account, iCloud account, etc.

They write a program that cycles through the educated guesses and automates the process of checking to see if it is a valid password. That’s about as much detail as is necessary. The point is, if your password is your first initial, last name and the month and day of your birthday, it’s going to eventually get “guessed.”

Enter “random” passwords.

Let’s pretend you chose your password to be a random string of 5 letters: owihl

There are 5 spots in this password, each of which that could have been occupied by 26 different characters (letters in this case). That means there are 26 X 26 x 26 x 26 x 26 or 265 = 11,881,376 possibilities. For a computer, that’s not very many to “guess” before finding the right one. BUT, what if the length of the password was unknown? Then you have to run this check for passwords of length 3, 4, 5, 6, 7, 8….

Now what if we added a number at the end that was 3 digits. A random number. Now we have 11,881,376 * 10 * 10 * 10 = 11,881,376,000 possibilities.

Random passwords are pretty hard to hack. But let’s face it, most passwords are not random. You have to be able to remember them, right? So you use your name or your kid’s name or your favorite name. Or you use your favorite color or sports team or sports team’s mascot. Then if you’re trying to be super secretive, you add a number…like 1….or your birthday….or your favorite number….or your kid’s birthday…or the year you were born…or the year you created the password….or 2.

Then maybe you capitalized a letter because iCloud/Apple made you. You probably capitalized the first one. You didn’t use any weird characters like $ or % because you didn’t think to, or you thought maybe that would mess up the form and not let you login.

Use the weird characters. Stick them in the middle of your password. Or the beginning. Or the end!

Stop using your name.

Stop using your birthday or the numbers 1 or 2. But use numbers!

Capitalize a different letter than the first one. Capitalize more than 1!

Wanna know where your passwords are safe? At your house on a post-it note. I know, I know, then other people in your life can see them and login to your stuff. But you know who CAN’T? Hackers.

The best place to store a password? In your head.

While we are at it:

Don’t use the same password for everything.

In particular, passwords that protect your money and your …naked pictures… should be separate from all other passwords.

]]>http://gazelleincorporated.com/american-top-team-hd/feed0Displaying a Calendar Month with PHPhttp://gazelleincorporated.com/displaying-a-calendar-month-with-php
http://gazelleincorporated.com/displaying-a-calendar-month-with-php#respondSun, 29 Sep 2013 12:12:31 +0000http://gazelleincorporated.com/?p=193The following snippet of code displays the current calendar month in an HTML table.

First we will get some information about today’s date.

$day_num=date("j"); //If today is September 29, $day_num=29
$month_num = date("m"); //If today is September 29, $month_num=9
$year = date("Y"); //4-digit year
$date_today = getdate(mktime(0,0,0,$month_num,1,$year)); //Returns array of date info for 1st day of this month
$month_name = $date_today["month"]; //Example: "September" - to label the Calendar
$first_week_day = $date_today["wday"]; //"wday" is 0-6, 0 being Sunday. This is for day 1 of this month

Next we are going to figure out which day is the FINAL day of the month.

$cont = true;
$today = 27; //The last day of the month must be >27, so start here
while (($today <= 32) && ($cont)) //At 32, we have to be rolling over to the next month
{
//Iterate through, incrementing $today
//Get the date information for the (hypothetical) date $month_num/$today/$year
$date_today = getdate(mktime(0,0,0,$month_num,$today,$year));
//Once $date_today's month ($date_today["mon"]) rolls over to the next month, we've found the $lastday
if ($date_today["mon"] != $month_num)
{
$lastday = $today - 1; //If we just rolled over to the next month, need to subtract 1 to get our $lastday
$cont = false; //This kicks us out of the while loop
}
$today++;
}

Now we have the final day of the month in $lastday. Let’s start some output, starting with a table with column headers for each day of the week.

The first week of the month is a special case because not all cells will necessarily be filled, since they may be days for last month.

$day = 1; //This variable will track the day of the month
$wday = $first_week_day; //This variable will track the day of the week (0-6, with Sunday being 0)
$firstweek = true; //Initialize $firstweek variable so we can deal with it first
while ( $day <= $lastday) //Iterate through all days of the month
{
if ($firstweek) //Special case - first week (remember we initialized $first_week_day above)
{
echo "<tr align=left>";
for ($i=1; $i<=$first_week_day; $i++)
{
echo "<td> </td>"; //Put a blank cell for each day until you hit $first_week_day
}
$firstweek = false; //Great, we're done with the blank cells
}
if ($wday==0) //Start a new row every Sunday
echo "<tr align=left>";

Now we are just outputting a cell for each day of the week showing $day.

Obviously, there are lots of things you can do with a calendar – put a Month dropdown at the top to switch to a different month, make each day a link to see a calendar of events for a single day, and so on.

Happy coding!

]]>http://gazelleincorporated.com/displaying-a-calendar-month-with-php/feed0Dynamically adding a watermark to an image using PHPhttp://gazelleincorporated.com/dynamically-adding-a-watermark-to-an-image-using-php
http://gazelleincorporated.com/dynamically-adding-a-watermark-to-an-image-using-php#respondWed, 20 Mar 2013 18:53:35 +0000http://gazelleincorporated.com/?p=177I decided to put this simple piece of code into a blog post so that

A) No one else wastes as much time perfecting this process as I have

B) So that I’ll remember it if needed in the future

If you have a gallery you are serving up on a site via PHP and you’d like to apply a watermark to each image before showing it to the world, create a script (example: watermark.php) with this code:
//Let's say you sent the filename via the url, i.e. watermark.php?filename=myimage.jpg
$filename=$_REQUEST['filename'];
//$imgpath is where your images in this gallery reside
$imgpath="images/";
//Put them all together to get the full path to the image:
$imgpath = $imgpath.$filename;
//OK cool, let's start the process of outputting the image with a watermark...
header('content-type: image/jpeg'); //HTTP header - assumes your images in the gallery are JPGs
//$watermarkfile is the filepath for your watermark image as a PNG-24 Transparent (ex: your logo)
$watermarkfile="images/watermark.png";
//Get the attributes of the watermark file so you can manipulate it
$watermark = imagecreatefrompng($watermarkfile);
//Get the width and height of your watermark - we will use this to calculate where to put it on the image
list($watermark_width,$watermark_height) = getimagesize($watermarkfile);
//Now get the main gallery image (at $imgpath) so we can maniuplate it
$image = imagecreatefromjpeg($imgpath);
//Get the width and height of your image - we will use this to calculate where the watermark goes
$size = getimagesize($imgpath);
//Calculate where the watermark is positioned
//In this example, it is positioned in the lower right corner, 15px away from the bottom & right edges
$dest_x = $size[0] - $watermark_width - 15;
$dest_y = $size[1] - $watermark_height - 15;
//I used to use imagecopymerge to apply the watermark to the image
//However it does not preserve the transparency and quality of the watermark
//imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 70);
//So I now use this function which works beautifully:
//Refer here for documentation: http://www.php.net/manual/en/function.imagecopy.php
imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
//Finalize the image:
imagejpeg($image);
//Destroy the image and the watermark handles
imagedestroy($image);
imagedestroy($watermark);

OK, now you have the code to apply a watermark to an image. All you need to do now is use HTML tags to call the image, using “watermark.php?filename=yourimagefile.jpg” as the “src” attribute.

]]>http://gazelleincorporated.com/dynamically-adding-a-watermark-to-an-image-using-php/feed0Tips for creating a website using WordPresshttp://gazelleincorporated.com/tips-for-creating-a-website-using-wordpress
http://gazelleincorporated.com/tips-for-creating-a-website-using-wordpress#commentsTue, 14 Sep 2010 09:57:49 +0000http://gazelleincorporated.com/?p=95Just about anyone can make a nice-looking, well-organized website these days if they are willing to get their hands just a little dirty. I’ve used WordPress with customized themes to create the following sites:

Here are a few tips for creating a website with WordPress for your personal or business use:

Create Pages, not Posts, for your informational content.

Most websites have a Home page and an About page. Depending on what the site is for, you may also want “Services,” “Portfolio,” “FAQ,” “Links,” pages and so on. These should be created as Pages in WordPress, not Posts. Only write Posts as part of your site’s Blog, if you want one.

Make sure you create a Page called “Home.” Then under Settings -> Reading, at the top of the screen, check the box for the front page to display a Static Page and select the Home Page to be the one displayed.

Get rid of Commenting, Author Name, the Timestamp and anything else but the actual content on each Page.

This will get rid of that “blog look.” For some themes, you can disable these things in the settings. For others, they are already removed on the static Pages for you. In case they’re not, you’ll need to edit the page.php file under Appearance -> Editor. This is the template file that each of your site’s Pages follows.

In the page.php file, look for a PHP function call that says “comments_template();” and put two slashes in front of it to disable that call: “//comments_template();” …do the same thing with the function call “the_time();” to get rid of the timestamp for the date and time the page was published to the site. If you see an Author listed under the title of the Pages on your site, look for a function call like “the_author()” or “the_author_posts_link()” and put two slashes in front of it. If there is also the word “by” in front of the author call, just delete it.

In general, if you see something in the body of a Page on your site that you don’t want, you can search the page.php file and get rid of the code causing that information to display.

Customize your Sidebar…or get rid of it.

For a site that will include a blog, a great way to display recent blog posts is to put them in the sidebar using a widget. Go to Appearance -> Widgets and drag the “Recent Posts” widget over to the Sidebar box on the right.

If you are on Twitter or Facebook, either put links to your accounts in your sidebar or embed a Twitter and/or Facebook widget for your account.

Of course, you would replace “yourtwittername” with your twitter handle and

“http://www.yourdomain.com/wp-content/uploads/2010/08/tweet.png”

with the link to the social media button you uploaded under Media.

If you want to embed a Twitter or Facebook widget, you can grab the code from your account on those sites and paste it into a Text/HTML widget in your sidebar.

Other ideas for your sidebar are:

Contact Information for you or your organization

Upcoming Events, if applicable

Partner or Sponsor links and/or logos.

If none of these apply to your site, and you don’t have a blog on your site, you don’t HAVE to have anything on your sidebar.

To get rid of your sidebar entirely, you can usually edit the footer.php file and put two slashes (“//”) in front of the call to “get_sidebar();” to disable it. If you don’t see that in the footer.php file, you may be able to disable it in your theme’s settings.

While I certainly didn’t cover all of the possibilities for customization here, I hope that gets you off to a good start. Feel free to comment if you have questions!

– Ann, Chief Go-Getter

]]>http://gazelleincorporated.com/tips-for-creating-a-website-using-wordpress/feed7What if we taught all the girls how to make websites?http://gazelleincorporated.com/what-if-we-taught-all-the-girls-how-to-make-websites
http://gazelleincorporated.com/what-if-we-taught-all-the-girls-how-to-make-websites#respondWed, 19 May 2010 23:03:26 +0000http://gazelleincorporated.com/?p=45This post was originally published at GirlyGeekdom.com

I was brainstorming with a director at Girls Inc Orange County on Monday about ways in which Women for Girls, a group of professional women in support of Girls Inc OC, could work with the girls served by the organization. The director was briefing me on the various programs currently in place, one of which is an internship program, placing high school girls with local businesses for a four-week internship that hopefully pays a stipend of at least a few hundred dollars.

The very first thing I thought was, “Let me hire one so I can teach her how to make websites!”

I’ve been contemplating offering “WordPress Consultation” as one of my services to fill in the gap between zero dollars and the starting price of a custom website by my company. Often I come across a potential client that just doesn’t have the money upfront to pay for a custom website and yet they have no idea how to create one themselves. I’ve had to turn these clients down because there just aren’t enough hours in the day to help everyone, even if I want to, without getting proper pay.

I often think to myself, “I could teach them how to do this themselves in a few hours,” especially if all they need is a basic informational website. WordPress (and other such blog packages you can host yourself) has made it possible to create a professional-looking website that is easy to maintain in a matter of hours…even minutes. Honestly.

Think about the most basic of websites with a home page, an about page, a services page, and a contact page. That’s four pages. Literally – pick a cool theme and activate it, create four Pages in the WordPress dashboard, label them appropriately, make sure the main navigation displays pages (and not categories), and you’re essentially done!

Ahhh, did I lose you a bit? “But how do I change the main navigation?” you ask. Yes, it’s true that you might need to tinker with some PHP code in order to make this work. That’s what scares most people off…just the mention of “code” will usually end the conversation.

But if I had an intern and it was her JOB to learn new things, I could show her. I could guide her through the entire process, and by the time we set up a couple of them together, she’d be off an running on her own, figuring out how to make expandable menus and hooking up the featured content gallery plugin. Of course, we’d also have to get into the details about hosting – Nameservers, E-mail Address setup, and so on. But all of this is pretty simple after you’ve done it a few times.

Just think of the power that gives her. A teenager who can create websites! She could setup a shared hosting account so she has space for a bunch of small sites as well as a discounted rate on domain names. Tben she could go to local businesses with fliers advertising her starting rate and rate per page after, say, four pages. They’ll trust her because she’s local and she’s not a big company who’s going to charge them an arm and a leg in the beginning and $100 every time a word needs to be changed. Also, she’s young and “hip” and will be perceived as current and “up on the latest styles” in terms of design and what catches people’s attention. Her prices will be lower than her competitors because she has no overhead – no office to rent, no employees to pay, and the only supplies she needs are a computer and internet access.

Knowing how to make websites has opened many doors in my life. How many doors could it open for young girls?