Monday, 24 September 2012

IntelliJ IDEA has a built in Regex Tester

This idea is just too freaking awesome. Only just discovered it today,
so I don't know how long it's been around. I know it wasn't there the
last time I worked on a lot of Regex Java code.

A built-in Regex tester within the editing window of IntelliJ IDEA. So
you write the regex in your code, you can test it right there!

Friday, 21 September 2012

Corporate proxies blocking spam sites

Interesting. Clicked on a link in an email I got and got this message
instead in my browser:


"This Page Cannot Be Displayed

Based on your corporate access policies, this web site (URL redacted
by me) has been blocked because it has been determined by Web
Reputation Filters to be a security threat to your computer or the
corporate network. This web site has been associated with
malware/spyware.

Threat Type: spam
Threat Reason: Domain has unusually high traffic volume for a very
recent registration. IP/domain is a spam source.

If you have questions, please contact your corporate network
administrator and provide the codes shown below.

Notification codes: (1, MALWARE, spam, Domain has unusually high
traffic volume for a very recent registration. IP/domain is a spam
source., BLOCK-MALWARE, 0x476c8b41, 1348186815.265,
QAAAAAAAAAAAAAAAJf8ACP8AAAD/AAAAAAAAAAAAAAA=, URL redacted by me)"

Wednesday, 29 August 2012

Renaming files in TortoiseHg

I've only been using Mercurial for a short while, and only using
TortoiseHg, so things are still a bit unclear for me. I know, I know,
I should be reading http://hginit.com all the way through to get a
good grounding in Mercurial, but it seems to be okay so far.

I'm testing out Mercurial on a little project I have to restructure a
project to use Maven instead of Ant, so there's inevitably some moving
of directories required.

But how do you move a file in Mercurial?

This is the annoying thing, they never use that word "move". They call
it "rename". I get it, Mercurial only cares about files, but for the
sake of real-world users who still use the word "move", there could be
a bit more guidance on this, IMHO.

Anyway, how to move a directory in TortoiseHg? You go to the parent
directory using Explorer, then you right-click and select "Rename".
Then you will get a dialog box where you select the location you will
place it in. By default, it will show the existing name (ie,
"src/com") in both the Source and Destination text fields. Now for the
Destination field, click on the corresponding "Browse" button and
select the new location where you will place the directory.

IMPORTANT: Make sure the name of the directory is also in the
destination field, as the contents will be moved to whatever location
is specified in Destination.

There is a checkbox with "Copy source -> destination" - what is this for?

It turns out this is just a way for the Mercurial "copy" command being
included in the Rename dialog. It's a bit of a confusing hack, in my
opinion.

It's annoying that this is not discussed in the docos I've seen for TortoiseHg.

Found out from here:
https://bitbucket.org/tortoisehg/hgtk/issue/1124/support-for-copy-command

If you tick the checkbox, it means Mercurial will copy the files, and
not move them. You'll end up with two copies, which might not be what
you want to do.

TOP TIP:

This is not the best way to move files or directories around. The best
way is to just move them, and then go to the top of the directory,
then right-click TortoiseHg to "Guess Renames"

Wednesday, 1 August 2012

Bloody hell. Simple WSRP demo works on Liferay Enterprise, but not on Liferay Community Edition

Spent a few days trying to get a simple "Hello World" portlet working
via WSRP, using 2 instances of Liferay running on my machine. Tried
6.0 CE. Didn't work. Saw a bug related to "Adding a WSRP Consumer",
JIRA said it was fixed in Liferay 6.1. Tried it on Liferay 6.1 CE as
consumer pointing to Liferay 6.0CE as producer: didn't work.

After a few days trying things like getting specific version of the
WSRP plugin to match the version of Liferay, multiple restarts, I've
now downloaded the Enterprise version of Liferay 6.0, matching it to
what we currently use in production.

I then set up a simple portlet as WSRP producer and then WSRP consumer
on the other Liferay instance: works perfectly.

Is this what they mean by "value-add"?

Wednesday, 25 July 2012

Running multiple instances of Tomcat on different ports on same server

I wanted to run two instances of Tomcat on different ports on my
workstation, and this is what I did.

Modify these values in /[TOMCAT INSTALL DIRECTORY]/conf/server.xml.

