Free News Papers Delivered to Home

This incidence relates to a Wijaya Newspapers. Wijya are to deliver news papers to your door step if you pay up front (3 months, 6 months or 12 months). The provided pricing is as such, you will get a 20% discount. So if you are an avid news paper reader, you can call them up and setup delivery.

I woke up early. I went to my office room and continued some work that was bugging me last night. While I was at it and sipping a cup of tea I heard some thing landing on my garden. It was a bunch of papers. I was unusual, but I thought it would be for mum, and got it inside.

She was her self puzzled. I suggested asking our neighbors if it was theirs. After I had finished work on the issue I got dressed and head out to ask about the papers.

For my surprise, I found out that the whole lane was supplied with news papers, wroth about Rs. 150. No one seemed to know why.

I had a hypothesis that there would be some advertisements related to the up coming elections. I checked but there were no advertisements. There was no common denominator when it came to front page news to suggest some one wanted to make a point.

Why those papers were delivered remains a mystery. Have you also received such?

Setup Local Dev with DOT Test

This is not Rails tutorial, but i use Rails references. Swap it with what ever the framework you use. How ever this setup is for Linux.

Not every project can simply rely on rails s for local development. This is specially true if you are working on a SaaS application that is using sub-domains for tenants. Today I am going to share with you how I have configured my local development environment to serve project using .test TLD.

The setup is as follows…

I assume you have a (Rails) project in /home/user/client/project.

DOT Test to localhost

There are many ways you can do this. But I believe the easiest way is to use dnsmasq.

#~ sudo apt-get install dnsmasq

If you are in Ubuntu you would need to update NetworkManager config. This is because NetworkManager it self uses dnsmasq which conflicts with our interests. Open up /etc/NetworkManager/NetworkManager.conf and comment out the line that reads dns=dnsmasq. Then restart the service

#~ sudo restart network-manager

Then you need to configure dnsmasq to listen to local DNS queries. Edit /etc/dnsmasq.conf and add listen-address=127.0.0.1 to the file.

Next we need to tell dnsmasq to resolve .test to localhost. To do this create a new file /etc/dnsmasq.d/test with content address=/test/127.0.0.1.

Now we are good. What we need to do is to install and setup Nginx.

Nginx Reverse Proxy

If you wanted to setup local environment to host .test domains, the chances are you need to configure Nginx or Apache for the task as well. I don’t use Apache. So here is an example how to install and configure Nginx to serve a Rails application.

Many developers I know already know how to setup and configure Nginx, so I kept it for last.

Installation

First of all, lets install it!

#~ sudo apt-get install nginx

Can’t get any simple than that, could it!

Project Configuration

I am assuming your project uses sub-domains. Some thing like a SaaS application with tenants served through sub-domains.

Create a file in

upstream projecttest {
  server localhost:3000 max_fails=3 fail_timeout=600;
}


