Archive
ack – Better than grep?
I stumbled onto a really nice command line tool named ack while reading a StackOverflow question yesterday. Living at the domain betterthangrep.com/, it purports to .. be better than grep. Or, as they put it
ack is a tool like grep, designed for programmers with large trees of heterogeneous source code
I’ve written previously about how to combine find and grep, and really, ack exists to obviate the use of find and grep. It ignores commonly ignored directories by default (e.g. all those .svn metadata folders that SVN insists on creating), and with a simple command line flag you can tell ack what sort of files you want searched. Furthermore, because it recurses by default, you don’t need to use the find command to traverse the tree.
Using the todo example, a basic way of searching for the TODOs in all of our java files is to use the command
find . -name "*.java" -exec grep -i -n TODO {} \;
In ack, this is accomplished much easier:
ack -i --java TODO
Furthermore, the matching results are highlighted right away, making it extremely apparent where the matches occur.
I’m going to start using this at work and see if it can replace my grep/find hackery. Will let you know. Very impressed so far.
If you want to give it a try, the easiest way to install it is with macports:
port install p5-app-ack
Give an indication of why a button is disabled
0to255.com – find lighter/darker shades of colors
Color choosers are a dime a dozen online, but 0to255.com is a very nice one. Its stated purpose is to allow you to specify a color and then find shades that are darker and lighter than that color. It’s very well designed, aesthetically pleasing, and has the good sense to allow you to copy the hex value of the color with a single click.
I use it on a semi-regular basis to design Java Swing UIs; just a quick tip for the Java folks out there – when you have the hex code copied, you need to preface the hex string with 0x for the Color constructor to work correctly. In other words, if you are have the hex string #facade, you would create a Java color object with the command new Color(0xfacade). The 0x tells the Java compiler to treat the following text as hexadecimal.
Two shortcuts for NetBeans navigation
Jump to any file in any open project
⌃⇧ O
Search for string
Increase heap size for NetBeans Platform project
To increase the heap size in a NetBeans Platform project, you can edit the nbproject/platform.properties file and add the line
run.args.extra=-J-Xmx1G
, replacing the 1G piece with however much memory you’d like. (The other solutions I found did not work for me). Thanks to the NetBeans Forums for this solution.
If you’re curious about the -J piece, it’s necessary to ensure that the arguments are passed to the JVM rather than interpreted by NetBeans itself. This should work in general for whatever arguments you want to pass to the JVM upon launch of your NetBeans Platform project.
Customize code formatting in NetBeans
if (cond1) { } else { }
After unsuccessfully searching online, I eventually stumbled onto some settings that control this behavior. By default, NetBeans wants to format your if/else statements as follows:
if (cond1) { } else { // 'else' is on the same line as the closing brace }
If you want to have a new line after your closing brace, as I do, you need to change some settings.
Make sure the “else” checkbox is checked in the “new lines” section. Customize the rest of it to suit your coding style.
Excel 2008 for Mac’s CSV export bug
Excel 2008’s CSV export feature is broken. For instance, enter the following fake data into Excel:
Row | Name | Age |
0 | Nick | 23 |
1 | Bill | 48 |
When you use standard unix commands to view the output, the results are all garbled.
[Documents]$ cat Workbook1.csv 1,Bill,48[Documents]$ $ wc -l Workbook1.csv 0 Workbook1.csv
$ file Workbook1.csv Workbook1.csv: ASCII text, with CR line terminators
# convert the Workbook1.csv file into a Unix appropriate file dos2unix Workbook1.csv WithUnixLineEndings.csv
tr '\15' '\n' < Workbook1.csv # remove the carriage returns, replace with a newline Row,Name,Age 0,Nick,23 1,Bill,48