Validate xml against local schema in eclipse

When an XML file references his schema (xsd) url, editing is easier in Eclipse. We can validate the xml file against this schema and use eclipse content assist which suggest possible values of tags.

An invalid reference to the schema.

In my current work, I have to edit XML files whose schema reference are invalid.

In the example below the xsd definition is not only commented out but also malformed. However I want the document to validate against modelSchema.xsd but I am not allowed to modify the header.
This is not the first time I see this on production environments. I suspect this is a quick and dirty workaround to avoid a parsing error when the server is not well configured to reach the Internet (or the schema is not deployed locally on the server).

<!--?xml version="1.0" encoding="UTF-8"?-->
<!-- xsi:schemaLocation="http://www.alfresco.org/model/dictionary/1.0 modelSchema.xsd" -->
<model name="my:customModel" xmlns="http://www.alfresco.org/model/dictionary/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <description>Custom Model</description>
    <author>odm</author>
    <version>1.0</version>
</model>

Workaround: force eclipse to validate localy

Copy the xsd file localy and configure eclipse XML catalog to use the local schema to validate and provide content-assist.

Under Global preferences/XML/XML catalog, add a new entry:

location myEclipseProject/modelSchema.xsd
key type: namespace entry
key: http://www.alfresco.org/model/dictionary/1.0

Right click on the xml file, launch “validate”.

 

Automate wordpress backup (with BackWPup)

A set-up and forget scenario

I used to backup wordpress sites via FTP and export of the database. But it takes a lot of time. And with an increasing number of sites to maintain, I often skip this essential practice.

I just discovered BackWPup, a very configurable plugin for wordpress. It does everything I used to do… and can be scheduled !

What I need to backup

  • wordpress files
  • custom themes
  • plugins
  • database export
  • uploaded content

I store the backup on my laptop and on an external service (Dropbox).

Backup with one click

BackWPup builds a ZIP archive that contains the whole wordpress directory as well as  the SQL file that can be used to regenerate the tables.

The archive is sent by email or stored on a folder of the site. Even better : support for Dropbox or  amazon S3 is native and configured in a minute.

I made it push an archive of the site directly to a /fieldnotes folder of my dropbox account.

  • install the plugin
  • add a new backup job via the admin interface (settings are fine by default)
  • indicates where to store the backup
  • … that’s all !

Trigger the backup manually from the admin interface to ensure the setup is correct.

Schedule it !

You can now add scheduling via the admin panel (only pitfall: remember to tick the Activate scheduling checkbox) and enjoy receiving regulars backups in your dropbox !

 

 

Disable firefox offline mode

When Firefox 3.6 detects a network connection issue, it switches to offline mode.

I find it rather annoying as it forces me to manually switch to “online”  mode via the file menu each time I replug my laptop.

This behavior can be disabled via a hidden preference.

Type about:config in Firefox address bar, right click to add a new Boolean key and create

network.manage-offline-status

set it to false

Alternatively you may add an extension for this: https://addons.mozilla.org/en-US/firefox/addon/13152/

Cancel a scheduled task in javascript

More than often, the application UI consists in one master table that is used to refresh a slave one (item-details view).

When the user selects one record of the item list, the detail frame is refreshed with the fields related to this item. We use AJAX request to refresh the detail view.

However, multiple useless requests may occur when the user scrolls quickly through the master table. This can be avoided if we decide to refresh the detail view only if the user selection remains the same for a certain time.

The example below presents such mechanism.

The showDetails() function is called by a UI event such as onMouseOut().  The trick consist in delaying the refresh (by one second here), via a setTimeout() function. We keep track of the scheduled call in a global variable. This allow us to cancel the request in case another item in selected in the meantime.

var reqID = null; // Global var to avoid multiple requests when scrolling through the Item table
 
function showDetails(selectedItem) {
    if (reqID){
         // If an delayed AJAX call was already scheduled , we cancel it
        clearTimeout(reqID);
        reqID=null;
     }
 // Schedule a delayed ajax call (1s)
 reqID = setTimeout( function() { myMagicAjaxCall(selectedItem);}, 1000);
}

Thanks to StackOverflow article for the initial suggestion

An easier search with vim

Use incremental (search as you type) and case insensitive search in vim.

Edit ~.vimrc to add:

:set incsearch
:set ignorecase
:set smartcase
:set nu

ignorecase allow a case-insensitive search.  When smartcase is also used, it makes the search case-sensitive if the searched term contains an uppercase.

Thanks to Linux Magazine for the original article:

http://www.linux-magazine.com/w3/issue/85/Vim_Tricks.pdf

Allow not compatible extension in firefox 3.6

When upgrading firefox, I cannot use extension which have not been flagged as compatible with the new version yet (open book for example).

Just add an entry in the about:config page to let firefox run it (at your own risks )
Add a boolean entry:

extensions.checkCompatibility.3.6

and set it to

false

The syntax evlolved since firefox 3.6 (the version number was not mentionned explicitly before).
Refer to http://le-moulin-de-verre.com/fieldnotes/?p=111 for firefox prior to 3.6.

Mozilla reference: http://kb.mozillazine.org/Extensions.checkCompatibility

KSH vi mode (auto complete)

Daily, I log into unix servers where the only installed shell is KSH.
I really miss the the auto-completion provided by the ‘tab’ key of BASH shells.

Something similar can be activated on KSH, by setting it to to the so called ‘VI’ mode.

set -o vi

in your .profile or .login scripts.
You can now enjoy the vi editor commands (and more) right from the command prompt.

To envoke the editor, simply hit the ESC key. Just like going from input mode to command mode inside of vi. Some of the more useful key strokes:

ESC+\ = autocomplete, will complete upto the non-unique character.
ESC+* = space delimited list of all files that match the pattern you started with.
ESC+/str = search the commandline history for str.
ESC+n = search for the next occurance of str.
ESC+k = go back one in the commandline history.
ESC+j = go forward one in the commandline history.
ESC+$ = go to the end of the current line
ESC+0 = go to the beginning of the current line
ESC+i = return to insert mode
ESC+A = append to the end of the current line
ESC+I = insert from the beginning of the current line
ESC+fx = move cursor to the right until the next occurance of x
ESC+Fx = move cursor to the left until the next occurance of x
ESC+x = delete character under cursor and place it in the buffer
ESC+p = place the contents of the buffer after the cursor
(combining the last two keystrokes)
ESC+xp = transpose two characters (I use this alot)

Allow connection sshd from other hosts

I set up an SSH server using Cygwin on windows. I was able to test it localy (ssh myAccount@localhost) but I encountered an error when trying from a distant machine.

ssh_exchange_identification: Connection closed by remote host

We have to allow connection from a distant machine inside /etc/hosts.allow on the server.
The syntax of this file is

<services separated by coma>:<hosts or IP separated by coma>[:command]

where command is the command to execute on a connection attempt

So I remove the PARANOID deny from the allow file (!?) and explicitly logged connection attempts from ssh.

# hosts.allow   This file describes the names of the hosts which are
#               allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
ALL : localhost 127.0.0.1/32 [::1]/128 : allow
ALL : PARANOID : deny
sshd: ALL
# hosts.allow   This file describes the names of the hosts which are
#               allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
ALL : localhost 127.0.0.1/32 [::1]/128 : allow
# sshd: ALL
# same directive while keeping track of attemps
shd: ALL: spawn (echo "Attempt from %h %a to %d at `date` by %u" | tee -a /var/log/sshd.log)