Category Archives: Programming

OpenShift is a Platform as a Service (PaaS) from RedHat. It’s great for deploying web applications as you can setup/scale/manage apps quickly without any hassle, just like Heroku, but the OpenShift platform is available as a free and open source software, so you’re not locked in (you can install OpenShift on your server and create your own private PaaS if you want).

Step 1. OpenShift Setup

First of all, Create a free Account. You get 3 small gears (resource container/unit : one small gear is equivalent to 512 MB RAM and 1GB storage) for free. If you need more, you can upgrade to premium plans.

Install rhc tool

gem install rhc

Note : If you use rbenv for managing ruby then you also need to run `rbenv rehash`.

create token and upload public keys

rhc setup

And follow the instructions. Once the setup is completed, you can easily create/manage your apps using this client utility (rhc).

Just type :

rhc

to see available options. If you want to see all the cartridges (application environment e.g ruby, php, python etc) available, just type :

rhc cartridges

Create a Ruby on Rails App [openshift]
Run this command from the parent directory of your project (~/parent_directory/project) or it will create a directory inside your app.

Note : joblee is the name of the Rails app we’re going to deploy. So, replace it with the name of your app. And I assume you’re using Postgresql for database.

rhc app create ruby-1.9 -a joblee

Add database cartridge

rhc cartridge add postgresql-9.2 -a joblee

Add ‘pg’ to your Gemfile. And run bundle install. Although, you’ll receive database details in the end (above command) but it’s a better to use openshift environment variables in database.yml. So, update the database.yml accordingly. Something like this one : production config for database.yml (openshift)

Step 2. Preparing the application for deployment

Once the openshift is setup, move to your project directory and setup git push deployment for your app.

cd joblee
rhc show-app joblee

And get the value of Git URL from the above command. Now, add the remote url for deployment. (replace GIT_REMOTE_URL with the value you got above)

to see lots of options available. You can also get rails console, just by typing :

cd app-root/repo
bundle exec rails console RAILS_ENV=production

Postgresql Database Setup

cd app-root/repo
RAILS_ENV=production rake db:setup

Assets compilation problem
I had to run few other commands on server due to some gems/assets related problems. But you can add it to openshift deployment hooks like this example rails app, so you won’t have to manually execute it every time you deploy the app.

If you don’t want to use www domain, then you should type this instead : (and you also need to add cname record for root domain, at your domain registrar)

rhc alias-add joblee joblee.in

Note : I’ve setup naked domain so, www version of the domain is getting redirected(301) to the root domain. Not all DNS providers supports this (I’m using namecheap and I can specify openshift app url as a CNAME record for the root record) and sometimes it can cause some weird behaviours, especially if you’re using email with the domain. (read more on how it can break MX records)

Brackets is a free and open source, cross-platformcode editor from Adobe. It’s specifically designed for web developers. It’s written in HTML/CSS/Javascript.

There are lots of cool features such as live preview for HTML, quick edit, built-in support for css preprocessors etc And it’s dedicated for web development so if you write a lot of HTML5/CSS3/Javascript then you may feel more productive with Brackets. The UI looks clean and minimal.

Getting started with Brackets

If you want to try Brackets – debian package is available for Ubuntu. It’s under active development, so there may be some new features/changes coming into the next release, you should checkout their project page on Github.

PyCharm is a new IDE from JetBrains, built specifically for Python developers. It has tons of cool features that may improve your productivity a lot. If you want to give it a try then you should checkout the video explaining some exciting features of PyCharm.

PyCharm is available (version 3 is available now) in two edition – One is community Edition (free and open source version) and the other one is Professional Edition with some extra features for web developers (supports Google App Engine, Flask, Django, web2py, CoffeeScript and other templating languages, Remote development, SQL and more).

Download Pycharm for Ubuntu / Linux

Installation is straightforward (extract the package and run pycharm.sh), but you need to have Oracle JRE (1.6+) installed on your system. (As the official manual says, OpenJDK is not supported, at least for now).

Spark is a micro web framework in Java, inspired from Sinatra (a popular lightweight web framework in Ruby). Using spark, you can quickly build web applications in Java, with minimal effort (without going through the boring xml configurations steps). If you learning java, then you can learn a lot by reading the source (since, it’s a free and open source framework).

Features

its simplicity

fast development

high productivity (get more done, in fewer lines of code)

Getting started with Spark

1. First setup spark

Download Spark (If you’re using Apache Maven, then it would be much easier for you)

2. Write some code

Code in image ? Ha Ha .. just to remind you that it’s not a good habit to copy/paste code! Type it.

As the name suggests, DNS Prefetching is the process of resolving domain names, in advance.

Suppose a user is reading a web page, he(or she) may or may not visit a link, referenced on that web page but if he(or she) does, the next page can be loaded a lot faster if it uses DNS prefetching – because it won’t have any delay due to DNS lookup (which may takes up few milliseconds to a second or more, depending on lots of factors such as latency and whether the result is locally cached or not).

How to implement it ?

To add DNS prefetching to your website, just add an extra link tag (in head, of course), in the following format :

<link rel="dns-prefetch" href="http://example.com">

You can also control DNS prefetching at page level, using the meta tag (off means no prefetching, change it to on to enable it) :

<meta http-equiv="x-dns-prefetch-control" content="off">

Does any browser support it ?

Mozilla Firefox and Chromium/Google Chrome certainly supports this feature (with compatible syntax, the above style works well for both browsers), I’m not sure about other browsers. (I think Safari and Opera do, but you need to make sure)