Posts

Why shouldn't you use health checks?

Image
This is a reprint of my post on  FANDOM's engineering blog . At  FANDOM  we believe our applications should be resilient, that is they should be able to recover from failures and while the failure occurs still be useful for the users. Health checks are one of the ways to make applications self-healing. The idea is that the health checks detect when an instance of the application reaches an invalid state. A supervisor monitors those health checks and attempts to fix any issues. Depending on your platform the action might be different. Many frameworks (like Dropwizard and Spring) and platforms (like Kubernetes and Marathon) encourage you to implement health checks for your web applications. When a health check fails, AWS will  stop sending requests  to that instance. That’s pretty straightforward — we suspect the application is not healthy, so it might not respond correctly. Decreasing load on it might also help it recover. In Kubernetes, there’s a ...

Geecon 2015

Image
So last month I've attended  Geecon  and I really loved it. Geecon is a conference focused on Java and JVM technologies, hosted annually in Cracow (usually). Geecon had a Steampunk theme This year’s it was all about microservices, so it’s no surprise that I enjoyed Fred George ’s “Challenges in implementing microservices” the most. In his talk Fred George shared his experiences with replacing monolith applications with microservices. He explained how microservices facilitate a Service Oriented Architecture and “going faster” as shorter reaction time for the whole company. What was most interesting to me was the comparison of asynchronous and synchronous approaches to microservices. He mentioned his friend Chad Fowler suggests synchronous communication on default mainly because it’s easier for most of the modern programmers. In contrast Fred George believes that asynchronous messaging gives so too much of an opportunity for robustness and graceful degradation to ignor...

Creation method in Mongoose.js, alternative to custom constructor or hooks

Creation method is a neat way of creating objects in the same way by using the object's well-named static method instead of constructor. While similar, creation method should not to be confused with factory method pattern , which involves the concrete implementation of created objects). If you'd like to know more about creation method's benefits and application I highly recommend Joshua Kerievsky's Refactoring to Patterns . Here's how this alternative to custom constructor or hooks can work in Mongoose. Let's use an Article model in Mean.js app generated by Yeoman as an example: Let's say we'd like article to have an url field, which we'd like to generate from the title. We'd like to avoid copying the url generation code everytime we'd like to create an article. One way to do this is to create a creation method which does that. Since all static methods have to be defined before the model class is created creating a creation method ...

Mavenized Java server application and Angular.js frontend application using yeoman

Image
Setting up Angular.js using Yeoman In Gruntfile.js change application config, so the application is compiled into java resources Finally add build plugin to pom.xml so the js appliacation and all of its resources are built into your Java resources. Notice that for workingDirectory I'm using my directory 'ui'. The build should pass and you can deploy your appliacation to a server container of your choosing. I'm using Spring (along with Spring Boot). A simple controller like this: Should yield a result like this: I've based this article on Gunnar Hillert's Botanic-ng and my own experimentation.

Calculating values for bar charts in LaTeX

Image
The bchart package If you want to add some bar charts to your latex document you might want to use bchart. This pdf by Tobias Kuhn shows some examples of how to use the package. Description taken from that pdf: bchart is a LATEX package for drawing simple bar charts with horizontal bars on a numerical x-axis. It is based on the TikZ drawing package. The focus of this package is on simplicity and aesthetics. Using the package one can display labels, specify the axis range, bar colors or unit of the values. Calculating values Unfortunately the package has a drawback. If you use math expressions they will be calculated for the bars but wont their values won't be displayed. In addition you cannot use \pgfmathparse{} to calculate the value for the chart because it will cause errors in displaying the bars. Which renders: I believe it is due to internal usage of pgfmath of the package. There is a simple solution though, using \\pgfmathsetmacro{}{}: Which renders: ...

Setup SQL Server 2012 and Adventure Works cube with Visual Studio 2010

Image
This tutorial will show you how to deploy a cube onto SQL Server 2012 using VS2010 and might help you avoid some of the problems I've encountered. It is complementary with Multidimensional Modeling (Adventure Works Tutorial) and uses its Adventure Works db and cube project. While this  states that it is not possible to deploy a cube using Visual Studio it is no longer the case with SQL Server 2012. Prequisites Visual Studio 2010 disc or image Installed Visual Studio 2010 SQL Server 2012 disc or image Service Pack 1 for VS2010  due to this Installing SQL Server 2012 or adding required features Note: Running VS2010 during the installation might cause errors so close it. Run SQL Server Setup by selecting New SQL Server stand-alone installation or add features to an existing installation from Installation tab of the SQL Server Installation Center. Move through the process up to Installation Type . If you already have an installed SQL Server you would...