server {
  listen 80;
  server_name *.project.test;

  root /home/user/client/project/public;

  try_files $uri/index.html $uri @projecttest;

  location @projecttest {
    proxy_pass http://projecttest;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

Here projecttest can be what ever you like. I use the naming format <project-name><tld>. Some use app. Its up to you!

Conclusion

Thats it… no cd to your project folder and run rails s and visit your app… www.project.test or any of its sub domains.

Chrome Kills DOT Dev - Use DOT Test

Last night I was involved with some refactoring in GivingFire.com. I went to bed following a dist-upgrade in Ubuntu. This morning when I fired up rails s and opened the project in Chrome I was greeted with an error. It was an issue about the certificate. FireFox was unaffected by this.

Google nabs dot-dev

Google had acquired the rights for the .dev domain in 2015. But until recently using .dev for local development wasn’t an issue. I didn’t use .test because most of my clients had their projects configured to use .dev for local environment.

This is a total dick move by Google.

Time to change

I would recommend the use of dot-test (.test). It is a reserved name by the IETF (Internet Engineering Task Force). A list of domain names you can use are as follows…

  • dot-test (.test)
  • dot-example (.example)
  • dot-invalid (.invalid) - wtf! exactly :P
  • dot-localhost (.localhost)

In addition, I think you can also use .local. It is generally used in private networks for networking devices.

When you change, you may need to…

  • re-gen your self-signed certs if in use
  • update session store config (Rails) and similar in other frameworks

Conclusion

It was time to move away from .dev 2 years ago. But since Google is forcing you out, you have to either ditch chrome or move to some thing like .test.

In my side, I think it is time to publish some new tutorials on how to configure local development using .test.

Implement Rails Views with Common Code

Proper structuring of views in an application is important. It helps minimize code redundancy. For components you can use partials. If the common code applies in the scale of layouts its best you use nested layouts. In addition to using nested layouts, you have the option to use partials that accept blocks.

Nested Layouts

Nested layouts are best when the common code applies in a layout level. For example think about a blog section. It will be different from the main layout in a way there will be a sidebar and a header. In ways layouts/application.html.slim will have additions to it. This is when you should use nested layouts.

You will have to modify your layouts/application.html.slim to accept a content_for block. This is where we will add the nested layouts content in to.

html
  body
    = content_for?(:content) ? yield(:content) : yield

Then you can write a nested layout as follows. Lets say it is layouts/blog.html.slim.

- content_for :content do
  header
    h1 My Cool Blog
  .blog-body
    = yield
  .blog-sidebar
    = render 'layouts/blog/sidebar'

= render template: 'layouts/application'

Partials Accepting Blocks

The other way to share layout code is through partials that accept blocks. Think about a page referencing a blog post. Rather than just having a link, you make a little drama adding the blog title, featured image etc.

In the page, we desire some thing like…

/ views/pages/products/web-crawlers-and-scrapers.html.slim
h1 Web Crawlers and Scrapers
p Lorem ipsum...
p Lorem ipsum...

= render partial: 'blogs/embed', locals: { blog: Blog.find(1) } do
  ul
    li Point 1
    li Point 2
  p Lorem ipsum...

Here we can customize each embed in the page by adding some extra slim to describe the context.

In the blogs embed view partial, we can do some thing like this.

/ views/blogs/_embed.html.slim
h3 blog.title
= image_tag blog.image.url
= yield

While this is a basic example, I believe you get the point.

Conclusion

Rails allows you to neatly structure your views reducing code duplication. While it is easy I have seen some projects with views that can only be described as a nightmare. A word of advice, don’t leave them a all over the place and and DRY (do not repeat your self) things up.

While I believe modern applications should be built separately as an API (Rails API, Grape or in node LoopBack) and client-side app using some thing like React JS or Angular, the Rails view layer will stay alive for a good 10 years to come. Hence my contribution on the topic.

Yahapalanaya - The great cockup

You remember a time people disappeared abducted in white vans? There is news that the abducted were taken to military bases before they vanished off the surface of earth! You remember people meeting with accidents just because they knew a birthmark of a girl the prince has been interested in? Remember the king going go release a drug lord who was was detained by authorities in live TV? Remember people getting shot and killed by the Army when they protested for drinking water. Remember great investments were made on roads that washed away on rain? Remember the same bridge been open lane by lane as if a new bridge was made?

A new beginning

That is just some of the fun people in one January 8th decided to say no to! The once invincible dictator Mahinda Rajapaksha was defeated in his 3rd attempt to secure rulership by a unlikely candidate Maithreepala Sirisena. Sirisena the secretariat of the former president (currently the Kurunegala District MP) Mahinda Rajapaksha victory was only possible with the alliance with teh UNP led by Ranil Wickramasinghe. While this is an explosive mixture with different ideologies, it was necessary.

Ranil Wikramasinghe, the world record holder on election defeats, who was been in the opposition for almost “for ever”, became the prime minister.

Peoples demanded change

People demanded one thing. Good governance, no corruption and the recovery of the economy from the debt of the last government. It was not too much to ask and that was what was promised in their marketing material.

Thieves in the previous government would face justice. Living quality will improve. Corruption will be stopped. These were the mantra they chanted in every election rally.

What happened

From the very beginning they showed concerning signs among significant improvement. I must say regardless of how many protests there has been no disappearences or deaths. People for unjust reasons are on strike highly inconveniencing the general public. Among all that the Central Bank bond issue comes in to light. I consider it the single biggest cockup done by the government.

The good thing is, there is an investigation initiated by the president Maithreepala Sirisena. People have been interrogated including the prime minister. No reporter reporting the incident died. Its an improvement. Since it is an active investigation I will not comment on the issue.

But what I can say is, the accused Arjun Mahendran, is a friend of Ranil and the UNP. I even recall the PM giving guarantees about him. The guy was controversial from the very beginning. It was said he worked remotely from Singapore.

In such case, I think the PM should have resigned. While the UNP tried to market the deposition saying Ranil was the “Fearless PM”, I think the more accurate term is “Shameless PM”.

Where I stand

To be frank, I used to give no fuck about politics. But now, I can’t say I don’t. Politics has profound effect on life and simply cannot be ignored.

My first vote was for Sirisena. I wanted to end the terror rule. The second vote for UNP in parliament elections to giver power to the new government so they have a chance. This time, I am not so sure.

The main issue is peoples choice. Do you think those with concern will not get votes next election? No, they will get votes. Majority of people in Sri Lanka are stupid. That is why it is hard to fix.

I thought there was hope for this country, but I stand corrected. Its time I start looking to leave this hell-hole for good!