Recentily I’ve been playing a little bit with Docker and Meteor, at the beginning, everything was ok but as soon I started to use settings.json file to define properties I started to face some issues, Node complaints about the JSON structure and Docker complaints about the syntax.

Problem with node

In my host machine, Meteor was parsing and using settings.xml without any problems as usual.

meteor --settings settings.json

But after building the application and trying to start it with Node I got a beautiful “METEOR_SETTINGS are not valid JSON”. What? Yes, the common solution for it just passes the settings.json direct to METEOR_SETTINGS what is correct, it expects a JSON not a path so, doing this would solve the problem.

export METEOR_SETTINGS=$(cat settings.json)

Ok, problem solved right? Not so fast my friend.

Problem with Docker

With that information in my hand, I basically put that snippet in my docker-compose.yml like that.

environment:
    - MONGO_URL=mongodb://mongo/dashboard
    - ROOT_URL=http://dashboard
    - PORT=3000
    - NODE_ENV=production
    - METEOR_SETTINGS=$(cat /bundle/settings.json)

All right! That’s it! Nope.

Now Docker didn’t like “$ at the end of environment variable causes “Invalid Interpolation” error”. Ok, it’s documented, if we have to use $, we need to escape it, using another $ in front of it.

- METEOR_SETTINGS=$$(cat /bundle/settings.json)

It worked! Docker accepted that! But was not good for Node, now METEOR_SETTINGS has $(cat /bundle/settings.json) as value, definitely not what I needed.

