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.
While setting up my Rails development environment on my fresh Kubuntu VM, I’ve encountered many errors.
This one was occurring when trying to launch a WEBrick server:
/home/dinduks/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require’: cannot load such file – openssl (LoadError)
This error means that your Ruby isn’t compiled with openssl.
Assuming that you use RVM, these are the steps to follow to fix this issue.
I’ll be soon working on a school project, which led me to look for a place where to version my code.
Since I use GitHub daily, I checked its plans first. The cheapest one, called micro, gives 5 private repos for $7/month. I unfortunately only need a single private repo, and I don’t want to pay for 4 ones that I probably won’t be using.
Although I knew about Bitbucket’s free private repos, the ideas of leaving GitHub and having my repos here and there didn’t please me that much.
Luckily, I stumbled upon GitHub’s Educational offers, that are available to both teachers and students.
The teachers’ offer concerns organization accounts. And the students’ one on the other hand is simply a micro plan, and lasts 2 years, enough to get your ass a job and pay a subscription.
To benefit from this offer, just contact GitHub from the Request an educational account page.
Make sure you are logged in with the account you want the plan for, and tell them why you need it.
I’m going to show you a simple way to cache a file.
To illustrate my example, I will use a script that creates a single image from multiple images.
I have written that script a few months ago to generate a patchwork of my top albums in Last.fm, due to the lack of working similar scripts.
First, let’s see how the script works, without the cache system:
As you can see, the image is generated whenever the script is called. This isn’t only greedy on the server’s resources, but does also take a little time ; between 4 and 6 seconds for a common patchwork.
To avoid this repetitive task, the idea is to save the generated image on a file, and, each time the script is called, check if the image doesn’t already exist before creating it again.
Create a signature of the source file
Since the image is generated from data that comes from the Last.fm Web Service, it will change according to it’s response. Let’s then create a MD5 hash of it.
Note: Make sure you have the write and read permissions on images/.
Save the file
At the end of the script, just before displaying the image, save it.
imagejpeg($patchwork, $fileName);
You’ll have to use fwrite() or a similar function depending on the type of the file you want to save.
Check if the file exists
The file is well saved now.
The final step consists in checking, at the next request, if that file exists. If it’s the case, answer with it, if it is not, run the usual code ; which is the image creation.
The code below should be put right before the image creation process.
if (file_exists($fileName)) {
header("Content-type: image/jpg");
echo file_get_contents($fileName);
exit;
}
You are now ready to implement your own little cache system. Have fun. :)