Bryan Geraghty

Author Archive

A Script To Remove PHP Closing Tags

by Bryan on Jul.14, 2010, under Programming

If you are a PHP developer, you may or may not know that it is becoming popular to omit the closing PHP tag in class files as it’s not necessary and it avoids the possibility of a space at the end of the file causing frustration in various situations. If you’ve ever had to remove these tags from a large number of files, you know how tedious it can be. Well, no more; here is a script to do just that. Just change into the directory containing the files to be stripped, and run ‘php-remove-closing-tag’.

The script makes use of the awk, pcregrep, sed, and wc utilities to get the job done. You may need to install some or all of them to make the script work. If you are a developer, you will probably have all of them installed anyway.

Download Source

Source Code:

#!/bin/bash
# vim:ft=sh:ts=3:sts=3:sw=3:et:

###
# Strips the closing php tag `?>` and any following blank lines from the
# end of any PHP file in the current working directory and sub-directories. Files
# with non-whitespace characters follwing the closing tag will not be affected.
#
# Author: Bryan C. Geraghty 
# Date: 2009-10-28
##

FILES=$(pcregrep -rnM --include='^.*\.php$' '^\?>([\s\n]+)?$(?!\n)' * | head -n 1);

for MATCH in $FILES;
do
   FILE=`echo $MATCH | awk -F ':' '{print $1}'`;
   TARGET=`echo $MATCH | awk -F ':' '{print $2}'`;
   LINE_COUNT=`wc -l $FILE | awk -F " " '{print $1}'`;
   echo "Removing lines ${TARGET} through ${LINE_COUNT} from file $FILE...";
   sed -i "${TARGET},${LINE_COUNT}d" $FILE;
done;
Leave a Comment :, , , , , , more...

Linux ACL Management Functions

by Bryan on Jan.07, 2010, under Programming, Security

Traditional file system permissions management in Linux leaves most users wanting. Fortunately, there’s a feature that most linux users don’t even know about called ACLs and it’s most likely already available on your system. All you have to do to enable it is add the `acl` option to your volume in `/etc/fstab` and re-mount the volume.

Once that is done, here are some functions that I wrote to help manage these ACLs.

Here is an example of a command that grants apache permission to read a directory with these functions:

> source aclfunctions.bash; grantUserRead 'apache' /var/www '*';

aclfunctions.bash:

# Author :: Bryan Geraghty
# Date :: 2009-10-28
# Notes :: ACL management functions

##
# Resets permissions on all files and directories in the specified path and removes
# and ACL entries
#
# @param string $2 Base path Path in which all operations will take place
#
function resetAll
{
   echo "Resetting permissions on all files in directory $1";

   echo "Removing ACLs...";
   setfacl -Rb $1;

   echo "Resetting directories...";
   find $1 -type d -exec chmod 770 {} \;

   echo "Resetting files...";
   find $1 -type f -exec chmod 660 {} \;
}

##
# Grants read permissions to all files/folders with names matching $3, which reside
# inside of directory $2, to user $1.
#
# @param string $1 Username The user to whom read permissions will be granted
# @param string $2 Base path Path in which all operations will take place
# @param string $3 Target Name of the file/directory on which to set the permissions
#
function grantUserRead
{
   echo "Granting read permission to user $1 on files/folders named $3 in directory $2";

   ## Set the default permissions for new files on the specified directory
   echo "Setting defaults...";
   find $2 -name "$3" -type d -exec setfacl -d -m u:$1:rx {} \;

   ## Recusively set the permissions on all existing directories and files within the
   ## specified directory
   echo "Setting directory permissions...";
   find $2 -name "$3" -type d -exec setfacl -R -m u:$1:rx {} \;

   ## Grant permissions to any files with the specified name
   echo "Setting file permissions...";
   find $2 -name "$3" -type f -exec setfacl -m u:$1:r {} \;
}

