andhapp Random ramblings

Fonts and copyright issues

I have always wondered what the implications are in using a font on your site. Since I own a mac can I just use any font that comes with and create an image and use it on my site. Does owning a Mac or PC or any other machine for that matter give me the right to use the system fonts? I never had to face any sort of copyright issues but I just got thinking the other day and started researching a little bit and it’s quite straight forward.

The person who creates the font is the rightful owner and it’s up to him to let it be used freely or license it out. Every font actually has different sorts of licenses attached to it. The fonts that come with your Mac or PC are licensed to be used on that machine. Let us say if you want to use the same fonts and put them on the server then they are not licensed to be used there which means to put them on the server requires one to buy a license for it.

However, if you create an image using a font on your system and then use it as your logo then are you breaking any copyright laws? Once you have created a graphic using the font you are the owner of the graphic and are using(or distributing) it as a graphic and not as a font. But, be aware that this depends from font to font and one should read the terms and conditions of the license before using it. It does get a bit complicated, I must say. Anyways, while researching I found a really nice site with a collection of fonts that one can use and majority of them do not have a hefty price tag attached to them.

Please make sure you consult a lawyer regarding any complex copyright issues to protect yourself from massive payouts later.

Designer code meet

Do you write Designer code?

Well, this was the topic of Chris Parsons’s (eden developments) talk on Thursday evening. The presentation was top-notch and so was the exercise afterwards. I was lucky enough to pair up with James Adams (from Go Free Range) and a ruby stalwart. We ended up refactoring some nasty piece of code into designer code pretty quickly. It was a really nice experience after all. If you would like to have a go then, it lives in Chris’s checkout-kata repository under obfuscated branch.

The problem is our own checkout problem, which I am sure you have come across before.

Rails inflections and the word 'Equipment'

I was in two minds about this post’s title. On one hand, I think this should be called “Why googling is not the answer to every question?” and on the other hand the current title will probably interest more people. Rails inflections is not the main focus of this post. This post is a consequence of Rails inflections and attempts to highlight some of the things that are wrong with the way developers work now a days.

Last week, I had to create a model called ‘Equipment’. I know now that ‘Equipment’ is uncountable therefore when it comes to creating a table rails will not tabelize resulting in a table with name “equipment”. But few days ago, I was surprised and straight-away googled the word ‘equipments’ and results confirmed my doubts that this is a bug in Rails. Silly me.

I went through the code and found it in the inflections file and found that the ‘equipment’ word defined as uncountable. Now, I was even more surprised. If the word “equipments” exist (as confirmed by Google) then why on earth will Rails do otherwise. There is only one place that could resolve my dilemma, yes you got it right, Oxford dictionary. I looked it up and “Equipment” is an uncountable noun just like “information”.

Now, this little research basically highlights two things:

1. Google is just a search engine. Think about what you are doing and then take an intelligent decision.

2. Don’t assume that Rails is behaving incorrectly and leave it at that. Investigate and read the code. That will improve your understanding. I have seen several code bases where developers have actually just assumed what they are told and carried on.

Few weeks ago, John Nunemaker spoke about ‘Stop Googling’. If I have a bug, I will clone the code and start looking into it. In last few weeks, I have read the code bases from rspec and cucumber, clearance, rails, rvm and spree and found various good and bad things in them. This also takes me one step closer to giving something back to the open source community. But will talk about it more in my next post.

Comment multiple lines in MacVim

Commenting multiple lines is mostly used when one is debugging and quickly wants to take a piece of code out, just to put it back again. Here’s how one can achieve in the same in MacVim.

1. Press ‘V’ on your keyboard and use the arrow key to select the code snippet to be commented out.

2. Then press ‘:’ which will automatically change that to something like this:

:'<,'>

3. Then just type in this command and press Enter.

:'<,'>s/^/#/g

Now, to uncomment them just follow steps 1 and 2 and then enter the following command:

:'<,'>s/^#//g

Moving this blog from Dreamhost to Linode

This post is in continuation to my earlier post which simply mentions the move of this blog from Dreamhost to Linode and this post is an attempt to expound on a little bit of the details and the experience.

This was not just a move from shared hosting a.k.a Dreamhost to a vps solution a.k.a Linode, but it was also a move from Apache to Nginx + fastcgi. Yes, now I am actually running the Wordpress blog on Nginx. It’s just a matter of choice really. There is nothing wrong with Apache. It’s just that I have been using Nginx with Passenger for Rails deployment and decided to keep everything under one hood.

Say NO to CentOS

If you are like me (not very bright), you will instantly google “setting up nginx with fastcgi” and like always google will not disappoint you. But this information overload becomes a pain in the back side, sometimes. Why? Well, if something worked for someone does not mean it will work for you and then how long ago was it and has something changed since then and so on and so forth. CentOS has outdated packages and in several cases broken. Also, most of the results you found whilst googling suggest creating a startup script for php with fastcgi and refers to the use of start-stop-daemon and CentOS does not have one. Therefore, to keep it simple just go with ubuntu. Trust me. However, if you insist on installing CentOS then here are few workarounds for the start-stop-daemon problem.

Install dependencies manually

What exactly do you need to run this blog? PHP, MySql, and Nginx along with fastcgi and the most important, configure Nginx to proxy all the .php requests via the fastcgi server. Here’s a link that I found extremely helpful in installing all the above mentioned softwares. However, my nginx.config is slightly different from the one mentioned in the link. Here’s how mine looks:

server {
  listen 80;
  server_name <server_name>;
  root <document_root>;
  index index.php index.html;
  location ~ \.php$ {
    include <location_of_fastcgi_config file="">;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    keepalive_timeout 0;
  }
}

Replace the values in “<…>” with your own specific values.

I create a new fastcgi_config file for each domain and the only value I change is the document root.

Here’s an example:

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME <document_root>$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT <document_root>
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

You can read here for more information on the nginx fastcgi. Creating a new config file for each domain is just stupid and you can just pass the values of dynamic variables like DOCUMENT_ROOT or SCRIPT_FILENAME from within nginx but I could not get it to work.

Install dependencies via Chef

I think installing everything manually is a bit backward and one could always use Chef. In my next post, I will talk about my experience of setting up an entire server using Chef. Chef’s wiki is amazing and takes you through each and every step. Give it a try.

Gotchas

  • Make sure you restart fastcgi_server as I totally forgot and it never picked up mysql.
  • Also, add mysql.so and mysqli.so to your php.ini file and restart php_fastcgi server for it to pick up the changes. It’s most probably in /etc/php5/cgi directory.

It took me quite sometime to really get everything working and I was tempted to just give up and just use apache. But I stood my ground and finally cracked it. I hope it helps you in your own endeavours.