I tried using { instead of (, tried “, ” with (, ” with {, one $, two $, so on and nothing.

The Solution

Is it possible to use the same JSON format, but without using the settings.json file, just set it programmatically. Using underscore.js defaults to doing it, you’ll not even have to change anything in the properties structure.

Meteor.startup(function () {
    _.defaults(Meteor.settings, {
        "private": {
            "jira": {
                "credentials":{
                    "accessToken":"accessToken"
                },
                "get-all":{
                    "endpoint":"https://jira2.iggroup.local/rest/api/2/project"
                },
                "statuses":{
                    "endpoint":"https://jira2.iggroup.local/rest/api/2/project/{project}/statuses"
                },
                "search":{
                    "endpoint":"https://jira2.iggroup.local/rest/api/2/search"
                },
                "issue":{
                    "endpoint":"https://jira2.iggroup.local/browse/"
                }
            }
        }
    });
});
Conclusion

Meteor working as usual without any weird workaround on top of it, just an alternative to save some hours or prevent you from using some fancy 3rdparty plugin that has nothing to do with your project.

 

Hello there!

Today just inspired by a post where I was referenced by Camila hope she doesn’t get mad because I’m revealing her name lol at dev4devs blog, I would like of first thank her for the mention and then say few words about why starting a blog.

Well, the motivations can be the most different ones like money, self-marketing, network or how Camila said.

I started to write this blog for save my map minds, drafts, notes and pieces of code and I decided to share it with the community as a knowledge base.

The thing is that she’s right, I think my reasons are most of the same, except by the fact that I’ve been trying to explain to myself things that I’ve been learning and I can say that this is a powerful tool for self teaching, I can see the difference between things that learn and try to explain here even that briefly than the ones that I learn and do nothing else than just apply to solve problems and perhaps do not touch again.

Just by doing the exercise of thinking about and writing down here, things get a place in my mind, besides the fact that when I write something that I just learnt or still learning, I’m in a supper priviledged position of trying to explain as a learner point of view what is quite different from a expert one.

So, doesn’t matter what are your aspiraitons or what’s your level, why not? I know that sometimes is hard to stop to write for a while but even if you put something there sometimes, you’ll be contributing with something that may be usefull to somebody and for you so, go for it.

An special thanks to Camila for the mention and congrats for the amazing collection that you already have there.

Let’s see today how to easily use Phython 3 in your macOS using Homebrew.

Before starting let’s remember what’s Homebrew.

“Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS operating system. Originally written by Max Howell, the package manager has gained popularity in the Ruby on Rails community and earned praise for its extensibility.[1] Homebrew has been recommended for its ease of use[2] as well as its integration into the command line.[3]”

But particularly what I most like in Homebrew is the fact that by default it installs everything under /usr/local (can be changed) to avoid conflicts with system directories.

Installing Homebrew

To install it all you need is just a simple command in your terminal

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Once it finishes just try it to see if it worked properly

brew

If it returns something different than command not found, it worked.

Now just try doctor

brew doctor

If you see something like “Your system is ready to brew.” you’re ready.

Python 3

Time to install Python 3 using Homebrew

brew install python3

Wait until the end of the installation and check if Python3 is there, executing python3 in your terminal, you must see something like that

Etna:playground-python adequeiroz$ python3
Python 3.6.1 (default, Mar 28 2017, 21:09:58)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Tip : Do not forget that the same pattern “3 in the end” applies for pip too, instead of executing pip you’ll use pip3.

Now is more of the same, write your code and use python3, if you’re using an IDE to it, do not forget to change your interpreter, if you’re using the default Homebrew configuration you’ll find it somewhere under /usr/local/Cellar, in my case.

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/bin/python3

All right, just go for it. Happy coding 🙂

Let’s see in this post how to disable the Java certificate validation for secure connections.

Before, I really recommend that you don’t do this when you intend to connect to somewhere outside of your DMZ, Disabling the trust manager defeats some parts of SSL and makes you vulnerable to man in the middle attacks, but wait, in this case, maybe even inside the DMZ… who knows 😀

Anyway, recently I had to authenticate to an internal MongoDb using SSL and I got some issues, how it was for a small internal application, the choice was just disabling the certificate validation.

private void disableCertificateValidations() {
      try {
         final SSLContext sslContext = SSLContext.getInstance("TLS");
         sslContext.init(null, new TrustManager[]{
               new X509TrustManager() {
                  public void checkClientTrusted(final X509Certificate[] x509Certificates, final String s) throws CertificateException {
                  }

                  public void checkServerTrusted(final X509Certificate[] x509Certificates, final String s) throws CertificateException {
                  }

                  public X509Certificate[] getAcceptedIssuers() {
                     return new X509Certificate[0];
                  }
               }
         }, new SecureRandom());

         SSLContext.setDefault(sslContext);
      } catch (Exception e) {

         LOGGER.error(e.getMessage());
      }
   }

This small snippet if used in a wrong way has the potential to put you in danger, be careful 🙂

In this quick tip I’ll show how to optimise images on the fly using ImageJ, looks simple but it took some time because of the input stream creation after the optimisation. I googled it but all the codes that I found were producing empty OutputStreams, until I finally realise that I could use ImageIO to produce the correct ImageWriter and ImageOutputStream.

public InputStream createOptimizedImage(Rendition rendition) throws IOException {
      try {
         final InputStream renditionInputStream = getRenditionInputStream(rendition);
         final BufferedImage bufferedImage = ImageIO.read(renditionInputStream);

         final String imageTitle = rendition.getName();
         final ImagePlus image = new ImagePlus(imageTitle, bufferedImage);

         final ImageProcessor processor = image.getProcessor();
         processor.setInterpolationMethod(ImageProcessor.BILINEAR);

         final BufferedImage optimizedImage = processor.getBufferedImage();

         final ImageWriter writer = ImageIO.getImageWritersByMIMEType(rendition.getMimeType()).next();

         final InputStream optimizedImageIs = getOptimizedImageInputStream(optimizedImage, writer);
         return optimizedImageIs;

      } catch (IOException e) {
         LOG.error("Failed in creating optimized image ", e);
         throw e;
      }
   }

   private InputStream getOptimizedImageInputStream(final BufferedImage optimizedImage, final ImageWriter writer) throws IOException {
      final ByteArrayOutputStream os = new ByteArrayOutputStream();
      final ImageOutputStream stream = ImageIO.createImageOutputStream(os);
      writer.setOutput(stream);
      writer.write(optimizedImage);
      writer.dispose();
      stream.close();

      return new ByteArrayInputStream(os.toByteArray());
   }

Forget about Rendition I wrote this code to be used into Adobe AEM, you can replace getRenditionInputStream to anything that returns an InputStream.

Since I used maven, this is the necessary dependency

<!-- ImageJ -->
<dependency>
   <groupId>net.imagej</groupId>
   <artifactId>ij</artifactId>
   <version>1.51h</version>
</dependency>

And the repository

<repository>
   <id>imagej.public</id>
   <url>http://maven.imagej.net/content/groups/public</url>
</repository>

Enjoy.