##
# Grants write permissions to all files/folders with names matching $3, which reside
# inside of directory $2, to user $1.
#
# @param string $1 Username The user to whom read permissions will be granted
# @param string $2 Base path Path in which all operations will take place
# @param string $3 Target Name of the file/directory on which to set the permissions
#
function grantUserWrite
{
   echo "Granting write permission to user $1 on files/folders named $3 in directory $2";

   ## Set the default permissions for new files on the specified directory
   echo "Setting defaults...";
   find $2 -name "$3" -type d -exec setfacl -d -m u:$1:rwx {} \;

   ## Recusively set the permissions on all existing directories and files within the
   ## specified directory
   echo "Setting directory permissions...";
   find $2 -name "$3" -type d -exec setfacl -R -m u:$1:rwx {} \;

   ## Grant permissions to any files with the specified name
   echo "Setting file permissions...";
   find $2 -name "$3" -type f -exec setfacl -m u:$1:rw {} \;
}

##
# Grants read permissions to all files/folders with names matching $3, which reside
# inside of directory $2, to group $1.
#
# @param string $1 Group The user to whom read permissions will be granted
# @param string $2 Base path Path in which all operations will take place
# @param string $3 Target Name of the file/directory on which to set the permissions
#
function grantGroupRead
{
   echo "Granting read permission to group $1 on files/folders named $3 in directory $2";

   ## Set the default permissions for new files on the specified directory
   echo "Setting defaults...";
   find $2 -name "$3" -type d -exec setfacl -d -m g:$1:rx {} \;

   ## Recusively set the permissions on all existing directories and files within the
   ## specified directory
   echo "Setting directory permissions...";
   find $2 -name "$3" -type d -exec setfacl -R -m g:$1:rx {} \;

   ## Grant permissions to any files with the specified name
   echo "Setting file permissions...";
   find $2  -name "$3" -type f -exec setfacl -m g:$1:r {} \;
}

##
# Grants write permissions to all files/folders with names matching $3, which reside
# inside of directory $2, to group $1.
#
# @param string $1 Group The user to whom read permissions will be granted
# @param string $2 Base path Path in which all operations will take place
# @param string $3 Target Name of the file/directory on which to set the permissions
#
function grantGroupWrite
{
   echo "Granting write permission to group $1 on files/folders named $3 in directory $2";

   ## Set the default permissions for new files on the specified directory
   echo "Setting defaults...";
   find $2 -name "$3" -type d -exec setfacl -d -m g:$1:rwx {} \;

   ## Recusively set the permissions on all existing directories and files within the
   ## specified directory
   echo "Setting directory permissions...";
   find $2 -name "$3" -type d -exec setfacl -R -m g:$1:rwx {} \;

   ## Grant permissions to any files with the specified name
   echo "Setting file permissions...";
   find $2 -name "$3" -type f -exec setfacl -m g:$1:rw {} \;
}

##
# Grants execute permissions to all files/folders with names matching $3, which reside
# inside of directory $2, to user $1.
#
# @param string $1 Username The user to whom read permissions will be granted
# @param string $2 Base path Path in which all operations will take place
# @param string $3 Target Name of the file/directory on which to set the permissions
#
function grantUserExec
{
   echo "Granting execute permission to user $1 on files/folders named $3 in directory $2";

   ## Set the default permissions for new files on the specified directory
   echo "Setting defaults...";
   find $2 -name "$3" -type d -exec setfacl -d -m u:$1:rwx {} \;

   ## Recusively set the permissions on all existing directories and files within the
   ## specified directory. One command will siffice for files and directories when
   ## setting execute permissions
   echo "Setting directory and file permissions...";
   find $2 -name "$3" -exec setfacl -R -m u:$1:rwx {} \;
}