In this example we are using "7" to replace the "8" in the port numbers

ie, 2nd tomcat to run on port 7070 instead of 8080, shutdown port is
7005, AJP connector port is 7009


<!-- DEFAULT VALUE: 8005 -->
<Server port="7005" shutdown="SHUTDOWN">

<!-- DEFAULT VALUE: 8080 -->
<Connector port="7070" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />


<!-- Define an AJP 1.3 Connector on port 8009 -->
<!-- DEFAULT VALUE: 8009 -->
<Connector port="7009" protocol="AJP/1.3" redirectPort="8443"
URIEncoding="UTF-8" />

Thursday, 5 July 2012

Adventures in legacy code: given a Map-based class, what do you think a method called getKey() should do?

Looking at some legacy code for a system that we're taking back from a
vendor. (Company has all these projects in-housing systems that used
to be outsourced) Rehost, port or rewrite?

Okay, so they created a class BundleMap that extends HashMap, and the
genius who wrote it added this incredible WTF "improvement":


/**
* Check if the key is present in the resource bundle
*
* @param key
* @return true if key is present
*/
public Boolean getKey(Object key) {
logger.debug("Returning value for key [" + key + "]");
if (super.containsKey(key)) {
return true;
}
return false;
}


AGAIN - WTF???

you already have a perfectly good method called containsKey() in
HashMap -- whatever the hell possessed you to rename it as getKey()??

Thursday, 3 May 2012

Maven dependency resolution problems caused by child module having a different parent version from top level parent pom.xml

The moral of the story is: When working on a multi-module project,
remember to update ALL pom.xml files, not just one version. Update
from the top-level often.

I'm working on a multi-module Maven project, and Bamboo (our
continuous integration server) is set up so that whenever a release is
done, the version number is incremented.

Now we have most of our dependencies set up in the parent-level
pom.xml. One of them is a client jar to our web services backend. Call
it services-client.jar

I've just spent an afternoon trying to sort out this very confusing
situation where I'd already updated the dependency in our pom.xml to
services-client-19.jar, but whenever I did a build, I would also get
services-client-17.jar.

I thought at first that it was an IDE problem, IntelliJ getting
confused with its caches, so I tried all sorts of fixes at that level
- cleared cache, recreated project file, reimport all Maven projects,
manually delete jars in settings - nothing worked.

I then went to command-line, removed all versions of
services-client*.jar from local repo, then did a build. I grep'd
through all my pom.xml files, and I saw that I only had one reference
to services-client, it was in top-level pom.xml and and it was version
19.


$ find . -name "pom.*" -exec grep -i "0.1203." {} /dev/null \;
./domain/pom.xml: <version>0.1203.0.134-SNAPSHOT</version>
./extension/pom.xml: <version>0.1203.0.134-SNAPSHOT</version>
./front-end/pom.xml: <version>0.1203.0.134-SNAPSHOT</version>
./pom.xml: <version>0.1203.0.138-SNAPSHOT</version>

While this was using services-client-19.jar:

./pom.xml: <version>0.1203.0.138-SNAPSHOT</version>

The child-level modules were pointing to an older parent pom file, one
that Bamboo already installed to our company repository.

The parent version used in the child modules:

./domain/pom.xml: <version>0.1203.0.134-SNAPSHOT</version>

Was using services-client-17.jar

So whenever did "mvn clean install" the project from the
parent-level, Maven was following this sequence when resolving the
dependencies:

1) Maven goes to child modules and builds

2) In /domain/pom.xml - it sees the reference to older parent pom,
fetches from repository, starts to resolve dependencies, fetches older
services client - services-client-17.jar.

3) services-client-17.jar gets installed in local repo

4) During build, code that uses services-client-19.jar code fails
compilation because that jar never actually gets installed until Maven
gets to the top most pom.xml

I haven't verified this with the Maven mailing list yet, this is just
my interpretation of what the problems have been.


The moral of the story is: When working on a multi-module project,
remember to update ALL pom.xml files, not just one version. Update
from the top-level often.


I have updated at the top level and the parent versions are now
consistent - 0.1203.0.140 all the way.

