Thursday, November 10, 2016

Putting Jenkins behind auth_basic Nginx reverse proxy

We have all been there and done that. And a simple Nginx reverse proxy with basic password authentication is no different. But what about putting Jenkins behind the reverse proxy?

What? So you're saying Jenkins changes the whole alchemy? Yeah boy. Jenkins and similar Tomcat Java based web apps that have their own authorization mechanism need to be treated differently behind a proxy. In fact you have to instruct them beforehand by adding the following header in your proxy block:

proxy_set_header Authorization "";

The whole nginx config may then look something like this:

server {
    listen 80;

    server_name jenkins.myserver.ltd;

    access_log /var/log/nginx/jenkins_access.log;
    error_log  /var/log/nginx/jenkins_error.log;

    location / {
      proxy_pass http://localhost:8080;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;
      proxy_set_header Authorization "";

      auth_basic "Restricted Content";
      auth_basic_user_file "/etc/nginx/.htpasswd";
    }
}

Wednesday, April 13, 2016

Refactoring React components to ES6

Refactoring components to ES6 is going to be inevitable. The trickier parts imho are to refactor state initialisations and state functions.

State Initialisation

React is encouraging to move from getInitialState() to using constructor() method. Example:

Before

  getInitialState: function() {
    return {
      timeElapsed: null
    }
  }

After

  constructor(props) {
    super(props);
    this.state =  {timeElapsed: null};
  }

In my opinion the code is cleaner...so I won't complain!

State Functions

React is removing our comfort zone of auto binding. This is to make is more Javascript idiosyncratic. Again, I won't really complain. Check the before and after example:

Before

..
  startStopButton() {
    return <TouchableHighlight
      underlayColor="gray"
      onPress={this.handleStartPress}
      >
      <Text>
        Start
      </Text>
    </TouchableHighlight>
  }

..

  handleStartPress() {
    var startTime = new Date();

    setInterval(() => {
      this.setState({
        timeElapsed: new Date() - startTime
      });
    }, 30);
  }

After

..
  startStopButton() {
    return <TouchableHighlight
      underlayColor="gray"
      onPress={this.handleStartPress.bind(this)}
      >
      <Text>
        Start
      </Text>
    </TouchableHighlight>
  }

..

Since handleStartPress is going to manipulate the state, it needs to be binded manually to the class object (i.e. our component). Another clean way is to define the bind in the constructor() method:

  constructor(props) {
    super(props);
    this.handleStartPress = this.handleStartPress.bind(this)
    this.state =  {timeElapsed: null};
  }
..
  startStopButton() {
    return <TouchableHighlight
      underlayColor="gray"
      onPress={this.handleStartPress}
      >
      <Text>
        Start
      </Text>
    </TouchableHighlight>
  }

..

Thursday, February 25, 2016

Oracle XE 11g master-slave (standby replication) on Docker


In this demo I show how to setup two oracle XE 11g instances as Master Standby replication configured on two Docker containers.



Friday, January 29, 2016

Malta to introduce super unleaded fuel

Enemed, a Maltese Government owned company which will be taking operation of Enemalta's petroleum division, has yesterday informed the public that it will be distributing super fuel in 60 stations.

This is great news for all the petrol heads (including myself!). But before we get all excited, as it normally happens with all cool tech / science that penetrate the Maltese market, let me point out the common myths that need to be busted once and for all!



Myth 1: Premium gas gives you more MPG than regular gas

To increase gas' octane rating, companies add ethanol, when they're mixing up a batch of premium fuel. Interestingly, ethanol actually contains less energy than untreated gas, so the net result from the ethanol component is a reduction in your MPG. Other premium additives, however, have the reverse effect, and slightly increase your MPG. So okay, overall premium provides a very slight net increase in MPG, but it's so slight that I swear you won't notice the difference.



Myth 2: Premium has special or extra detergents in it that are worth the added cost.

Ignore any sales pitch about the super-special detergents that come in the premium-grade fuel.

These days, all of the gasoline from the major gas companies contain more than enough detergents to keep your engine clean. Period.

The only reason you might have a use for the extra detergents in premium, is if you have a noticeably dirty engine, and need to scrub carbon and other crud off engine components. (And, if you're doing that, I'd instead suggest that you toss in one of the many fine engine additives.)



Myth 3: I will void my warranty if my owner's manual calls for premium and I use regular unleaded.

You might, but I don't think so.

But, that's just my humble opinion. If you use regular instead of premium, and your car calls for premium, there's no way I can guarantee that your dealer won't try to sneak away from taking responsibility for repairs.

But, if I had a vehicle that called for premium, I'd take the risk. There's a big price difference between regular and premium. That adds up to quite a bit of money over the life of your car.



Myth 4: Using regular gas in a car designed for premium will definitely damage the engine.

I don't believe that any modern engine that claims to require premium will be damaged by using regular unleaded judiciously. Neither do any of the sources I've checked with - including the American Petroleum Institute and the American Engine Rebuilders Association.



Source: Cartalk.com

Saturday, January 09, 2016

How to fix an overheating Macbook (running sluggish and fan noise)

MacBooks are notorious for overheating - although there is a plethora of information out there how to fix this issue, most of the suggestions are either "Take it to Apple Care" or reset SMC.... In this post I am going to help you fix it for real, especially if it is a MacBook Pro 2010 in which case it is likely to be a hardware related issue.

In my opinion, an overheating MacBook causes two main nuances:

Problem 1 - If it overheats than there must be a hardware issue!
Problem 2 - MacBook overheats for no apparant reason even if it just sitting on your lap!
Problem 3 - The fans are whirling and creating lots of noise!
Problem 4 - The system runs sluggish when there is the overheating!

Fixing FIRST ISSUE
So let's tackle the sluggish issue first - I know it is a bit like cheating, but we will get to the root of the problem soon! Why does the MacBook run terribly slow during an overheat? Some of you may have fired up the Activity Monitor and noticed a process called kernel_task taking high CPU, sometimes even 400% !! So what is happening here?

Basically OSX has a kernel module called ACPI_SMC_PlatformPlugin that regulates the kernel and user processes to prevent overheating by trying to minimise the CPU cycles and system activity. This is done by constantly monitoring the temperature and inputs this information in a negative feedback system - the higher the temperature, it will tell the CPU to slow things down..you know..to chill a bit (that was good eh!).

So in theory this is a good thing. BUT...if there is a hardware fault - I will come to this later - this negative feedback system will actually worsen things out. So I suggest to eliminate this kernel module in the first place by running this command in your terminal:

The result is this: MacBook will still overheat for now, but at least will not cause the whole system to run super-slow and collapses your mental sanity. GOOD!

Fixing ROOT CAUSE
Now let's go to the hardware fault - I will talk about my experience but you can use the same troubleshooting and fix for your particular problem. So my MacBook was giving me trouble from day 1 - everytime I lay it down on my lap it will overheat in a few seconds. If I put it down on a couch, it will do the same. So I used to think that MacBooks in general do a terrible thing in compromising practicality for the sake of running sleek.

However one day I noticed while adding a RAM module that if I press on the RAM, the MacBook will suddenly overheat - so I started replicating the problem to be 100% sure - I was pressing down on the motherboard to make sure that it was just the spot on the RAM that was causing the issue. Further research gave me more insight and appeared to be a common problem!

So how did I fix this? This was easier now that I knew where was the problem. The fix is a bit of a household hack, but hey it works - I just folded a piece of paper and put it on top of the battery. This way I created a buffer and the lid was never pressing against the RAM module:

Monday, December 21, 2015