##
# Grants execute permissions to all files/folders with names matching $3, which reside
# inside of directory $2, to group $1.
#
# @param string $1 Group The user to whom read permissions will be granted
# @param string $2 Base path Path in which all operations will take place
# @param string $3 Target Name of the file/directory on which to set the permissions
#
function grantGroupExec
{
   echo "Granting execute permission to group $1 on files/folders named $3 in directory $2";

   ## Set the default permissions for new files on the specified directory
   echo "Setting defaults...";
   find $2 -name "$3" -type d -exec setfacl -d -m g:$1:rwx {} \;

   ## Recusively set the permissions on all existing directories and files within the
   ## specified directory. One command will siffice for files and directories when
   ## setting execute permissions
   echo "Setting directory and file permissions...";
   find $2 -name "$3" -exec setfacl -R -m g:$1:rwx {} \;
}
1 Comment :, , , more...

Software Engineering: Over-Engineering

by Bryan on Sep.18, 2009, under Programming

I’ve been a software developer for 10 years and since I can remember, I’ve heard this term being passed around as if it were the bane of any software project: over-engineering. In the early years, I was a novice in a shop full of seasoned developers, so I absorbed every bit of sage advice like a sponge. This idea that you shouldn’t over-think things because you’ll end up with a system that is far more complex than it needs to be made sense. Unfortunately, it seems as though the original intent of this phrase has been lost to the current generation of programmers. From my experience, it seems that far too many developers have interpreted this phrase to mean “do no engineering at all”. Complex systems are created one line at a time by trial and error. Let me point out right away that this article is by no means an attack on people developing software this way. This is my attempt to reach out and help improve the state of the industry. Hopefully, it will make all of our lives a little easier.

When I re-examine the phrase now, the entire concept of over-engineering seems laughable. The purpose of engineering is to design an optimal solution to a practical problem. How can you make a system worse by thinking more about how it can be improved? I think this oxymoron of a concept has stemmed from two possibilities. This first is that these developers don’t understand the role of engineering and the second is that they don’t understand the project requirements.

I’ve experienced the first condition firsthand. When I was a pup, I thought software engineering was creating software from scratch. I created every bit of it, so I must have been the engineer! Unfortunately, it turns out that those projects simply had no engineer at all. There weren’t even specific requirements of the system before I started writing code. I had a rough idea of what it needed to do, so I created it the best way I knew how: by trial and error. This was a gross misunderstanding of the role engineering on my part. I’ve since learned that software engineering is much like any other type of engineering.

One major qualification required of an engineer is a deep understanding of all of the available materials. If an electrical engineer doesn’t understand the difference between paper and plastic capacitors, their circuit may not hold up under certain conditions. If a mechanical engineer doesn’t understand the tensile strength of iron vs aluminum, they may not make the best decision when deciding which to use. In either case, it’s possible that the person in question could design a solution to the problem; it may even turn out to be a good one. But a true engineer would understand all of the costs, strengths, and weaknesses of all of the available materials. They would be able to make a scientific decision about which should be implemented. This same principle is applied to software engineering. If you don’t understand the costs, strengths, and weaknesses of the available technologies, how can you make an informed decision about which to implement?

Another major qualification of an engineer is to understand the problem in its entirety. If an architect is asked to design a home but does not consider whether it will be built on an island where little electricity is available, in a desert, or in the middle of a metropolitan city, it’s likely that something won’t work out. This is an extremely obvious example, but the point I want to illustrate is that the person who wants the house built may not understand all of the issues that need to be considered. It is the job of the engineer to be able to see these issues in the design stage and raise the appropriate questions when necessary. Otherwise, you may end up with a very expensive sculpture. In the realm of software, a client may ask for a custom CRM package but doesn’t mention that they want it to be usable offline. A software engineer needs to be able to foresee this type of issue and raise questions. I’ve seen too many systems built where nobody stepped back to look at the big picture. There would be an immense focus on getting a small task done and when it was finished, it turned out that it couldn’t be implemented as needed or someone on the next team had already solved the problem.

The final qualification I’ll highlight is the ability to create documentation. You could engineer the perfect system but if it’s not spelled out specifically, details get lost. By the time a project enters the development stage, all of the questions need to be answered in writing. Nobody would expect a contractor to build a structure without a blueprint. Neither would you build a complex circuit without a schematic. The same should go for software. Every detail should be spelled out on paper before anyone even starts dreaming of code. There will be plenty of revisions, for sure. But the problems found at this stage will take far less time to correct than in the development stage.

