A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Stop Confluence making CamelCase links

You can include the following code in the page, or make a macro out of it.
Note: You need to attach JQuery to one of your wiki pages, and edit the URL in the code.
{html}
<script type="text/javascript" src="/download/attachments/59835554/jquery-1.2.6.js"></script>
<script type="text/javascript"> 
//The $ notation is used by DWR. So we rely on jQuery namespace only
jQuery.noConflict();          
jQuery(document).ready(function() {
   //The camel case links have class createlink. So fetch all such links and remove the html part and retain the text part
   jQuery("a.createlink").each(function(index){
    var text = jQuery(this).text();
    if(isValidCamelCase(text)){//Only filter where we have a camelcase text and not valid yet to be created link
       jQuery(this).after(text).remove();
    }
    return true;
   });
});

function isValidCamelCase(s){
 if(s == null || s.length == 1){
  return false;
 }
 
 if(s.indexOf(' ') != -1){
  return false;
 }

 //Check for case where valid link is being created like [Test123]
 var indexOfNonUpperCaseChar = -1;
 for(var i = 0; i < s.length; i++){
  var c = s.charAt(i);
  if(!isUpperCase(c)){
   indexOfNonUpperCaseChar = i;
   break;
  }
 }
 
 if(indexOfNonUpperCaseChar == -1){
    return false;
 }
 
 var lowerCase = s.toLowerCase().substring(indexOfNonUpperCaseChar);
    var originalCase = s.substring(indexOfNonUpperCaseChar);
    if(originalCase == lowerCase){
     return false;
    }
 return true;
}

function isUpperCase(char){
 return char >= 'A' && char <= 'Z'
}
</script>
{html}

Thanks

How to fix ntpdate

# set 'server' value in config to the correct ntp date server on your network
$ sudo vim /etc/ntp.conf

# force update (1.2.3.4 is your ntp date server)
$ sudo /etc/init.d/ntpd stop
$ sudo /usr/sbin/ntpdate 1.2.3.4
$ sudo /etc/init.d/ntpd start


# check it worked (offset should be < 10)

$ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 1.2.3.4            6.7.8.3      3 u    6   64    1    3.902   -0.216   0.001
 1.2.3.5            6.7.8.4      3 u    5   64    1    1.753    0.048   0.001


Komodo IDE: Perl Remote Debugging


# Komodo IDE Remote Debugger                                                    
export PERL5LIB="/path/to/remote/debugging/libraries"
export PERLDB_OPTS=RemotePort=10.5.16.101:9009                                  
export DBGP_IDEKEY=wsheppard

Docs

Why doesn't smbclient work?

Symptoms:
You can mount a NetApp 'shared drive' using the mount program fine.
But if you try to browse it using smbclient, you get this error when it fails to connect:
session setup failed: NT_STATUS_MORE_PROCESSING_REQUIRED

Cause:
A bug in Ubuntu 11.04

Workaround:
Change your hostname to a short string, without any hypens (dashes) in it!

(copy)

Perl Tests: Better output when comparison fails

use Test::More;
use Test::Differences;

is_deeply($actual, $expected, 'foo') or eq_or_diff($actual, $expected, 'oof');

or

is_deeply($actual, $expected, 'foo') or diag explain $actual;

Use lighttpd as a proxy-pass server

$HTTP["host"] =~ "made.up.hostname" { # hostname you want to create
    $SERVER["socket"] == ":1234" { # port you want to create

        server.errorlog      = "/var/logs/madeup/lighttpd-error.log"
        accesslog.filename   = "/var/logs/madeup/lighttpd-access.log"

        proxy.server = ( "" =>
                           ( ( 
                               "host" => "123.456.789.012", # where you want to proxy to
                               "port" => 5678, # port you want to proxy to
                             ) ) 
                         )   
    }   
}

# Now go to http://made.up.hostname:1234 and you will get directed through to http://123.456.789.012:5678



smbclient commands on linux

# List all shares
smbclient -L '\\\\server-name' -U username -W DOMAIN

# Logs into server to type commands
smbclient '//server-name/sharename$' -U username -W DOMAIN

# Logs in, runs 'ls' command and disconnects

smbclient '//server-name/sharename$' -U username -W DOMAIN -c ls

# Other parameters:
-d99 = debug output
-D directory = start from directory

# Commands
get = just like FTP



See also smb2www (perl) and smb2www (c).


Configure CNTLM

0) Download cntlm
./configure
make
sudo make install

1) Generate the password hash
cntlm -u username -d DOMAIN -H

2) paste the output into the config file, and add this:
Auth NTLM

3) Run:
cntlm

4) export http_proxy=http://localhost:3128

5) You can now access web pages


See also Charles proxy

Set the date in linux

# date +%Y%m%d --set "2013-05-20"
# date +%H%M%S --set "15:30:00"

Find and kill slow postgres queries


SELECT query_start,datname,procpid,current_query FROM pg_stat_activity;
SELECT NOW();

SELECT pg_cancel_backend($PID);
-- where $PID is the number from the procpid column in the first query

See all variables in Template Toolkit

[% USE Stash %]
[% USE Dumper Indent = 1%]
<pre>[% Dumper.dump_html( Stash.stash() ) %]</pre>


Template::Plugin::Stash docs