general Java

Kegs & code

I attended the kegs & code last night. It was a code challenge and party with cash prizes that was hosted by Saltt Ventures. I had never attended a code challenge or hack-a-thon or anything like that, but I figured it is good to get out of your comfort zone every now and then and try something new. Plus when they have free beer that is a pretty big perk. The beer was supplied by BrainDead Brewery which I hadn’t had prior to this event. The event started out as a happy hour with pizza and beer and then at some point we setup and the challenge began. It was a race to solve 10 problems in the quickest amount of time with first place getting $500, second $250 and third $100.

The scoreboard
The scoreboard

I setup my laptop and opened up a new IntelliJ project to work in. Looking around I saw a whole mix of people doing different things. The one contestant that I knew Rocco was using a macbook and I suspect programming in Ruby since he is a Rails programmer. I saw someone programming on a little netbook which is funny to see as he then pulled out a huge keyboard and mouse, so his keyboard was much larger than his machine. I saw some people with Python on their screen as well. So it is pretty much pick whatever tools you are comfortable in to solve the problems. The rules that were given to us were that if you submit 10 wrong answers you are disqualified so up front you already have to be somewhat conservative and double check the questions.

The start screen
Waiting for the challenge to begin…

The contest began and the first question displayed a sha1 hash that was a result from the word kegs with a 4 digit hexadecimal value appended to it. I quickly went out and downloaded Apache Commons Codec so I could use its DigestUtils.sha1Hex class, to spit out a hex string after you run sha1 on it. I executed my code and quickly came up with a result of c0de.  The original hash presented was bdcb2013c555b6ff440a0b51ddf9c49284f48d9e

