Arrow

Posts on this site are never sponsored.

Logging Varnish variables to a file

Much of the documentation regarding Varnish logging is around varnishlog (makes sense, considering the name), which parses the Varnish request and response logs from system memory. However, what about when you’re building or troubleshooting your VCL configuration file and want to dump specific variables or messages to a file? This is not widely documented but quite easy to do.

The key function is std.syslog. In order to use that function, you simply have to enable the std (standard) Varnish module, which is the only built-in “vmod” and is thus natively available and doesn’t have to be compiled.

To enable the std module, simply put this at the top of your VCL file:

import std;

Then, you can use it in any of the VCL functions like this:

std.syslog( 180, "VARNISH: Invalid cookie found." );

Or, add in some variables to your log message:

std.syslog( 180, "VARNISH: beresp.ttl is " + beresp.ttl );

This will log the message to general system messages log, which is often at /var/log/messages on Linux operating systems. The first parameter, which is 180 in the examples above, is the priority value.

Coast to Coast Hockey Shop review: roller hockey equipment in Vancouver

After having played indoor roller hockey for many years, I needed to replace my rollerblade (or “inline skate”) wheels and the accompanying screws.

I purchased some new wheels and bearings at The Hockey Shop in Surrey and had a good experience there. Unfortunately, my old screws were still coming loose every game. I could either buy some thread lock material to apply to the existing screws or buy some new screws. I waited too long and some of the threads got warped, so I decided to just buy some new screws.

At first, I couldn’t find a store that sold screw and axle kits for rollerblade wheels. In fact, someone at Sportchek told me that I shouldn’t even bother trying, as no one would carry such replacement screws for my old Mission skates anymore.

Thankfully, I found Coast to Coast Hockey Shop, which is a Vancouver-based online store that sells all sorts of inline hockey accessories, including wheels, bearings, bearing lubricant, tape, stick tape, and yes, screw / axle / bolt kits:

Mission roller hockey screws and axles

The owner, Sean, ships fast and even hand delivers sometimes in the Vancouver area (which is what happened to me). He was responsive, friendly, eager to listen to my needs, and seems to really know his stuff about all things roller hockey.

I found the Coast to Coast Hockey Shop website easy to use and full of great prices, and I highly recommend it. Sean is working on opening a retail store in Vancouver at some point soon (Update: Sean is partnering with Shop-Task on Main Street between 1st and 2nd Avenue), which I expect will be a very useful resource for indoor and outdoor inline skaters.

Changing the cursor position in TinyMCE

Many open source content management systems use TinyMCE for rich text / WYSIWYG editing, including WordPress, Drupal, eZ Publish, Joomla, Alfresco, and more.

Inserting custom layouts in TinyMCE can be accomplished by using the custom block feature, or “custom tag” in eZ Publish.

TinyMCE custom block

The problem with the custom block is that if you have multiple custom blocks adjacent to each other, nested custom blocks, or a custom block at the end of the rich text content, your cursor gets “stuck” at the bottom of the custom block. Pressing “Enter” on your keyboard will create a new line or paragraph within a custom block but you cannot create a new line or paragraph outside of the custom block without editing the source HTML or XML.

For eZ Publish, my company wrote a small TinyMCE plugin that will create a new line or paragraph directly after a custom block when “CTRL+Enter” is pressed on the keyboard.

Most of the plugin code is standard and well-documented functionality on how to create a TinyMCE plugin and generally manipulate HTML using JavaScript. The most challenging part was getting the code right to simply place the cursor at the beginning of the new paragraph (so that the user can continue to type and enter content there).

The most popular solution I found when searching was as follows, but it did not work in Chrome and other WebKit browsers: the cursor would simply stay within the custom block.

# ed is the TinyMCE editor instance, or tinymce.Editor
ed.selection.select( newParagraph);
ed.selection.collapse( false );

Other suggested alternatives that I could find were ed.focus(); and ed.selection.setNode( newParagraph );. I even tried a standard jQuery function $( ‘#target’ ).mousemove();

In the end, the solution that works in all standard browsers is to use the very aptly named setCursorLocation function, which appears to be documented only for TinyMCE 4.x, but also exists and works for TinyMCE 3.x.

I’ve pasted the code snippet below, and you can also see the full plugin file here.

ed.onKeyDown.add( function( ed, e )
{
    // Capture CTRL+Enter
    if( ( ( e.keyCode == 13 ) || ( e.keyCode == 10 ) ) && ( e.ctrlKey == true ) )
    {
        var dom = ed.dom;
        
        var parents = dom.getParents( ed.selection.getNode() );
        for( var i=0; i < parents.length; i++ )
        {
            currentNode = parents[i];
            // Insert empty paragraph at the end of the parent of the closest custom tag
            if( currentNode.nodeName == 'DIV' && currentNode.getAttribute( 'type' ) == 'custom' )
            {
                // dom.insertAfter doesn't work reliably
                var uniqueID = dom.uniqueId();
                jQuery( '<p id="' + uniqueID + '"><br /></p>' ).insertAfter( currentNode );
                
                // Move to the new node
                var newParagraph = dom.select( 'p#' + uniqueID )[0];
                ed.selection.setCursorLocation( newParagraph );

                // Don't create an extra paragraph
                e.preventDefault();
                break;
            }
        }
    }
});

Cinnamon toothpaste in Metro Vancouver

A friend from out of town was recently in search of cinnamon gum and toothpaste in Metro Vancouver. While we were able to find cinnamon chewing gum in most grocery stores and drug stores, cinnamon toothpaste was harder to find. Canadians seem to enjoy only one flavour of toothpaste: mint. There are endless varieties of mint of course…

In case you are also searching for cinnamon toothpaste, we found it in 2 stores: Pharmasave (at least in New Westminster and North Delta) and Target (at least in North Delta).

Crest 125mL: $4.49 at Pharmasave; $2.97 at Target
Crest cinnamon toothpaste

Close-Up 100mL: $1.49 at Pharmasave; $0.97 at Target
Close-up cinnamon toothpaste

Sending money from Canada to Brazil with XE Trade

I’ve previously written about using XE Trade for currency exchange: exchanging Canadian dollars for US dollars and sending money internationally. In both cases (including sending money to the UK and Australia), there are no fees charged by XE Trade except for the exchange rate spread (since, as with all currency exchanges, they charge more than the mid-rates).

My company recently had to send money from Canada to Brazil. We first used PayPal, but for the amount involved, the fees were quite high. So we looked at XE Trade. Unfortunately, there are no fee-free options when sending money to Brazil, and it was a bit more complicated than sending money to the UK or Australia.

The first thing to be aware of when sending money to Brazil is that the standard international currency is US dollars, so all foreign currencies that arrive are first converted to US dollars. Therefore, we had a couple of options:

  • Send a US dollar wire transfer directly to XE Trade
  • Use XE Trade to convert Canadian dollars to send a US dollar wire transfer

There were a couple of problems with the first option: the XE Trade fee was $64.91 instead of $22, and we had to send a wire transfer to XE’s bank (Custom House) in the US — that would have added an additional fee. My company’s bank (RBC Royal Bank, using their RBC International Remittance option) does not currently support any online wire transfers for business accounts, and oddly does not support wire transfers to the US even from personal accounts.

With the second option, the wire transfer fee charged by XE Trade was $22, and we could pay using our bank’s online bill payment system since we were paying in Canadian dollars. For the amount that we were sending, the additional transaction costs of converting CAD to USD (instead of directly from any existing US dollars we had) plus the wire transfer fee still added to less than the fees from the first option.

In the end, it worked out well using XE Trade to send money to Brazil and it took only 2 business days for the money to arrive!