Posted by Matt on 30th November 2006
I was working with a list of wildcard banned domain names (e.g. *.spamsite.com) stored in a database. I needed to compare a submitted domain (e.g. anything.spamsite.com) to the wildcard entries stored in the database.
Essentially then I need the function in_array to perform with a wildcard match with the wildcards being the array haystack not the needle.
In the above example, I need the script to detect that anything.spamsite.com is banned. Here’s what I did:
Code (php)
-
$bannedurl = false;</p>
-
//The function fnmatch is useful here but is not available on Windows systems, so it must be defined if it does not exist.
-
-
-
function fnmatch($pattern,
$string) {
-
-
}
-
}
-
-
//This function allows wildcards in the array to be searched
-
function my_inArray($needle, $haystack) {
-
foreach ($haystack as $value) {
-
if (true ===
fnmatch($value,
$needle)) {
-
return true;
-
}
-
}
-
return false;
-
}
-
foreach ($wild_urls as $value) {
-
$wild_urls[] = ‘*’ . $value;
-
}
-
-
//An Example
-
-
$wild_urls =
array(‘*.spamsite.com’);
-
$domain = ‘anything.spamsite.com’;
-
-
//Test it, returns true if the Domain is banned.
-
-
if (my_inArray($domain, $wild_urls)) $bannedurl = true;
-
-
//Note, for the domain spamsite.com, you can do a straight MySQL query such as " …… where domain like ‘%" . $domain . "’ and domain not like ‘%_." . $domain . "’ "
Posted in MySQL, PHP Code Snippets | No Comments »
Posted by Matt on 27th November 2006
I was looking for a Wordpress plugin to display PHP code on my site. I found the following:
http://priyadi.net/archives/2005/09/27/wordpress-plugin-code-autoescape/ I tried this one but did not like it because it does not highlight the code and I could not seem to get it to work quite right, it kept adding –> to certain tags/areas… didn’t spend time trying to figure out what was going on as I didn’t like it anyway.
http://www.deanlee.cn/wordpress/code_highlighter_plugin_for_wordpress/ I tried this one next and I like it. It displays the code and highlights it with no problems/errors and is easy to impliment. One thing I didn’t like about it is that I had to use BR tags with each tags for each line to end the line.
http://dev.wp-plugins.org/wiki/GeshiSyntaxColorer I didn’t try this one, but I believe it is the same software as the one above.
Posted in PHP Code Snippets | 1 Comment »
Posted by Matt on 27th November 2006
MySQL injection attacks occur when the code of a MySQL query can be altered by the user due to improper escaping of variables.
See http://us3.php.net/mysql_real_escape_string for a great example of an SQL injection attack.
MySQL injection attacks can be prevented by using mysql_real_escape_string($mystring) for each variable inputted into a MySQL query.
Posted in Web Development, MySQL | No Comments »
Posted by Matt on 27th November 2006
I’ve found this script works best for getting the users IP address. Still spammers can mask their IP address from this.
Code (php)
-
$user_ip = $_SERVER[‘REMOTE_ADDR’];
-
if (trim($user_ip) ==
‘’) { $user_ip =
$_SERVER[‘HTTP_CLIENT_IP’];
}
-
if (trim($user_ip) ==
‘’) { $user_ip =
$_SERVER[‘HTTP_X_FORWARDED_FOR’];
}
Posted in PHP Code Snippets | No Comments »
Posted by Matt on 27th November 2006
If you’re just trying to find a replace a string in a MySQL table, you don’t need to write a script to do it. You can simply use the following syntax with MySQL (e.g. phpMyAdmin, MySQL shell access)
UPDATE TABLENAME SET COLUMNNAME = replace(COLUMNNAME,”FINDWHAT”,”REPLACEWITHWHAT”);Note that this method is case-sensitive. This is a great timesaver over doing it with a scripting language such as PHP. With PHP, you’d have to write a script to select the row, do the replacement, and update the table.
Posted in Web Development, MySQL | No Comments »
Posted by Matt on 27th November 2006
Coulter Pine Trees (Pinus coulteri)
5 Gallon size Coulter Pine trees for sale. 19 available. $40/ea or make offer for all 19. Moving, must sell, grown from seed, in pots, ready to go. They are are from 1997-99. Excellent health.
Coulter Pines are almost impossible to find at any nursery, they are native to the lower portions of the San Bernardino and San Gabriel (local) mountains. Very nice looking tree at all ages. They produce large heavy cones that are a tan-yellow color with edible seeds. They have needles that are up to 14″ long for adult trees and have a deep green to greenish-blue color. Adult trees have long, sometimes swooping, robust branches. They do well in the high desert, just add water. They are slower growing than most of the common nursery pines, but they are the closest thing we have to a native pine tree here in the high desert. They exhibit a very nice classic pine tree shape with a broad spread.
See some pictures here:
http://www.desertmud.com/trees/
Pictures taken on April 20, 2004. Trees have grown some since the pictures were taken.
Pictures at bottom of the page show full grown Coulter Pines.
Also available:
9 x 1 gallon size Ponderosa Pines - Small cone Southern California Variety ($10/ea)
1 x 1 gal Jeffery Pine ($10)
3 x 2 gal Coulter Pine ($15/ea)
1 x 5 gal Italian Stone Pine ($20)
Posted in Miscellaneous | No Comments »
Posted by Matt on 27th November 2006
Recently our main office needed some employee lockers. We looked at the internet and found a great company called Lockers Depot. They are based out of Southern California so we were able to pick up the lockers ourselves to save on the shipping costs which for lockers are quite hefty. We placed our order and were able to pick up the lockers 3 days later. Assembly of the lockers was easy thanks to the instructions provided and now we are set with 42 bright new locker units.
Posted in Miscellaneous | No Comments »
Posted by Matt on 27th November 2006
I’m trying to plan for next year’s mountain bike race season by keeping track of good days vs bad days on the bike and what I’ve done that may have caused it to be a good day or bad day in the preceeding days/weeks.
To do this I’ve been keeping some cycling training logs that allow anyone to signup for free for cycling training logs. The logs feature color coded days so it is easy to visually pick out color coded trends and then read the corresponding data to see what may have caused the specific trend. With this I hope to be able to better plan out my good days on the bike for race day.
So far I have about 2 months of cycling log data collected and can’t draw any specific conclusions.
It seems for me that potatos lead to good performance, along with a good run 2 days before a big ride. My legs seem to perform better on the bike when they are sore from another non-cycling activity, like running, that I do not do that often.
It’s always hard to get much sleep the night before a race because for me it usually means getting up real early and driving an hour or 2 to arrive to the race an hour or 2 early. I’ve found that it’s best for if I get 9 hours of sleep 2 nights before and then the usual 4-5 hours the night before. 2 days in a row of 4-5 hours sleep make for a bad race day.
Try the logs out by creating your free cycling training log account.
Posted in Cycling | No Comments »
Posted by Matt on 27th November 2006
I got a laugh out of this page titled “Target Heart Rate for Fat Burning”
http://xfile007.blogspot.com/2006/06/target-heart-rate-for-fat-burning.html
It has some basic heart rate info, but scroll down to the 4th picture.
Posted in Cycling | No Comments »
Posted by Matt on 27th November 2006
I’ve noticed recently that I have more power than many people on the flats but when it comes to the climbs I am usually suffering as the same people start passing me. I wondered why and found this good article about it here:
http://www.flacyclist.com/content/perf/hi_pwr_hills_or_flats.html
From this it seems that because I have more power on the flats and less on the hills, I could get faster than the people passing me on the climbs by loosing weight. Problem is I don’t have any weight to loose. I’m already 15 pounds lighter than I was last year and that was all upper body muscle loss. Another thing that doesn’t make sense is the people that pass me on the hills who I in turn will pass on the flats, some of them are larger than me. If they were smaller I can attribute it to their weight but being larger and a better climber but not good on the flats doesn’t make sense according to this article and the physics involved.
Maybe I just suck at climbing.
Another interesting link is at
http://www.cptips.com/climb.htm
Posted in Cycling | No Comments »