Next we were presented a json map that had integer values as a key and text as a value. You were instructed to decode it. Basically if you appended all the keys in the right order you ended up with a sentence that was the answer. Here is the original json: [[7,\" t\"],[33,\"n.\"],[14,\" B\"],[30,\"du\"],[28,\" p\"],[0,\"I \"],[23,\"te\"],[25,\" i\"],[24,\"st\"],[2,\"n'\"],[17,\"he\"],[10,\"my\"],[1,\"do\"],[26,\"t \"],[29,\"ro\"],[32,\"io\"],[19,\"I \"],[18,\"n \"],[11,\" c\"],[12,\"od\"],[15,\"ut\"],[16,\" w\"],[13,\"e.\"],[8,\"es\"],[22,\"I \"],[21,\", \"],[31,\"ct\"],[4,\"al\"],[27,\"in\"],[9,\"t \"],[6,\"ys\"],[3,\"t \"],[5,\"wa\"],[20,\"do\"]]

With this problem I considered using gson or Jackson. I haven’t actually written any gson code in over 3 years and I am used to using Jackson in the context of Spring where everything is setup for you.  I quickly determined that it would take me longer to set those libs up to do the problem than to just solve it by looking at it, so I did that to move on. But I chalk that up to a lesson learned for next time on preparation for this type of event.

The next challenge we were presented with the following string: gv qrxvy V qan yevt n qrffvx V We were asked to rot13 the string and then reverse the string and replace the world girl with squirrel and then upper case that string as our answer. I googled up a rot13 algorithm that I found on stack overflow and used.

The next challenge question was a block of text:

"Ecstatic advanced and procured civility not absolute put continue. Overcame breeding or my concerns removing desirous so absolute. My melancholy unpleasing imprudence considered in advantages so impression. Almost unable put piqued talked likely houses her met. Met any nor may through resolve entered. An mr cause tried oh do shade happy.\n" +
"\n" +
"She travelling acceptance men unpleasant her especially entreaties law. Law forth but end any arise chief arose. Old her say learn these large. Joy fond many ham high seen this. Few preferred continual sir led incommode neglected. Discovered too old insensible collecting unpleasant but invitation.\n" +
"\n" +
"Savings her pleased are several started females met. Short her not among being any. Thing of judge fruit charm views do. Miles mr an forty along as he. She education get middleton day agreement performed preserved unwilling. Do however as pleased offence outward beloved by present. By outward neither he so covered amiable greater. Juvenile proposal betrayed he an informed weddings followed. Precaution day see imprudence sympathize principles. At full leaf give quit to in they up.\n" +
"\n" +
"Living valley had silent eat merits esteem bed. In last an or went wise as left. Visited civilly am demesne so colonel he calling. So unreserved do interested increasing sentiments. Vanity day giving points within six not law. Few impression difficulty his use has comparison decisively.\n" +
"\n" +
"At every tiled on ye defer do. No attention suspected oh difficult. Fond his say old meet cold find come whom. The sir park sake bred. Wonder matter now can estate esteem assure fat roused. Am performed on existence as discourse is. Pleasure friendly at marriage blessing or.\n" +
"\n" +
"Examine she brother prudent add day ham. Far stairs now coming bed oppose hunted become his. You zealously departure had procuring suspicion. Books whose front would purse if be do decay. Quitting you way formerly disposed perceive ladyship are. Common turned boy direct and yet.\n" +
"\n" +
"Way nor furnished sir procuring therefore but. Warmth far manner myself active are cannot called. Set her half end girl rich met. Me allowance departure an curiosity ye. In no talking address excited it conduct. Husbands debating replying overcame blessing he it me to domestic.\n" +
"\n" +
"Consider now provided laughter boy landlord dashwood. Often voice and the spoke. No shewing fertile village equally prepare up females as an. That do an case an what plan hour of paid. Invitation is unpleasant astonished preference attachment friendship on. Did sentiments increasing particular nay. Mr he recurred received prospect in. Wishing cheered parlors adapted am at amongst matters.\n" +
"\n" +
"Assure polite his really and others figure though. Day age advantages end sufficient eat expression travelling. Of on am father by agreed supply rather either. Own handsome delicate its property mistress her end appetite. Mean are sons too sold nor said. Son share three men power boy you. Now merits wonder effect garret own.";

We were instructed to count the number of words in the block of text that only used letters from the first half of the alphabet. For this problem I found myself wishing I was better with Java 8 Lambas and Streams as this seemed like a perfect problem to stream through the test and then do reductions until we are left with what we want to count. However since I am still a beginner on the Java 8 functional style I slammed out the traditional imperative style. I split the block of text into words. I iterated the array of words and converted them to lower case and then iterated through each letter. I took advantage of the fact that a char in Java is a 16 bit unsigned integer. I found the ascii value for the letter m which is 109 (for lowercase) and then said if the value of the char was > 109 then we break out of the loop and don’t count the word otherwise we increment the count. That worked great and it was on to the next challenge.

I had actually forgotten about this question until just now when I am reviewing my code from the event. This question was given a list of numbers convert them all to binary and count how many one’s there are in those binary numbers. Then take that count and convert that number to binary and that is the answer.  The numbers we had to convert were as follows: 533, 239, 1144, 51, 217, 247, 312, 0, 941, 1060, 805, 158, 1020, 1038, 748, 834, 36, 460, 688, 276, 2, 112, 91, 297, 954, 245, 885, 37, 1120, 803, 551, 257, 654, 1101, 948, 1050, 524, 607, 336, 883, 17, 524, 66, 399, 343, 368, 389, 741, 841, 196, 303, 20, 190, 828, 940, 825, 941, 258, 385, 14, 650, 427, 118, 44, 152, 709, 112, 554, 183, 22, 711, 772, 865, 986, 399, 957, 358, 759, 306, 94, 577, 980, 396, 451, 441, 829, 145, 62, 566, 138, 899, 1010, 383, 449, 745, 560, 586, 489, 117, 56, 508 For this problem I just slammed all the numbers into an array iterated the array and appended the binary value to a StringBuilder using Integer.toBinaryString(). Then I went character by character through the string builder and counted the ones.

The next challenge was to count the number of numbers between 0 and 10^8 that divide evenly by 13 and also if you reverse the number the reversed number also divided by 13 evenly. So for example if 1234 divided evenly by 13 check if 4321 also divided evenly by 13, and if so count it. This was a pretty easy problem to solve basically iterate in a loop and do a couple of modulus operations.

Then I hit the next question. It was a database table of 20 ids and values. You were presented a db query that was something like SELECT SUM(VALUE) FROM TABLE WHERE value / key > 20 AND value / 2 NOT EQUAL 0. I quickly wrote up some java to do the algorithm and slammed the values into a map and spun there and did the result. I got the result of 1620 and I entered it and was told it was incorrect. I double and triple checked both my values and my algorithm and they looked correct. So I loaded all the data into a SQLServer database that I have on my laptop. I again got the same result 1620 which they said was incorrect. At that point I was basically blocked as I had printed out all the values at each step in the java program and could verify it was doing the right thing. After banging my head on this problem for probably 15 minutes then all the money prizes were taken. They offered to give me the value if I wanted to complete the rest of the challenges, but my thought was if I was out of the money I would rather grab a beer and chat with some people, so that is what I did. I ended up completing 60% of the challenge and had a lot of fun messing around with it.

I was discussing the problems with Rocco afterwards (whom placed 2nd). He said there was also a question about pulling something out of an Amazon S3 which I haven’t done, so that would have taken a bit of research but was probably something I could quickly google. The winner of the challenge interestingly enough actually got more than 10 wrong answers. By the rules we were given at the start of the contest he should have been disqualified but they changed the rules in the middle and said they were going to allow 25 incorrect answers. Rocco said the winner beat him by about 5 minutes.

Would I do it again? For sure, however I think before the next one I would do a little prep. First I would have a new IntelliJ project setup and just preload common libraries you are probably going to need to solve most problems. So next time I will have a bunch of things like Apache Commons downloaded and ready to go and some JSON library as well that I will have practiced with. A question worth asking is would I have an advantage programming in a more dynamic language than Java? I think if you have the advantage of a great IDE like Idea and you had a preloaded project with most common libs you are going to need for anything like this type of challenge I don’t feel you are at a disadvantage using Java. One of the biggest strengths of Java is just how rich the libraries are that you can solve most of these things with very few lines of code. Maybe if I had access to the Java 9 REPL shell it could be faster, but coding inside of my IDE is very fast. I saw some people brought external keyboards and mice. I type fast enough on my laptop I can’t see bringing an external keyboard, but I will definitely bring an external mouse next time I could speed things up with that.


The Jetbrains fiasco

This is sort of old news now, but I haven’t had a chance to weigh in yet so I figured I would type my thoughts up anyway. On September 3rd Jetbrains announced a new licensing model. As you can imagine people immediately went crazy on twitter and 15 years of developer goodwill went up in smoke. What is the issue with the new model, the biggest problem with it is that they are moving from a perpetual model where you own that version of the IDE to a rental model ala Adobe where if you stop paying your tools stop working. Even more infuriating they came out like this was doing a favor for their developers and making it cheaper. In reality it only really makes it cheaper if you are say a consulting shop that is often switching between say pycharm, webstorm and idea. Then you can save some money over the cost of 3 perpetual licenses. For pretty much everyone else it is much worse.

As soon as they saw all of this blowing up they quickly came up with another response. In the comments of the 2 articles they argued that they were giving a lower price to the current customers with a perpetual license. That isn’t exactly true. If I am a customer that as soon as my license expires I renew it can be true for a year at least as they are only guaranteeing that license price for the first year. So assuming they kept the new lower price it would be an $89 a year update to IDEA instead of $99 the current price. But for new customers the renewal is $119 for a promotional price before January and then it goes to $149 a year which is much more expensive than the current model ($199 for a personal license and $99 for an upgrade).

Another way this fails vs the current model is if I buy a license and then say an upgrade for a few years and then I am short on money I can continue to use my old version without updates as long as I want. In the new model as soon as I stop paying the software is gone. So it really does feel like owning a license to that version of the software vs renting the software.

We switched to Idea at work a little over a year ago. In that time I fell in love with that product. It really is the best IDE I have ever used. I was such a fan that when they had the save 20% sale for the 20 years of Java I decided to buy a personal license to mess around with at home. In my home use case I don’t use the tool a ton. A couple of times a month I will use it to play around with an idea I have or to experiment with some idea or technology that I may use in the future at work. But given that I make no money with it at home and it is just something to toy with I have the option when it expires to not renew for a few years and just use the tool as I do now. Unfortunately with the new licensing model Jetbrains takes that away from me. If I don’t keep paying for it monthly I don’t get to use it. I can’t justify a monthly bill for what is effectively something I just play around with when I am bored. If there is no perpetual model going forward I will use the license I have now until it doesn’t work for me anymore (probably when Java 9 comes out next year) and then I will go back to Netbeans.

Thinking about it at a professional level, at this point I was ready to advocate for the environment in any company I was working for. I truly believe their tools are better. But at the same time I don’t want to see a business I am working for held hostage by their tools. It feels like a cross between dealing with Adobe (for their monthly subscriptions) and Oracle who would allegedly threaten businesses with a license audit if one believes what they read on the internet. So on the one hand I am tempted to say we should immediately upgrade our licenses at work before the switch so we can kick the can down the road for another year before we have to make a decision on it. And on the other hand that sort of feels like rewarding them for the betrayal to the developers when they get all those license fees for everyone trying to keep their perpetual license a bit longer. Will I recommend that we stay on it if our only choice is subscription? Given what I have seen so often with corporate budgets being frozen for a period of time I would have a hard time recommending a tool that may stop working for us because we are in a spending freeze.

So I am not sure what to do, what I can say is if they don’t have a perpetual model they have probably lost me as a customer forever.



I saw some friends on Facebook discussing Duolingo. While I had briefly heard of it I had never paid attention to it. So I decided to log on and check it out. It is pretty cool, as an intermediate level Spanish speaker I wanted to see how I did on their placement test and what the classes were like.

First off it is free which is a good way to get people interested. They follow the things that it seems like all the popular sites are doing and gamify learning a foreign language. So you see your friends, and you see how much experience they have earned in the last week, month and overall. You have a streak counter (like stack overflow) to track consecutive days you are practicing (which is also important for foreign language learning so you are getting repetition daily). When you level up role playing game style you receive their virtual currency which you can save up and use to buy bonus courses. And you see all your friends events which encourage you to keep working at it so you pass them in the rankings.

All in all it is a very cool site. Additionally they have an IOS app, and I think Android as well, so I can practice on my phone too. So how did I place? I ended up placing at their level 4 for Spanish which I felt was a bit low, but I made a few rookie mistakes. There are some terms they used that aren’t common in Mexico (they are either Spanish or Latin American) so I had forgotten them and missed those questions. After playing around with it for a day I am at level 6 Spanish. I will work my way through all their Spanish content and then either play around with the German (which I haven’t really used since High School) or else the Italian which I haven’t used for about 7 years so I have forgotten most of it. The only thing the site is missing for me would be Latin. I would love to learn Latin on a site like this. They do have some unusual languages such as Esperanto and Klingon. Greek might be a cool language to have on there as well, though not sure how they would handle the different alphabet. But I guess there is a Hebrew for English speakers so I could check that out to get an idea of how they are dealing with teaching you new letters as well.

Anyway if you decide to check it out follow me at my link here.

Spring Boot Spring Framework

Spring Boot Actuator Guide

One of the most interesting Spring Boot features to me is the Spring Boot Actuator. I just love the concept of having all these restful endpoints to get useful operational data right out of the box. One issue I have had is that I don’t actually know all the endpoints just a few that I have used here and there. Today I saw a link to the Complete Guide for Spring Boot Actuator which is a pretty amazing post that covers everything and anything that you would want to know. The purpose of this post is just so I can go back and find this data later. If you are playing around with Actuators go and check out this post.