$ find . -name "pom.*" -exec grep -i "0.1203." {} /dev/null \;
./domain/pom.xml: <version>0.1203.0.140-SNAPSHOT</version>
./extension/pom.xml: <version>0.1203.0.140-SNAPSHOT</version>
./front-end/pom.xml: <version>0.1203.0.140-SNAPSHOT</version>
./pom.xml: <version>0.1203.0.140-SNAPSHOT</version>

Wednesday, 2 May 2012

Dear Ticketmaster Australia: if a gig is sold out, just fucking tell me. I can handle it.

What I can't handle is being treated like an idiot and having my time wasted.

The fact that searching is allowed would naturally lead any user to
think that there is something to be found. But in this case, widening
my search to "Best Available" and "Any Price" still returns nothing!
If that's the case, why allow searches at all?

Instead of wasting everyone's time letting them search for tickets
that do not exist, just mention it upfront on the site if tickets have
sold out already. Don't waste my goddamn time!

What were your marketing fuckwits thinking? "Oh, maybe they'll stay
around longer on the site and buy tickets to something else!"

That's not how it works, assholes.

We just get pissed off and tell everyone your website is a piece of shit.

Unfortunately, consumers don't have any options as you and Ticketek
have the big events pretty much between yourselves.

Fuck. This.

Friday, 13 April 2012

The cat food saga: the dry and the raw

I used to feed my 2 cats dry because my vet said so. All the places
I've been to - RSPCA, animal hospital, vets - sold mostly dry food
like Hills Science so I figured that was accepted good practice. Main
complaint I would have was the stink of their poo. One of the cats has
always been fanatical about covering up his offerings, but it still
had a strong smell despite being buried in the litter. In the mornings
my wife would always wake me up way earlier than I'd like to make me
clean up the litter boxes.

Then a recent spell of cat gastro made me change their diet to mainly
raw meat, and it's completely all for the better. In Australia, wild
kangaroo meat is commonly sold as raw pet food. Kangaroo meat is very
lean, as kangaroos are not farmed animals. It's all from the wild.

Now i'm not 100% sure if it was the change to raw meat or if they were
already getting better. The smell is gone in the mornings. The stench
of the litter boxes don't fill up the house. It's possible it was just
something in that particular dry food didn't agree with them, but I
wasn't prepared to go and try out umpteen kinds of dry food to test
that theory.

Another impact of this is that they're using the litter box way more
to urinate, and it was starting to get expensive with the clumping
litter, but I've started trying out crystal litter which seems way
better and less expensive at dealing with cat wee. From the number of
times they urinate,I would say they now consume a lot more water
because of the wet food diet.

The transition to raw food was actually pretty uneventful. While
dealing with the gastro issues I did a timeout of 24 hrs on feeding
them, and this gave us a break on the cleanup and made them very
hungry and pretty receptive to ANYTHING that I gave them. They
finished their first bowl of raw meat very quickly! One of them was a
bit reluctant so for a few days I gave him his own mix with raw meat
and dry food.

I've started using canned cat food as backup, in cases where I'm out
of raw food or it hasn't thawed out yet. I've found this more
agreeable with them than switching back to dry food, or mixing wet and
dry in the same bowl. They still seem to be sensitive with changes to
diet, so I've just stuck to some canned brands that they like. I still
have some leftover Felidae, so the dry food remains as a last resort
or on the few times that I can't feed them myself.

Monday, 13 February 2012

Mystical spam message of the day

Found some truly mystical spam in my inbox today:

The coach with six horses was waiting at the porch.
Suggestion area: Barge in Now
Wholeheartedly your, Neiford Brandkamer.

Friday, 13 January 2012

Q: What is a blog?

Q on Yammer:

"now what about the question - is an online journal the same as blog?
although technically a blog is a weblog, blogs have grown into a
public domain where people discuss and banter over a certain topic or
discussion raised by the blogger. an online journal on the other hand
could be a dear diary or a "whate happened to me today". any thoughts
on this?"

A:

a blog is a blog
you can use it to share
or you can use it to care
you can use it to joke
or you can use it to poke
you can talk to other people
or stay alone in your steeple

its just a way to go 'bla bla bla'
and the only difference is
WHY you go 'bla bla bla'

(apologies to Dr Seuss)

Wednesday, 11 January 2012

Reintegration merge in SVN using TortoiseSvn