The qualifications I’ve mentioned are things that we need to start seeing more of in software development. It’s a cop-out to say, “It’s my code, nobody else will ever touch it.” or, “I don’t have time to create documentation.”. I’ve inherited too many extremely complex projects left behind by people who said these very things. I’ve even been guilty of doing those things in the past. It’s time to evolve. To me, the fact that the National Vulnerability Database posts 20+ new vulnerabilities a day illustrates that we’re doing something wrong.

Lets make a change.

Leave a Comment :, , more...

Finally, A Decent XPS M1730 Bag!

by Bryan on May.30, 2009, under Photography

For Christmas this year, I received a Dell XPS M1730 Laptop to help facilitate my home studio recordings. This laptop will happily handle anything you can throw at it but it has one undesirable trait: its size. What Dell fails to advertise is the fact that this is largest 17″ laptop on the market and it won’t fit into most 17 inch laptop bags because its dimensions are 16″x12″x2″. It’s a monster when you compare it to a 17-inch MacBook Pro at 15.4″x10.4″x1″. Dell does offer a very nice back-pack case designed specifically for this laptop. The problem with it is the fact that it was specifically designed for this laptop. There is not much room left for anything else and the bag itself is huge which makes for quite cumbersome travel.

The real problem I have, is that I take my SLR camera and some extra lenses with me everywhere I go. Anytime I travel, I also take my laptop. So far, this has meant carrying either more bags than I’d like, or over-stuffing one. As we all know, over-stuffing isn’t a great option for delicate equipment.

Dell XPS M1730, meet the Tenba Shootout Photo/Laptop Courier bag

The internal dimensions of this bag are a perfect fit at 16.5″x12″x7″. The icing on the cake is that Tenba is a renowned manufacturer of camera cases and they seemingly had my struggle in mind when they made this one. So far, I have loaded my laptop, the power supply, mouse, memory card reader, and my SLR in the bag. Everything is neatly divided and there is still tons of space; but most importantly, everything is well-protected.

Well done, Tenba.

1 Comment :, , , , , , , more...

Mesa/Boogie Subway Rocket Sound Clips

by Bryan on May.19, 2009, under Music

About a month ago, I purchased a Subway Rocket and said I would put some sound clips up. It’s taken a while, but I’ve finally gotten around to it. Well, I got around to making one :)

Sound Clips:

Mesa Boogie Subway Rocket Tone – Contour Mode

I’ll post the others soon, I promise!

Leave a Comment :, , , , , , more...

Mesa/Boogie Subway Rocket

by Bryan on Apr.10, 2009, under Music

The Mesa/Boogie Subway Rocket is the newest addition to my recording studio; it’s a 22 Watt vacuum-tube guitar amplifier.

Tone Controls - Mesa Boogie Subway Rocket

Specs

  • 2 Channels: Rhythm and Lead+Switchable Contour
  • 3 Band Shared EQ
  • 22 Watts: 4×12AX7 Preamp Tubes & 2xEL84 Power Tubes
  • Parallel Effects Loop with Mix Control
  • 8-4-4 OHM Outputs
  • Eminence 10″ 50 Watt 8 OHM Speaker (Labeled as Vintage Black Shadow)

On to the details

I have been considering making the jump to a tube amp for a while but the cost has always put me off. I have a collection of solid state amps that have given me great tone and I could never find a tube amp for less than $1000 that sounded significantly better than the amps I already had. Nevertheless, any time a new reasonably-priced tube amp shows up in my GC (Guitar Center) catalog, I have to go try it out. It was on one of these treks where I encountered the Subway Rocket.

