Category Archives: programming

UNIX find writeable files – more creative

In a follow-up to my previous post, I got tired of typing things.  And so I came up with this script:



# Put arguments into an array

# If no arguments, set firt value to current dir.
if [ -z "${args[0]}" ]; then

# Loop over supplied paths and find writeable files
for arg in $args; do

  find $arg -type f -perm /u=w  | grep -v "\.class" | grep -v tmp-bin | \
grep -v aTest | grep -v fixToStuff | grep -v build/ | grep -v gensrc/ | \
grep -v Reference | grep -v "~" | grep -v "classes" | grep -v "buildtree"



My only detail to sort out was exactly how to refer to $@.  Apparently if you quote it (being exactly “$@”) that takes all the arguments as a single string.  Unquoted, it takes them separately and gets what I’m looking for.

As you can see, I also have a lot of cruft I don’t want to see in my results, so I use good ol’ “grep -v” to weed it out.  Yes, I know there is a way to use egrep to make that all one command, but for some reason it doesn’t always want to play nicely for me.  So in a classic “eff it, let the script deal with it” I just chain some pipes.  I think if I had thousands of files to sort through, this would suck.  But I don’t, so it doesn’t.

UNIX find writable files

Way back when, I posted about using find and grep.  I have learned a couple of things since then.

1) find your critiera | xargs grep your grep criteria … is nicer to your processor, memory, and quickly returning the results.

2) finding writable files.  This has been particularly useful when using a really backwards SCS that doesn’t integrate nicely, cleanly, or usable with an IDE.

My command:  find . -type f -perm /u=w

So simple. So elegant. So simply says “find all files in this directory, recursively, that are writable by the user/owner”. The one confusing thing I had about this was /u instead of /o. I figured “owner, group, world”, but it is actually “user, group, other(s)”.

Anyway, this has improved my programming life.  Yeah, I’m gonna say it… take that, Windows.

diff in ‘nix environments

After a long silence… he surfaces!  I have a couple of things to say, but I’m going to start with a very simple pleasure: diff.  First, let me clarify that I generally love the command line.  But in a world of many different pieces that all have different importance, I have come to appreciate what GUI tools have to offer.  I find the compare functionality in something like eclipse to be handy in an efficiency++ way.  So when I go back to the command line for something like this, it is because nothing else can truly replace it… like the beauty that is vi.  ;D

The short story is this:  diff -w -B -y -W 200 {file1} {file2}

Now some of you are reading that and saying, “No kidding.  Welcome to the real world.”  The rest of you may be saying “gonk… gonk… goo gonk.”  So to quote the help on diff:

  • -w:  ignore all white space (like tab expansions and changes to white space)
  • -B:  ignore changes whose lines are all blank (just in case the above is finicky)
  • -y:  output in two columns
  • -W 200:  make the output 200 columns wide (this permits both files to be displayed in full width, with room, assuming 80 char width)

I have yet to find a graphical diff tool that can manage that so nicely.  The side-by-side output is very clean and I can redirect it to a file if I want to.  Smooth, simple, elegant.  And if there’s a way to improve on this, I hope a casual passerby will comment!


Interview Techniques

Interview Techniques… you are probably wondering what that has to do with technology.  This is partly to do with technology, partly a way for me to remember these, and partly, well, a ramble as usual.  I have been exposed to some simple interview techniques for “software engineering” positions and they are worth remembering.  These have come in a variety of difficulties, so I will attempt to organize them as such.

First, technology!  See Mike Code, is cool.  It is a way an interviewer can ask simple questions over the phone and see the person write the code.  That gets a darn cool in my book.  Perhaps it is as modern as VHS is these days, but who says a technology needs to be on the order of Star Trek to warrant recognition?

Also, I recently found this:  It is excellent for automatically formatting HTML/XML and code for posting in a blog.

Beyond the technology is the questions I have either been asked or found in my own prowling around.  These are thing ones I find to be the most interesting.

Practical Questions:

  • fizz-buzz, written in any language — basically, for some multiplier of a loop print “fizz”, for a different multiplier write “buzz”.  For a multiplier equal to one divisible by A and B, write “fizzbuzz”.
  • given two lists (e.g., friends lists), and assuming list-2 represents changes affected upon list-1, who was added, who was removed, who is the same.  Written in any language.
  • Extend a standard Java class (e.g., HashMap) such that it meets new constraints such as, and using HashMap as an example:
    • limit the number of values that can be stored popping off the oldest when a newer one is inserted
    • disallow overwriting an existing key; key/value must be removed first
    • lock the list if three unsuccessful attempts are made to retrieve a value
    • lock the list if three unsuccessful attempts are make to insert a value (e.g., inserting an existing key)
  • web application to retrieve basic statistics from somewhere like flickr, using web app technology of choice

