Monthly Archives: April 2013

Map tab key to indent and shift+tab to outdent in TinyMCE (in Wicket)

Today’s post is about changing the behavior of the TinyMCE implementation in the wicket stuff library. In this library TinyMCE functionality can be implemented by just adding the TinyMCEBehaviour to the wicket component TextArea and calling the behavior’s constructor with an instance of TinyMCESettings, where you can set all kind of parameters.

Generally very content with our implementation, our customer wanted a way to define pre-formatted text blocks to use in documents at a later point. For ease of use, pressing the tab key should indent the text and shift+tab should revert the effect = outdent the current line. Although the advanced edit settings showed indent/outdent buttons we also wanted it to work when the buttons aren’t shown, in forms where space is precious for example. After some google searches I found this post (cached google version), about how to execute TinyMCE functionality in javascript and this stackoverflow answer, about where to put this info.

The solution, which works pretty well for us, was to insert a method in our TinyMCE class, which just adds the following function to the settings instance.

public static TinyMCESettings addTabFunctionality(TinyMCESettings settings) {
settings.addCustomSetting("setup : function(ed) { " +
"ed.onKeyDown.add(function(ed, e) { " +
"if(e.keyCode == 9) {" +
"if(e.shiftKey) {" +
"ed.execCommand('Outdent');" +
"}else{" +
"ed.execCommand('Indent');" +
"}" +
"e.preventDefault();" +
"return false;" +
"}" +
"});" +
return settings;

The addCustomSetting() method adds code to the init() function created by the TinyMCE addon and in the javascript code we listen for keydown in the textarea. If keycode equals ‘9’ (tab) we check if shift is also pressed, if so an outdent action is performed using execCommand(‘Outdent’), if not, an indent is executed. By calling preventDefault() afterwards, the default action of the tab key is prevented – in our case it just was a 4 space-tab, which wasn’t written to the created html code. Calling the TinyMCE indent and outdent commands, padding is added to the affected line’s <p> tag (30px per tab) so the format can be saved to a database, without loosing the tabbed white-spaces.

Hope this helps someone, have a nice weekend! Until next time, feedback’s very welcome!

Running cron jobs on Raspberry Pi in Raspbmc

Here’s another little tutorial especially for people new to raspberry pi or linux in general (such as myself). Cron jobs are used to execute specific actions at pre-configured times. These actions can be executing scripts, writing data to a file, etc. (would be glad to hear of stuff you do with cron jobs in the comment section ;))

In my specific case I needed a script to map my changing external ip address at home to the domain I specified for my raspberry to have access to it when I’m away. Big thanks for all the help to my good friend Thomas for domain hosting and tipps on how to get this to work! Now let’s get to it!

  1. Activate cron jobs in Raspbmc
    Per default running cron jobs is deactivated in Raspbmc and there are two ways to activate them.
    – In the Raspbmc GUI under Programs -> Raspbmc Settings -> System Configuration -> Service Management -> Cronjob Scheduler
    – Via SSH/FTP by modifying sys.service.cron value to “true” the settings file under /home/<your_username>/.xbmc/userdata/addon_data/script.raspbmc.settings/settings.xml – for more infos on changing settings via SSH / FTP, check my latest blog post
  2. Configure your ‘crontab’
    All cron jobs are defined in this file and you can specify multiple of them, each on its own line – to edit  your crontab in your default text editor, type ~$ crontab -e in the console. By using ~$ crontab -l the content is shown.
  3. Write your cronjob
    The syntax isn’t too easy to understand in the beginning, but there are tools online, which can help you write your (first) cron jobs. In my case the cron job looks like this:
    20,40 * * * * sh /
    Every hour at minute xx:20 and xx:40 the script in the root directory of my raspberry is executed, which just calls a magic dns mapping domain via wget.
    Especially in the beginning it’s a good idea to add a test job, which executes every minute and only helps to see if your cron configuration is set up properly. I use the following:
    * * * * * echo “crontest $(date) $(whoami)” >> /tmp/crontest.txt
    This just writes the current date and the current user to the specified textfile.
    Below is a screenshot of my current crontab:
    Screen Shot 2013-04-05 at 11.48.22 PM
  4. Control the cron service
    In order to get your cron jobs to run, the cron service must be active. The following commands let you control the cron service:
    ~$ /etc/init.d/cron stop
    ~$ /etc/init.d/cron start
    ~$ /etc/init.d/cron restart
    These commands will probably need a leading ‘sudo‘ – just check your console output. To quickly repeat your last command with leading sudo type ‘sudo !!‘.
  5. Check if your cron jobs are running
    If you also specified a test cron job like the one above, you can test if it’s working by printing the latest contents of the text file to your console. This can be done by using the ‘tail’ command and the ‘-f‘ parameter updates the output as new content is added to the file. See below screenshot for example output:
    Screen Shot 2013-04-06 at 12.00.48 AM

And… That’s it! Thanks for reading, hope it helps someone, glad for every kind of feedback! Bye!

Update (10.11.2013): As jazz and CFWhitman pointed out in the comment section, you can also just use the commands /etc/init.d/cron status or service cron status to check if cron jobs are running. For output see screenshot below 🙂 Thanks!

Screenshot 2013-11-10 04.31.52