Spring autowire values in @Controller

The Java Spring framework allows you to annotate classes via the _@Controller _annotation. This allows you to maps requests and handle them via a MVC implementation. These classes can be detected automatically via a:

<context:component-scan base-package="example.class" />

The downside of this approach is that the values cannot be set anymore via a tag, because the class is already constructed. In order to still be able to set values in the class use the @Value annotation in the attribute fields of the class.

Leave a Comment

MySQL skip replication

Replication in MySQL is a useful tool to build a fast and reliable database infrastructure. But replication can go wrong, which leaves the MySQL slave unable to execute the queued query. This halts the entire replication process, replication commands after that are also not executed.

The cause for the replication problem can be determined by logging in and the slave and executing the command:

SHOW SLAVE STATUS\G

This shows the following output if replication is running correct, the important attribute is the Slave_IO_State:

mysql> show slave status\G
    *************************** 1. row ***************************
                 Slave_IO_State: Waiting for master to send event
                    Master_Host: 127.0.0.1
                    Master_User: replication
                    Master_Port: 3306
                  Connect_Retry: 60
                Master_Log_File: mysql-bin.000045
            Read_Master_Log_Pos: 53443450
                 Relay_Log_File: mysqld-relay-bin.001454
                  Relay_Log_Pos: 53443587
          Relay_Master_Log_File: mysql-bin.000045
               Slave_IO_Running: Yes
              Slave_SQL_Running: Yes
                Replicate_Do_DB:
            Replicate_Ignore_DB: mysql
             Replicate_Do_Table:
         Replicate_Ignore_Table:
        Replicate_Wild_Do_Table:
    Replicate_Wild_Ignore_Table:
                     Last_Errno: 0
                     Last_Error:
                   Skip_Counter: 0
            Exec_Master_Log_Pos: 53443450
                Relay_Log_Space: 53443587
                Until_Condition: None
                 Until_Log_File:
                  Until_Log_Pos: 0
             Master_SSL_Allowed: No
             Master_SSL_CA_File:
             Master_SSL_CA_Path:
                Master_SSL_Cert:
              Master_SSL_Cipher:
                 Master_SSL_Key:
          Seconds_Behind_Master: 0
    1 row in set (0.00 sec)

It may be that a certain CRUD command cannot be executed, this will be displayed in the same attribute that now shows everything is okay. After examination you may decide to skip that action, because it is not important or you decide to execute it manually. Execute the following command to skip 1 command:

SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;

For more information on replication and other skipping possibilities read this article on ducea.com.

Leave a Comment

Use git-svn for SVN repositories

Recently I came across the possibility to use git to access SVN repositories. Basically you use the command

git svn ...

to checkout a SVN repository. This is then stored locally on your hard drive and accessible as an ordinary git repository. Updating your local checkout is done by issuing

git svn rebase

committing the changes back to SVN is done easily by issuing a

git svn commit

command.

This solution looks a very nice solution for older code sources which are still using SVN. There are some ifs and buts of course, with one the biggest remarks that branching and merging from your git-svn checkout back to SVN is discouraged because of the very different nature in branching between git and svn.

Leave a Comment

Mount SMB network folder in local folder on Windows

The mklink command is available in Windows since Windows Vista. It allows you to map a location as a subfolder on a NTFS file system. This behavior is comparable to the Linux ln alternative. SMB/CIFS network folders can also be mapped using this technique.

The command to do this is:

mklink /d C:\Folder\ShareName \\Server\ShareName\Directory\

The command explained:

  • /d is a flag that tells mklink to create a directory symbolic link instead of the default, a file symbolic link
  • C:\Folder\ShareName is the destination locate to map the network share to
  • \\Server\ShareName\Directory is the SMB network folder location to use as source A requirement is that the \\Server\ShareName\Directory location has been visited before and the credentials to access the share have been stored. Once the command has been executed the network folder is directly available at \\Server\Sharename.

Leave a Comment

Setting a PHP configuration value via htaccess

An Apache .htaccess file can be used to set specific configuration values for PHP in a website. This is a useful feature when looking for a temporary PHP setting specific to that website; for example when doing an upgrade.

To set a value use: _php_value _. Setting a boolean value is done using php_flag Off|On. An unlimited execution time can be set for example by placing php_value_time_limit 0 in the .htaccess file.

Overriding a PHP setting via .htaccess is not always allowed in the site configuration. To allow this the Options option must be added to the AllowOverride directive in the Virtualhost configuration of the site.

Leave a Comment

Easy WordPress update via SSH

Have you ever struggled with the automated update feature of WordPress, not being able to use it because it requires FTP? FTP is by design a “not really secure” protocol, so if it can be avoided, avoid it. There is a plugin called SSH SFTP Updater Support which enables updates via SSH/SCP.

When using it I encountered an issue with the php_time_limit being to short (30 seconds); so I temporarily set it to 0 (unlimited) via a .htaccess file.

Leave a Comment

Concatenate files under Windows

Recently I found the need two concatenate two javascript files in a build script under Windows. Using Linux concatenating two different files is easy using the cat command. It turns out that using Windows it is also trivial.

copy /b script1.js+script2.js combined.js

That’s it, really easy. The /b operator is added to let copy handle the files as binary files, for safety reasons.

If the destination file already exists, copy will prompt to overwrite. This prompt can be set to Yes by default by adding the /y option.

copy /b /y script1.js+script2.js combined.js

When combining files from different folders, e.g. ..\script1.js+.\htdocs\script2.js make sure you are using backslashes and not forward slashes in the path.

Leave a Comment

PHP Whitespace check

Did you ever find yourself with unwanted whitespace at the start or end of your document? A tip to prevent this beforehand is to never close the PHP file with a _?> _tag. These tags are not required. It is a common practice on several projects.

If this is too late and you do have whitespace, execute the snippet below in the root folder to find the culprit.

<?php
foreach (glob('\*\*/\*.php') as $file){
	if (preg_match('/\?'.'>\s\s+\Z/m',file_get_contents($file)))
		echo $file . PHP_EOL;		if( preg_match('/^[\s\t]+<?php/', file_get_contents($file)) )
		echo $file . PHP_EOL;
}

This code will match both the whitespace starting before the open and after the close tag.

Leave a Comment