We built a Store Locator for our Content Management System, and needed to calculate what stores were close by. That's simple enough in PostgreSQL, which a Point unit type, and simple trigonometry. However, in the Admin area, where you can add new stores, I needed to accept an address in its normal format, and convert that in to longitude and latitude points to be stored. Google's Geocoding API helps us do that.
As I work on an internal time tracker for our company, I needed to show all the TimeEntries for a specified week. To specify which week, it made sense to simply select 1 day in the week, since that's the easiest default control in Flex. This let's me get Sunday and Saturday, the start and end of the week, so I can build a query that grabs entries between those 2 dates.
In two languages that I use often (PHP and Javascript), there's 2 different equality operators when comparing values. It's become quite common to see places expressly tell you that you should only ever use one of them. That the other is evil. People see this, and then point fingers whenever you use 2 equal signs instead of 3. Here's perfectly valid reasons to use equal operator (==) instead of identity(===).
I've been playing with some random string generation, since I built a fairly simple one in a recent project for when users forget their password, and I reset it. It seemed decent enough: produced a string of strong size, alpha-numeric. It was good enough.
base_convert(uniqid(rand(),true),10,36)
It didn't take long after I had commited that code before I started thinking it could be better.
For some of my freelance clients, I have provided a home-brewed CMS, built using CakePHP, since I'd already used Cake for the rest of their web-site. I wanted to create a couple users, and an interface to be able to create pages that made up the navigation and content.
Building an admin area for this functionality, the first thing I did was turn on admin routing.
In the world of the web, lots of sites are popping up requiring users to login. When you need to do so, there's a bit more security than you might realize. You might be making a simple To-Do list, and might think:
Security? Pfft, I'm not too worried about people's to-do lists being stolen.
But what you didn't account for, is that all those username/password combinations a hacker just made off with? Yea, those are the same login's to important stuff, like e-mail , or bank accounts . Yikes!
Say we have a player model, and every field in playerstable is prepended with player_. For example, player_username, player_email, etc.
I'm personally not used to this database design, but I know plenty of people use it. When I work on projects that have this, I'm not particularly found of having to write:
$p = new Player;
echo $p->player_username;
I'd rather ditch the prepended part in all my PHP code.
echo $p->username; I probably spend more time writing PHP than I do Javascript (I'd like to reverse that but oh well). Well, PHP has so many functions, I'm constantly going to something like http://php.net/substr_replace to simply remember how a function works. It's not a long process, but it involves opening a new tab (Control + T), selecting the address bar (Control + D), typing php.net/substr_replace, and then loading the page.
To learn the basics of a Ubiquity command, I made it so all I have to do is open Ubiquity (Control + Space) and then type:
php substr_replace
Here's a short tip today. I've been finding that when using foreach in PHP to check if there's more in the array, the use of next() has failed me on multiple occasions . I just converted every instance of next() in my code to instead use end() .
I was doing some sorting of Models in PHP. Unfortunately, I didn't have the luxury of letting the SQL do it all for me. Usually it does. But besides sorting, I had to make sure I didn't have any duplicate entries, since I was merging arrays with different queries. My first hope was PHP's array_unique method.
In PHP, objects are all dynamic. If you declare a variable for object after instantiation, it just throws it right in, no questions asked. Much friendlier than, say, Java, where you absolutely must define a variable prior to use or the JVM will smite you. PHP also lets you define extra or different instructions when using a previously unknown variable with magic functions.
This past week, I was using PHP’s DOMDocument class to work with some XML generation. It’s pretty similar to Javascript’s DOM manipulation. The XML I was generating was a bunch of items with key attributes. () Learning how to extend a new class so that it behaves like a PHP Array made me outright excited for PHP ! Let’s delve into the magic.
With web applications becoming more prevalent, and new developers showing up to fill the demand, security for web applications is increasingly important. Some applications have very special, very private data that should be only accessible to the specific user. Other, less “important” applicat...
I've developed a couple really simple random elements that I have used prior on my web-site, a random header message and a random stylesheet .
