Archive by Author

Find text in Files recursively on Linux and Mac OS X

Ever had a page that says something like “Test” on it, and you have no idea where that page is? I know you have and that’s why you’re here. You’ve thought to yourself “If I could just search to find the text in files recursively it would make my life so much easier!” and it does.

I’ll give you an example. Recently I was working on a Drupal project using advanced forum and I had this ridiculous block “What’s going on?” below my forum and I didn’t want it there. Going through file by file wasn’t exactly what I envisioned my day to be so I started looking around for a simpler way to find text in files using linux but I wanted it to work on Mac OS X too because I run production on Linux and Development on Mac OS X.

The baby-making-magic time-vampire killing power is below

grep -lir "some text" *
// or
find /path -name *.txt | grep -lir "some text" *

Sample output

bmaxwell$ grep -lir "What's going on" *
./modules/advanced_forum/styles/naked/.svn/text-base/advf-forum-statistics.tpl.php.svn-base
./modules/advanced_forum/styles/naked/advf-forum-statistics.tpl.php

Obviously the first one is the svn base file for that revision so we can ignore it. The second asshole causing all of the trouble known to man-kind contains exactly what I’m trying to find so I can use my DELETE button, or modify it.

Tetco rewards cards are bullshit.
Bryan

Getting the available variables in Drupal

It’s simple but it’s a complete headache if you’ve had this problem and found this post (or a similar one) trying to do what this function does. What I mean when I say “Get available variables” or “Get the available variables in Drupal” or “Find the available variables in PHP” or any number of combinations you’re still havin the same problems.

Get the available (defined) variables in Drupal

You want the variables available to you in a PHP script. This is tailored for Drupal only because it’s the reason I came across it FOR a PROBLEM I was having in Drupal. It’s what I use this function the most for but I can see this having seriously  dynamic capabilities if used correctly (I’d elaborate, but it’s too genius… it seems. I want to play around with it first. Think Russian doll situation (while maintaining the same size, but not relationally) with a level of granularity where weight wasn’t a factor, it could be an axis position on axis’ with one object allowing large amounts of array data and non-scalar information between-themselves to be displayed at a dashboard-like interface. Maybe I’m making it a Drupal module, maybe I’m not.)

The code is!

// Get the available aka "defined" vars available to Drupal
print_r(get_defined_vars());

Pretty simple like I said but if you’ve ever been there you’ll thank me every day. Every. Single. Day.

WAM BAM THANK YOU MA’M.
Bryan

25 Google Wave Invites

Who wants one?! Post a comment!

List of Geocode APIs with Rate Limits and Features

https://webgis.usc.edu/Services/Geocode/About/GeocoderList.aspx

Don’t bother with Yahoo! or Google. They rate limit you, some of the services in the link above do not.

Function to remove all non-numeric characters in PHP

Sometimes it’s helpful to ONLY get numeric characters.
Phone numbers, age — whatever your little PHP heart desires.

function remove_non_numeric($string) {
return preg_replace('/\D/', '', $string)
}

WRAAAAAAA,
Bryan