Live geek or die tryin'

Apache: Enable HTTPS Locally

Sometime you’d like to use SSL on a local website, for development purposes. This is possible to do in few minutes.

Enable Apache’s SSL mod

If you’re on some Debian based distro, and installed Apache with aptitude or apt-get, executing the a2enmod ssl command will do the trick. This means Apache2 Enable MOD, and will simply create a symbolic link to /etc/apache2/mods-available/ssl.** in /etc/apache2/mods-enabled/*.

If you installed Apache in some other way, enable the SSL mod manually.

Ask Apache to listen on the port 443

443 is the default SSL port. Ask Apache to listen on it by adding Listen 443 in your config file (httpd.conf for example). You don’t need to do that if you installed Apache with aptitude or apt-get. Apache automatically listens on this port when the SSL mod in enabled.

Create an SSL certificate

mkdir /etc/apache2/ssl/
make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem

This will generate a SSL certificate, based on the ssleay.cnf template.

Setup your application’s virtual host

Setting up SSL is over. Now it’s time to create a virtual host for our application.

<VirtualHost *:443> # listen on the 443 port
  ServerName myawesomeapp.dev

  SSLEngine On # enabled SSL
  SSLCertificateFile /etc/apache2/ssl/apache.pem # specify the certificate file

  DocumentRoot /var/www/dev/myawesomeapp/
</VirtualHost>

We’re done, happy coding!

Sinatra, RSpec and DataMapper: Configuring and Using a Database for Tests

Hi there,

When testing your Sinatra application, you may need to check if some data was stored, removed, or changed in the database.

Your application would look like this:

Okay. First of all, let’s tell RSpec to use a blog_test.db database:

Explanations:

  • DataMapper::setup(): Tells DataMapper which database to use ; it will create it if it doesn’t exist.
  • DataMapper.finalize: Finalize the models. More information in DataMapper’s documentation.
  • auto_migrate! drops and recreate the tables, which is a good thing since we want to have a clean database before each test.

If it doesn’t already exist, a database will be created in the application’s root path the next time RSpec will be called (from the cli for example).

All what is left now is to write the test:

I hope this quick how-to was helpful.

Happy testing! :)

Rails: Load Assets in a Specific Order

Let’s pretend you have many CSS/SASS stylesheets and JS/Coffee scripts in your project, and you want to load some before the rest. This can be done in stylesheets/application.css and javascripts/application.js by using the keyword require.

Examples:

Stylesheets:

If you want to load Bootstrap’s stylesheet first:

Javascripts:

This is how to load jQuery and Boostrap’s scripts before the others:

You can omit the files extensions.

I believe they call this the awesomeness of Rails.

Clean Code vs Efficiency

I have recently submitted my first pull request ever, to the Symfony2 project.

The code I contributed with is a 3 lines long method that simply checks whether a form field is hidden or not. I have no doubt about the usefulness of this method, especially after seeing few people using a similar one (it seems that it was removed).

The pull request was refused because the class in question isn’t supposed to be aware of information we need. I agree with this and approve the good practices and clean code, but in this case we penalize the end user for the sake of doing things the right way.

The purpose of my post is to answer the following question: should efficiency and simplicity be sacrificed for the sake of good practices and clean code?

In my opinion, the answer is no. Especially when we’re dealing with a big project that thousands of people use, and that claims easiness and simplicity.

I’m looking forward to know your opinion about the subject. Feel free to leave a comment.

Programming Motherfucker

VMware Workstation: Enable Folder Sharing

Hello,

I daily use VMware Workstation to code on Linux.
Yesterday my dear Debian’s Gnome broke because of a bad manipulation, so I just took it as a call to move on and try some other distro.
I first installed Linux Mint Debian, and removed it because folder sharing didn’t work, despite my effort to fix the problem. Then I tried with Kubuntu: the same issue.

The problem there was that my shared folders didn’t show in /mnt/hgfs/.
After reading many documentations, forums, and mailing lists, and trying to mount the shared folder manually, I reached a point where I got a FATAL: Module vmhgfs not found error.
This error, as far as I understood, was occurring because of a bad installation of VMware Tools. Re-installing the latter didn’t work.

The vmhgfs module, like some others, isn’t sometimes built because it is not included in the VMware tools. To build the required modules, you just have to install open-vm-dkms:

apt-get install open-vm-dkms

Now restart VMware Tools:

/etc/init.d/vmware-tools restart

And finally, mount the your shared folder!

mkdir /mnt/hgfs/my_shared_folder
mount -t vmhgfs .host:/my_shared_folder /mnt/hgfs/my_shared_folder

If that doesn’t work, just log out and on your session.

I hope this tutorial has been helpful.

Note: The last post of this thread http://communities.vmware.com/thread/332887 was useful to me.