Conceptual Questions:

  • What information should a bug tracking system have?  How should it be stored?
  • What project did you make the most difference on?  What did you learn?  What would you do differently?
  • Create an interface from a legacy system to a newer UI.  Assume an API or web service exists.  Describe the architecture you would use; describe high-level design considerations; define milestones.
  • A database has been demonstrating progressively degrading performance (either via an application or reports).  What diagnostic steps would you take?

Mean Questions:

  • I file lists like this as mean because they contain a lot of questions that either a person knows from practical use, or can look up.  To put someone on-the-spot to answer deep details like this in an interview is merely a test in making the interviewee squirm.  To me, these questions are a lot like asking a mechanic about metallurgy — while they use metal in their daily work, but they don’t need to know the minute details about the metals they use to get their job done or do their job well.

Eclipse Project Natures

I recently made the horrible, horrible mistake of adding JavaScript support to my eclipse project.  After a bit of searching around I found absolutely no help on how to reverse this.  The answers I found basically said that once a kind of support/nature is added to a project, you are just up the creek.  Reversing it is nigh on impossible.

Not so!  Rejoice!

Here is my project file that gave me so much trouble:

<?xml version="1.0" encoding="UTF-8"?>
  <name>blah blah blah</name>

Okay, kids. Can you take a SWAG at what to remove?  Yeah, I thought so.  You are now one up on official responses from the Eclipse project.

I removed the obvious buildCommand element-block (…javascriptValidator) as well as the jsNature nature element.  A rebuild of my project no longer brought eclipse to its knees.

On another note, a super cool thing is that when I created this project, it did not have Groovy support.  Guess what I did to add that.  Of course, this isn’t official, and certainly not supported.  But it worked because I have the necessary plug-ins installed.

As a side note, it very well may be the case that there is detritus left behind.  Simply removing these elements may not completely clean up what “Right-Click-on-project | Configure | Convert to JavaScript Project…” may have added for files.  However it turned off eclipse from doing a lot of extra parsing and compiling that caused garbage collection and loop errors.  (Yep, I tried fixing those errors first, but it seems that with the volume of js files I have that eclipse just cannot handle that.)

Groovy, Grails, and Gradle. Oh My!

My long silence has largely been due to unemployment followed by starting a new job. I have a draft post waiting in the wings regarding some technology I observed during the interview process. Things certainly have changed since the last time I interviewed for jobs, and not just since I interviewed for my first technical job.

I am going to abstain from mentioning my company, but I can talk about some of the technology pretty freely. I have moved from working with EMC|Documentum products to working with eCommerce tools. It is still content management in some ways, but I am now more focused on making a product work as apposed to installations and integrations. In doing this, I am also working with Groovy, Grails, and Gradle. They are pretty neat technologies which I sorely underestimated. I should have started using these in my last job!

Groovy: It is Java with many additions. It isn’t some poor little scripting language, but definitely takes Java programming to a new level. You simplify a lot of what you are doing, add the power of closures, and do away with specific declarations when you don’t really care what the object is that you are working with. That is pretty nice. I’ve decompiled some of the classes created with “groovyc” and it is crazy what happens to permit the many assumptions to be made about what a class might do. This doesn’t result in compact byte-code, but it makes coding a lot easier!

Grails: Maybe this could have been used. It is a bit light weight for a full-blown web server, but for a development environment it is pretty cool. The integration of unit, integration, and functional tests is darn nice. It helps to promote a test-driven development model.

Gradle: This really blows my mind. It takes ANT to a whole new level where you can do Groovy coding in your build script to improve the build process. Let’s say you have some modules you need to build in one order, and then clean up in a reverse order. That is a nuisance with ANT, but with Gradle you can declare an array and then iterate over it in the appropriate direction in the appropriate target. Very nice!

So, yeah. My technology juices are flowing again. Hooray!

Steps in the KDE development direction

I embarked on a simple investigation today:  get kdevelop setup on one of my machines so I could start learning how to develop under KDE.  The first lesson was to get my environment right (Kubuntu 64-bit 10.04):

525  export KDEDIR=/usr
527  export KDEDIRS=/usr
535  export LD_LIBRARY_PATH=/usr/lib/kde4:/usr/lib/qt4:$LD_LIBRARY_LIB
537  export LD_LIBRARY_PATH=/usr/lib/kde4:/usr/lib/qt4:/usr/include/KDE:$LD_LIBRARY_LIB
539  export KDE4_INCLUDES=/usr/include/KDE

Then came the actual coding which, once the above was done, was quite easy.  I followed the tutorial here and modified it slightly to add a custom “No” button.  Simple small step, but progress nonetheless!