Currently doing some reintegration merges in SVN, and one thing
tripped me up. I forgot to commit the mergeinfo file that got created
during the merge!! This would have meant that SVN would have no
knowledge that a branch was already reintegrated back into trunk (or
another branch).

The process using TortoiseSVN would be:

For example, where we are merging big_branch_1 into trunk

1. Checkout trunk into working directory and go into this directory in Explorer

2. Using TortoiseSvn right-click and select TortoiseSvn --> Merge

3. On the Merge dialog box, select "Reintegrate a branch" radio
button, click Next

4. Under "Tree merge", and under "From URL" select the branch we want
to reintegrate, then click on Next.

5. Under "Merge options", you can select options such as ignoring or
comparing whitespace differences, etc.
I normally click on "Test merge" so it can go through a test of the
merge and show in advance any potential conflicts. (I haven't seen
any, but I think that's what it does)

7. Click on "Merge", and fix any conflicts that come up.

6. After that's done, do a commit, and put in an appropriate message
to indicate what you've done

7. NOTE 1: During the commit, make sure "Show unversioned files"
checkbox is ticked

NOTE 2: There will be an additional, unversioned change listed in the
commit list. At first I thought it was a new file, but it's actually
an updated SVN property.
The svn:mergeinfo property make sure you commit this change,
otherwise, SVN doesn't know that a branch has been reintegrated.

If you leave out this file from a commit, all that SVN knows is that
you put in a bunch of changes to a number of files.

In one earlier merge, I rolled back the "file". So I just went back
into that directory, ran through the merge again, and committed the
updated svn:mergeinfo.
There shouldn't be any other changes to commit since the changed files
have already committed. I only did this so that svn:mergeinfo was up
to date.

Some information in this post may be incorrect as I've never had to do
these types of merges before. I'll update them once I've read up more
on this.

Further reading:

http://durak.org/sean/pubs/software/version-control-with-subversion-1.6/svn.branchmerge.basicmerging.html
http://www.collab.net/community/subversion/articles/merge-info.html

Wednesday, 9 November 2011

Senseless corporate doublespeak sample #001

Original text:

"Through these discussions, we have also identified opportunities to
change the role of PC&S in ways that will better support the execution
of the IT strategy. By specifically leveraging the discipline and
framework of the SMO, as well as accelerating the decision to combine
this function with the PMO function, we can focus on our sourcing
strategy and continue the emphasis on agile roll out and our people
leadership program."

What I think it means:

This role will be abolished. Some of its functions will be done by someone else.

Wednesday, 19 October 2011

Steve Jobs on customer experience (WWDC 97)



(the quote starts from 1:55)


You've got to start with the customer experience and work backwards to the technology. You can't start with the technology and try to figure out where you're gonna try to sell it.
...
It started with "What incredible benefits can we give the customer? Where can we take the customer"? Not starting with "Let's sit down with the engineers and figure out what awesome technology we have and how are we gonna market that?" And I think that's the right path to take.



Thursday, 13 October 2011

Note to self when using java regex - always call Matcher.matches() so that text matching actually happens

The general pattern of usage is:

1. regexString = [REGEX]
2. final Pattern p = Pattern.compile(regexString);
3. final Matcher matcher = p.matcher(text_to_match);
4. matcher.matches() 


DO NOT FORGET to call Matcher.matches().

Otherwise you will get messages like:

java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Matcher.java:468)

and you'll be wondering why because you have confirmed that the regex itself is correct. (http://www.fileformat.info/tool/regex.htm and http://rubular.com/ are useful tools for doing this quickly)

REMEMBER: call .matches() so that our Matcher actually performs the matching!

Just wasted 10 minutes wondering what I was doing wrong.


Tuesday, 13 September 2011

Use Windows path separators if you're using the JDK keytool in Windows - backslash "\" not forwardslash "/"

This error "keytool error: java.io.IOException: Keystore was tampered
with, or password was incorrect" may not really mean a password or
keystore problem.

Here's my story:

Kept trying various passwords to add a certificate to my JRE CA using
this command:

./keytool.exe -v -alias certalias -import -file <DomainRootCA>.crt
-keystore ../jre/lib/security/cacerts

And I kept getting

