Write a new task using Capistrano

Capistrano can be a great tool to run a task on several servers. It can be a task like uploading a maintenance page or deleting some logs :

desc <<-DESC
This is my awesome task. Description appears in help so write it carefully.
run "rm -rf #{logs_folder}"
run "mkdir #{destination_folder}"
top.upload("index.html", "#{destination_folder}/index.html")

You can read more about writing Capistrano tasks here.


Create a copy of a Vagrant machine

1. Stop your vagrant machine

vagrant halt

2. Create the copy (it can take sometime)

vagrant package --base <name_of_your_machine>  --output path/to/newly/created/package

The machine name is on Virtual Box 🙂

Prototype – Cheat Sheet

I had to deal with Prototype while working with Magento. Here’s a little cheat sheet of some very simple stuff I had to do.

Make an Ajax Request with parameters

new Ajax.Request(url, {
                   params : { data1 : 'myParam' }
                   onSuccess: function(xhr){
                    var json = JSON.parse(transport.responseText);

Change value of an input

$('ID OF THE ELEMENT').setValue('The new value');

Change data within a span tag

$('ID OF THE ELEMENT').update('Your new data');


Magento – Custom routing

If you implemented several store views in your Magento shop (let’s say for French and English), if you implement a new router, he will be associated to this views.

Ex: In Magento’s default behavior,

your-store.com/my_router # KO 
your-store.com/fr/my_router # OK 
your-store.com/en/my_router # OK

The solution to this problem is to implement custom routing. Inchoo wrote an awesome article about it.


Increase security on a WordPress site

WordPress is an extremely popular framework, which makes it easier to hack. Here are couple of ways to increase the security of your WordPress installation :

  • Hide your admin back-end to a list of whitelisted IPs through server rules on Apache / Nginx
  • Change the path to your admin back-end
  • Protect the wp-login.php script
  • Change the prefix of your tables
  • Use complicated passwords and change them often

For people who are not necessarily developers, the plugin “iThemes Security” does some of the steps I mentioned pretty well.


NoMethodError /Ruby/Gems/2.0.0/gems/sass-3.4.8/lib/sass/plugin/compiler.rb Undefined method start

I had the weirdest issue when initializing my compass project for Greenie.

kikoo:greenie leiluspocus$ sudo compass watch --trace
>>> Compass is watching for changes. Press Ctrl-C to Stop.
NoMethodError on line ["402"] of /Library/Ruby/Gems/2.0.0/gems/sass-3.4.8/lib/sass/plugin/compiler.rb: undefined method `start' for #<Thread:0x007f90d1afd098 sleep>
  /Library/Ruby/Gems/2.0.0/gems/sass-3.4.8/lib/sass/plugin/compiler.rb:402:in `map'
  /Library/Ruby/Gems/2.0.0/gems/sass-3.4.8/lib/sass/plugin/compiler.rb:402:in `listen_to'
  /Library/Ruby/Gems/2.0.0/gems/sass-3.4.8/lib/sass/plugin/compiler.rb:338:in `watch'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/sass_compiler.rb:46:in `watch!'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/commands/watch_project.rb:41:in `perform'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/commands/base.rb:18:in `execute'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/commands/project_base.rb:19:in `execute'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/exec/sub_command_ui.rb:43:in `perform!'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/exec/sub_command_ui.rb:15:in `run!'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/bin/compass:30:in `block in <top (required)>'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/bin/compass:44:in `call'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/bin/compass:44:in `<top (required)>'
  /usr/local/bin/compass:23:in `load'
  /usr/local/bin/compass:23:in `<main>'

I solved it by using a more recent version of Ruby using RVM. RVM is pretty cool because you can switch your Ruby versions very easily. Note that I had to re-install compass afterwards.

How to add a new stock option in Woocommerce

Sometimes, clients can come up with some pretty creative ways to handle their inventory … It was the case for me with a customer who was using WooCommerce.

I had to add a third option but the stock options was not customizable. I ended up deleting the native dropdown of stock options and I implemented a custom field.

In functions.php

add_action('woocommerce_product_options_stock_status', 'add_custom_stock_type');    
function add_custom_stock_type() {
        // Stock status - We remove the default one
        <script type="text/javascript">

And then I followed this tutorial to create a custom field : http://www.remicorson.com/mastering-woocommerce-products-custom-fields/

Someone on SO proposed an other solution based on my approach but my contract was already done with that client by the time he answered, didn’t get the chance to test it out.