I went into GC specifically to try out a second-hand Crate V33 they had priced to move. After ten minutes of tinkering, I was completely turned off. But I figured while I was there, I’d have some fun. So I grabbed a nice Strat and plugged into the ol’ standby: the Fender Blues Junior. The Blues Junior has always held a certain quality that attracts me. Set the gain at 7, roll back the volume on a bridge-position single coil, and let the tubes sing. I’ve always loved the sound, but I could never justify spending $600 on an amp when I have an old $200 Fender Automatic that cries quite beautifully in it’s own (albiet, solid state) right. Well, while I was enjoying the tone pouring from the Junior, I glanced over and spotted a small combo amp with the logo which has become sort of a holy grail for me: Mesa/Boogie.

I think the main reason Mesa/Boogie has reached holy grail status for me is that I never thought I would be able to afford one. I’ve been a fan of John Petrucci (of Dream Theater) for along time and his guitar tone is what set the bar for me. Any time he plays you’re sure to see a wall of Mesa/Boogie cabinets and his trusty Mark IIC+ amp heads. Those heads alone sell for $2500+, and since I’m not making a living off of my guitar playing, I could never justify spending anywhere near that amount of money on an amp. But man, is the tone incredible.

Now, my first thought as I looked at this unassuming combo amp was, “That has to be some kind of marketing gimmick”. I thought that there was no way Mesa could get the wall of tone that they’re famous for into a 10″ combo. But just for fun, I decided to plug in a see how it sounded. After five minutes, I was completely sold; this amp is amazing.

I’ve now had it for a week, I’ve put it through it’s paces, and I have to say, I’m still completely sold. The rhythm channel on this amp at half gain is the silkiest, smoothest blues grit I’ve ever heard. Flip it into the lead channel with the gain at 8 and you’re in metal land. Step on the contour switch and stand back! Even though it’s a 10″ combo, this thing will make your ears bleed. I set the lead channel volume at 2 in my recording room (a huge open room with vaulted ceilings) and I couldn’t take it for more than a couple of minutes; I had to turn it down. My final test was to throw an SM57 in front of it to see how it would track to “tape” without too much fuss and I wasn’t disapointed. That magical thing about microphones is that they don’t care how big the speaker is; it sounds monstrous. I’ll have some clips of the recording up here shortly.

In a final word, this amp is the perfect studio guitarist/owner’s friend. It’s extremely versatile and because it was built by Mesa/Boogie, it is truly a professional piece of equipment. Just by looking at it, you get the impression that it was built to last. If you’re a guitarist in the market for your first tube amp, I HIGHLY recommend seeking out one of these amps. This is one piece of gear I will never sell.

More Photos

Mesa Boogie Subway Rocket
Toggle Switches -Mesa Boogie Subway Rocket
Tone Controls - Mesa Boogie Subway Rocket
Rear - Mesa Boogie Subway Rocket
Rear Closeup - Mesa Boogie Subway Rocket
Footswitch - Mesa Boogie Subway Rocket

Thanks for stopping by!

1 Comment :, more...

Yamaha NS-4 Speakers

by Bryan on Mar.21, 2009, under Music

A couple of years ago when I was visiting my dad, he was setting up for us to do some guitar jamming when I saw a distinctive logo on a couple of speakers collecting dust. As I looked closer, the label read “Yamaha NS-4″ and the model number imediately brought to mind the iconic NS-10M. I turned to my dad and asked if he knew much about them but he said he didn’t. He said someone had given them to him a few years prior and that they hadn’t even been plugged in for a while. I mentioned that these could be some significant speakers to which he replied, “I’ll mail them to you if you want them”. A few months later, true to his word, the NS-4s showed up on my doorstep.

Yamaha NS-4 and NS-10M Studio

Since receiving them, the NS-4s gained a permanent place on my mixing desk. I knew that they wouldn’t be true reference monitors, but to be honest, these speakers are amazing. Paired with my NS-10Ms, they make a great a/b team.

Related to the NS-10M?

Earlier this month, I decided to try and find out if there was any significance between the NS model numbers. Now, anyone who knows the recording industry has heard of the NS-10M. If you look through a recording magazine, you’re bound to find at least one photo of a studio with a pair of the iconic, white-woofered, NS-10Ms sitting on the the console. Why they’re so popular is a subject of much debate. Some engineers will say that they are really unforgiving and will only sound good if the mix is good. Others will say that it’s merely the result of some great engineer mentioning that they used them and it caught on. I won’t go into that argument here; Suffice it to say, they’ve been used to mix thousands of great records.