keytool error: java.io.IOException: Keystore was tampered with, or
password was incorrect
java.io.IOException: Keystore was tampered with, or password was incorrect
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:771)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:38)
at java.security.KeyStore.load(KeyStore.java:1185)
at sun.security.tools.KeyTool.doCommands(KeyTool.java:715)
at sun.security.tools.KeyTool.run(KeyTool.java:172)
at sun.security.tools.KeyTool.main(KeyTool.java:166)
Caused by: java.security.UnrecoverableKeyException: Password verification failed
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:769)
... 5 more

I tried various passwords. My usual default passwords. "changeit" -
which is usually default for these certs. Nothing worked.

Then remembering how bad these java exceptions are, I changed the
keystore parameter, to see if it would complain about not seeing the
file.

Just remove the "s" from "cacerts"

[everything to the left of this is still the same] -keystore
../jre/lib/security/cacert

And still got the same error. Bloody JDK! So maybe it was failing
because it couldn't find the file, but it wasn't being shown in the
error message.

So I changed my path references to backlash "\" instead of "/", even
though I was doing all these under cygwin bash shell.

./keytool.exe -v -alias certalias -import -file <DomainRootCA>.crt
-keystore ..\jre\lib\security\cacerts

Using the first password I tried, "changeit"

And it worked.

The lesson:

1. JDK error messages suck!
2. When using keytool.exe on Windows, make sure your path separators
are "\" and not "/". The fact you're running under bash shell doesn't
affect it.
Remember: Use Windows-based path separators if you're using the JDK
keytool in Windows

Saturday, 10 September 2011

Are you using iPhoto by *its* rules? Make sure your understanding of iPhoto terms is correct.

AAARGH!! Almost buggered up my iPhoto library. Was using "Flagged
photos" to mark favourite photos. Then accidentally selected "Create
Event From Flagged Photos" while trying to split an Event.

Result? An event containing 1000 photos from 2008 to today. And good
thing I Googled it first, because an event is actually like a folder
of photos. So deleting an event would have deleted all the photos in
it. All my favourite photos from my entire library, going back to
2008. Dammit.

But thank <deity> that "Edit -> Undo" can also reverse that operation.

Be careful of "Create Event From Flagged Photos" if you're treating a
"Flagged photo" to indicate a Favourite photo. This is not really what
it's for. Flagging a photo is probably meant for short-term
operations, in the context of creating an event or album going across
multiple windows of photos.

This is where following the rules and reading a bit more would have
helped. The model I *think* I should have been following was:

Event - Physical directory of photos.
Album - Virtual collection of photos.
Album - can have photo from any events
Smart Album - can have photos based on search criteria
Folder - a collection of Albums or Smart Albums

Remember:

Deleting an Event will delete the photos.
Deleting an Album will not delete the photos.

You should only Flag a photo to maintain a temporary list before
either moving them to an Event or Album. Normally I should put them in
an Album, since I like to keep photos grouped by date on the
filesystem. When I was on Windows using Picasa my workflow was to
first rename any new photos in a photo_upload directory using the
program "jhead" then running a Ruby script to move them into
date-based folders using each photo's EXIF metadata.

Don't keep them for longer than that, lest you mistakenly create an
Event and shove photos from different times into the same folder. If
that happens make sure to go to Edit -> Undo before doing anything
else.

This link cleared things up for me:

http://docs.info.apple.com/article.html?path=iPhoto/8.0/en/6443.html

Friday, 26 August 2011

Just discovered SVN switch command - switch to a different branch instead of doing a full checkout

I've been doing complete checkouts whenever our branches get renamed,
instead of using "svn switch". Not a small pain considering it takes 8
minutes to do a full checkout. Good thing this doesn't happen that
often (and probably the reason I haven't discovered the command. not
painful enough). How embarrassing!


Quick example of using SVN's "switch" command

$ cd calc

$ svn info | grep URL
URL: http://svn.example.com/repos/calc/trunk

$ svn switch http://svn.example.com/repos/calc/branches/my-calc-branch
U integer.c
U button.c
U Makefile
Updated to revision 341.

$ svn info | grep URL
URL: http://svn.example.com/repos/calc/branches/my-calc-branch

Only fewer files need to be updated. More time to read Hacker News. =)

REF: http://www.linxit.de/svnbook/en/1.1/ch04s05.html