Archive for scripting

10 letter words with no duplicate letters

egrep '^[a-z].{9}$' /usr/share/dict/words \
| awk '{ 
    ok = 1; 
    for ( i=1; i<=length($0); i++) { 
        c = substr( $0, i, 1 );  
        if ( counts[ c ] ) { 
            ok = 0; 
            break; 
        }
        counts[ c ] = 1;
     } 
  if ( ok ) print $0;
  delete counts; 
}'

Leave a Comment

Convert camel case to all caps underscored

Convert camel case to all caps underscored:

$ echo -e 'SomeNiceHTTPCandyTCPSocketWrapper\nSimpleExample\nMoreHTTPFun' \
  | sed 's,\([A-Z][A-Z]*\)\([A-Z]\),\1_\2,g;s,\([a-z]\)\([A-Z]\),\1_\2,g' \
  | tr '[a-z]' '[A-Z]'
SOME_NICE_HTTP_CANDY_TCP_SOCKET_WRAPPER
SIMPLE_EXAMPLE
MORE_HTTP_FUN

Leave a Comment

styling gnuplot

So… I like gnuplot a lot, but out of the box, it looks terrible.

I mean it looks great as far as informational use, but not so great for the sexy, sexy.

I don’t really get that into it, but it doesn’t make the same splash as some goofier js toolkits, etc.

So… I went thru tons o’ dox, turned to svg terminal and did some minor post production work with a script

% for f in min max mean ; do grep -w ${f} test* ; done | awk '{print $NF > $1}'
% TITLE="Time Ranges by Test Run" XLABEL="Test Run" YLABEL="Time in Seconds" \
gello.sh min mean max 

That first crazy line gets the min,max and mean from the test file and splits each one out into a separate file (thx awk!)

SEXY!

Leave a Comment

making m2 salad

Irrelevant Silliness

So… I’m a vim hold out. I still care deeply about emacs and it’s spawn being defeated once and for all.

Which means I don’t really like bloated IDE’s like Eclipse…. which makes me a pariah… which means people whisper and plot against me behind my back…

And… they’re always out to get me… and…

Ahem… sorry, about that… Like I was saying….

Which means I prefer to write a lot of tools and utilities to provide the sort of out-of-the-box functionality other people are perfectly happy to point and click thru with their brains in the neutral gear.

It’s part of a sickness I have… and I am going to confess it here on the internet: I love programming computers.

I know, I know… appalling! The gall! But there it is! My dirty little secret!

So what have I brewed up this time?

You know that functionality which lets you see right click and see methods, etc in Eclipse?

I thought it would be nice to have something like it for the CLI where I can use grep the way the Lawd intended. Here is the soup-to-nuts for nuts.

Finally he gets to the point

% m2_salad.sh 
m2_cp.txt is older than pom.xml... rebuilding m2_cp.txt
m2_soup.txt is older than m2_cp.txt... rebuilding m2_soup.txt
m2_salad.txt is older than m2_soup.txt... rebuilding m2_salad.txt

Zounds! So I wrote 2 new scripts: m2_soup.sh and m2_salad.sh.

Like m2_cp.sh, each produces a file named X.txt with some junk in it.

Here is the breakdown:

m2_cp.txt      colon separated list of the jars maven uses
m2_soup.txt    list of all the classes defined in the m2_cp.txt jars
m2_salad.txt   javap of all the classes listed in m2_soup.txt

These along with the standard UNIX CLI utils provides the same sort of handy lookup funtionality, where it belongs: in the CLI, not in the editor.

And?

Well… OK, maybe it could live in the editor too if it was slim-and-fast and minimalist…

I’ve really enjoyed the vim plugin supertab for tab completion.

Part of the challenge of integrating it with the output from the scripts is to make the completion be contextual… Which means a plugin would have to have some notion of the program semantics.

For example, it would need to know that a piece of text was a variable and what it’s type was so it could lookup the appropriate methods.

