Live geek or die tryin'

Posted on by Dinduks


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! :)

Posted on by Dinduks | Posted in Ruby | Tagged , , , ,


Posted on by Dinduks


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.

Posted on by Dinduks | Posted in Development, Pieces of code, Rails | Tagged ,


Posted on by Dinduks


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
I now understand what you mean, @zedshaw

Posted on by Dinduks | Posted in Development | Tagged , , ,


Posted on by Dinduks


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.

Posted on by Dinduks | Posted in Uncategorized | Tagged ,


Posted on by Dinduks


The idea of creating a blog post to gather people's opinions is pretty weird, but nothing ventured, nothing gained.

Hello,

I'm building an application that will have many types of multilingual dynamic content: news, about, announces, meta tags, meta description, and maybe more.
The app is a Rails one, so I'll be talking about tables and not entities.

I've been creating a database table for each of the content types above, and I noticed halfway that they have (almost) the same columns: title, body, lang_id.
I decided then to use one single table, called text, which will have a text_type_id column, additionally to all the previous columns. type_text will only contain the type of the content (news, about, announce, etc...).

The thing is that I'm not very convinced about what I've done, I find it a bit dirty because many kind of data will be stored in the same place. On the other hand, if I create a table for each type, it seems to me that there will be some kind of redundancy, which is also messy in my eyes.

What do you think about this? Please leave a comment explaining what you would have done if you were in my shoes, and why.
Thanks!

Posted on by Dinduks | Posted in Development | Tagged ,