Posts

Showing posts from March, 2015

Sort a set of strings by each string's last character, solution 2

Here's another solution to the same problem, this time I am not using a comparator. Instead, I reverse each element, save it in a new TreeSet which keeps elements in sorted order, then instantiate a new LinkedHashSet which maintains an insertion order, reverse the strings again to the way there were. What I noticed doing this problem is that this solution is faster with larger sample size than solution with comparator. That's a surprising revelation. Also, using StringBuilder to reverse a string is a lot faster than reversing character by character. package com.ervits; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Objects; import java.util.Set; import java.util.TreeSet; /** * * @author Artem * @created Mar 27, 2015 2:15:49 PM * * Project SetSorter * */ public class SetSorterWithReverseString { public static void main(String[] args) { long start = System.curren...

Sort a set of strings by each string's last character, solution using comparator (Update)

I have the following problem. Sort a set of strings by each string's last character. This is my implementation, please suggest other solutions. UPDATE turns out I had a bug in my previous version, I was only comparing the last character to last character and on the return from the method, it would ignore every other word with same last character. It was only noticeable after a much larger sample set. package com.ervits; import java.util.Comparator; import java.util.Objects; /** * * @author Artem * @created Mar 27, 2015 2:07:21 PM * * Project SetSorter * */ class LastCharComparator implements Comparator { public LastCharComparator() { } @Override public int compare(String t1, String t2) { Objects.requireNonNull(t1, "passed String1 cannot be null"); Objects.requireNonNull(t2, "passed String2 cannot be null"); final int result; if(reverseWithStringBuilder(t1) ...

Running saved sqoop 1.4.4 jobs with password file

This has been bugging me for a long time. I've been trying to pass password to sqoop job securely for the longest time with no avail. Apparently, my approach was flawed by two things. First of all, the sqoop user guide 1.4.4 has incorrect spelling for password file option in the example. The documentation has the correct option but if you're like me and follow the example you will get it wrong. wrong way in Sqoop 1.4.4 user guide: sqoop import --connect jdbc:mysql://database.example.com/employees \ --username venkatesh --passwordFile ${user.home}/.password right way in Sqoop 1.4.5 user guide: sqoop import --connect jdbc:mysql://database.example.com/employees \ --username venkatesh --password-file ${user.home}/.password the other flaw is that when you create the password file with "echo" command, make sure you don't append a new line character to the password. Here's a handy script to create a password: echo -n "password...