Not easy, but I’m a big believer in the 90/10 rule.

Alternatively… what other sort of useful development application could be written leveraging this info?

Good times… good times…

Leave a Comment

noun chunking with openNLP

This is pretty much straight from the openNLP README

% echo "The openNLP project is also pretty cool, LGPL and it doesn't cost $3000" | ./textMe.sh 
[NP The/DT openNLP/JJ project/NN ] [VP is/VBZ ] [ADVP also/RB ] [ADJP pretty/RB cool/JJ ] 
,/, [NP LGPL/NNP ] and/CC [NP it/PRP ] [VP does/VBZ n't/RB cost/VB ] 000/CD

The script is dumb:

_textMe_main() {
    local classpath="output/opennlp-tools-1.4.3.jar:"
    classpath="${classpath}:$( find lib -name "*.jar" |xargs |tr ' ' ':' )"
    local jMe="java -classpath ${classpath}"
    ${jMe} opennlp.tools.lang.english.SentenceDetector  \
        english/sentdetect/EnglishSD.bin.gz                     \  
    | ${jMe} opennlp.tools.lang.english.Tokenizer            \
        english/tokenize/EnglishTok.bin.gz                       \
    | ${jMe} opennlp.tools.lang.english.PosTagger -d       \
        english/parser/tagdict english/parser/tag.bin.gz   \
    | ${jMe} opennlp.tools.lang.english.TreebankChunker \
        english/chunker/EnglishChunk.bin.gz
}   

_textMe_main ${*}

Break it down:

% echo "This is a sentence? I know this is, Mr. Funzone... What will happen?" | ${jMe} opennlp.tools.lang.english.SentenceDetector english/sentdetect/EnglishSD.bin.gz
This is a sentence?
I know this is, Mr. Funzone... What will happen?
% echo "This is a sentence?" | ${jMe} opennlp.tools.lang.english.Tokenizer english/tokenize/EnglishTok.bin.gz
This is a sentence ?
% echo 'This is a sentence ?' | ${jMe} opennlp.tools.lang.english.PosTagger -d english/parser/tagdict english/parser/tag.bin.gz
This/DT is/VBZ a/DT sentence/NN ?/.
% echo 'This/DT is/VBZ a/DT sentence/NN ?/.' | ${jMe} opennlp.tools.lang.english.TreebankChunker english/chunker/EnglishChunk.bin.gz
[NP This/DT ] [VP is/VBZ ] [NP a/DT sentence/NN ] ?/.

Leave a Comment

Print the name of any class in a jar that has a main method:

Print the name of any class in a jar that has a main method:

jar="output/opennlp-tools-1.4.3.jar"
javap -classpath ${jar} $(     
    jar tf ${jar}      \
    | grep ass$        \
    | cut -f1 -d.      \
    | tr '[$/]' .      
) \ 
| tr '\n' '@'          \
| sed 's,}@,}=,g'      \
| tr '=' '\n'          \
| grep -w main         \
| tr '@' '\n'          \
| grep '^public class' \
| awk '{print $3}'

Leave a Comment

upload a file to crx via sling and webdav

###############################################################################################
# some variables and aliases
secret="admin:admin"
host="crunky"
port="7402"
path="content/test_2009_12_18"
base="http://${host}:${port}/${path}"
file="x.xml"
alias crx="curl -u ${secret}"

###############################################################################################
# make a directory to put junk in
crx -X MKCOL "${base}"

###############################################################################################
# put/get sling style 
crx -F"sling:resourceType=application/xml" -F"content=@${file}" ${base}/sling_test.xml
crx http://crunky:7402/content/test_2009_12_18/sling_test.xml/content

###############################################################################################
# put/get webdav style
crx -T ${file} ${base}/webdav_test.xml
crx http://crunky:7402/content/test_2009_12_18/webdav_test.xml

Leave a Comment

Older Posts »