Interestingly, it seems as though there may be some relationship between the NS-4 and the NS-10M afterall.

I found this post on the following: http://thewombforums.com/showthread.php?t=3835&page=3

Bob Olhsson says:

Bob Clearmountain and a bunch of us LOVED the mixes we got using Yamaha NS-4s.

Lots of studios had them on hand because for a few years during the ’80s they were the biggest selling speaker having dethroned the JBL L-100. They had dethroned the Advents and before them the KLH6s.

Unfortunately Yamaha discontinued the NS-4 and the amount of professional use quickly depleted Yamaha’s stock of original replacement drivers. They came up with a substitute but it wasn’t the same at all translation-wise. The closest thing Yamaha made to the NS-4 was the NS-10 which was a smaller “high end” version. When the Power Station finally ran out of NS-4 drivers, they put in NS-10s. Clearmountain thought they were brighter but sort of the same so he put tissue over the tweeters.

He got a write-up about a Stones album he mixed that included mention of the NS-10s with tissue over the tweeters. Next thing we knew, virtually every studio in the world had NS-10s with tissue over the tweeters sitting on their consoles.

I’m not sure how much truth there is to that post but according to Bob’s website, he’s been recording since 1965 and I’m inclined to believe him.

Well, whether the NS-4s played a signifigant role in recording history or not, I sure do love them. If anyone has any more information about these speakers, I’d love to hear it!

2 Comments :, , , , , more...

Valley Of Fire State Park

by Bryan on Mar.15, 2009, under Photography

After talking with some friends at work and seeing some brochures, my wife and I decided that it was finally time to head out to the Valley Of Fire National Park which is only about an hour from our house. I have to say that the driving experience is incredible. I’m an auto racing enthusiast and my wife would probably attest that I drive in quite a “spirited” manner. For people like me, this place is a dream come true. On top of the great driving experience, the view is outstanding. I would often crest a hill and my wife and I would say, “Wow…”, in unison. Then I’d quickly spot a place to pull over and we’d get out and snap some photos.

I’m pretty happy with some of the photos that I got but I have to say that they don’t give the place any justice. The thing I noticed right away was that the scenic pull-offs were always just far enough down the hill from a fantastic view that the most I could achieve was a decent shot. You could attribute this to my lack of skill or nice equipment, but I found myself wishing I had my camera mouted to the car so I could snap photos from the road. Maybe that’s something to persue… :)

It was a fun trip but a word to the wise: If you or a passenger is prone to motion sickness, make sure they take some Dramamine ;)

Photos

Valley Of Fire State Park
Valley Of Fire State Park
Valley Of Fire State Park
Valley Of Fire State Park
2 Comments : more...

A New Desk

by Bryan on Mar.12, 2009, under Music

One of the afformentioned projects that I finished up recently is a new desk. I took woodshop classes in High School and I’ve always loved building things but I’ve never really had the opportunity to build anything substatial. I’ve built a TV riser and a few odd things around the house but nothing that would get your attention. After a few hours with some graphing paper, I had my optimal design.

Unfortunately, the selection of local lumber in Las Vegas is a bit slim so my design was limited by the selection available. I already knew I wanted 100% hardwood, so I looked at what they had at the local Home Deopt, made some quick calculations in my head, and asked them to cut me a few pieces of Red Oak and Maple.

About 2 hours of measuring and cutting, 6 hours of sanding, and a few hours waiting for glue to set, I had my finished product.

Photos

Red Oak And Maple Grain Detail
Handy leg posts
Mixing desk sans laptop
My Home Studio
Vaulted Ceiling
Leave a Comment :, , more...

To anyone who is looking for old content

by Bryan on Mar.12, 2009, under Updates

Hang in there. I’m still learning how to use Wordpress, so bear with me ;)

2 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...