MongoDB and distinct values in arrays

This post is a mini-tutorial on how to deal with array fields in MongoDB, specifically arrays of items that may or may not be duplicated. Let's create a collection of unicorns, smilarly to  The Little MongoDB Book examples: Find should now return something like this, the _ids will vary: Adding a value into an array We've found out that our unicorn Scott also loves playing games, so lets push a new value into our document's loves array: Using push , we could insert into our the same value multiple times. Pushing a value if its unique We have found out that all our unicorns love movies and want to update the whole collection. Unfortunately Scott already has got movies in his loves field. As shown here , we can use addToSet , which won't add a duplicated value to an array: The third parameter of update is upsert (false by default). The fourth is multi which makes the query update every document that matches the criteria (false by default meaning th...

Installing FANN on Java project and NativeLibrary.loadLibrary problems with 32bit/64bit

If you try to install FANN  and get it working with a Java project you might run into a few problems. The whole process is explained on the fannj (the Java binding) project's wiki but not in great detail. Installing Fannj Get fannj Store it somewhere and add the jar to your project. Get FANN Extract it somewhere. Set up the DLL by either: copying the fannfloat.dll to System32, or adding the following line before you try to use FANN:  System.setProperty("jna.library.path", [fannfloat.dll dir path]); Solutions to common issues No Java Native "Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform" Solution : Download the JNA and add the jar to your project. Can' find the FANN library Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'fannfloat': The specified module could not be found. Solution : Add debugging code (or better yet: use a debugger) after y...

Setting up Grails project on Oracle XE database

If you have some code already working on another database, say Postgres, and you want to set it up on Oracle XE database, there are some things to consider. You have to change the application data source (conf/DataSource.groovy) and move the Oracle jdbc driver to /lib - all that is explained pretty well here . Basically the result will be something like this: You might have some troubles with the url, here is a little explanation: I'm running the XE database on my local host, hence the host is: 127.0.0.1. 1521 is the default database listener port for Oracle XE XE is the default SID for Oracle XE Oracle XE and port setup While we are talking about ports. The default http interface port for Oracle XE management through APEX is 8080 and it might be in collision with other software you are running, like our grails app. You can read on here to find out the way to check default ports and those set on your configuration and also how to change them. Oracle XE and reserve...

Android Activity.managedQuery selection and selectionArgs arguments

Most of the examples of managedQuery don't use the selection and selectionArgs arguments, others are pretty simple like : Cursor simple(String id) { return managedQuery(getIntent().getData(), PROJECTION, "id = " + id, null, DEFAULT_SORT_ORDER); } or Cursor simple(String id) { return managedQuery(getIntent().getData(), PROJECTION, "id = ?", new String [] ={id}, DEFAULT_SORT_ORDER); } Both of the above do exacly the same thing. The '?'s are the elements in the array in order they are placed. [ Resource ] I was working on a piece of code that stored IDs in SharedPreferences and then loaded the elements with those IDs into a ListView from a ContentProvider. Basically I was trying to get that : WHERE id IN ( id1, id2, id3, id4,...) So the selection argument looked like that : "id IN ( ? " +  [",? "] + " )" and the selection args stored the ID of elements I wanted to load. SharedPreferences data = getSharedPref...

Android Virtual Machine and non-ASCII characters the path

Image
I have found a job ! =) For a month (and hopefully more) I'll be working at Espeo Software. I've started last Wednesday and I've really enjoyed it so far. Currently I'm working on an android app. During its developement I've encountered a bug when trying to launch the AVM on Windows with a profile containing the letter 'Ł'. This is the message I got : ERROR: no search paths found in this AVD's configuration. Weird, the AVD's config.ini file is malformed. Try re-creating it. It appears that while the sdk can be in a folder with such a path that contains non-ASCII character the emulator does not like it. Specifically to .android/avd which on default is stored in your windows user folder. The solution is to add a local user/system variable ANDROID_SDK_HOME with the path to a place you want .android to be. For example ANDROID_SDK_HOME=C:\AndroidDev. You might have to restart your Eclipse or other IDE after doing that. But that fixed it...