FFMpeg conversion - wmv to flv HOWTO

More of a quick note to self about converting video formats:

To convert wmv to flash video:

ffmpeg -i input.wmv -ar 44100 -qmax 8 out.flv

This does the following:

  • -i input.wmv - Load input file
  • -ar 44100 - Resample audio to 44.1kHz.
  • -qmax 8 magic voodoo about quality. Gave better results than not using it.
  • out.flv save it as an flv.

Easy.

Split first name and last name with Openoffice/Excel

I've been dealing with a lot of spreadsheets of usernames recently and sometimes you get firstname and lastname in seperate columns, and sometimes in the same column.

If you get them in the same column but need them in two columns here are two little formulae to do it:

FullName | FirstName | Lastname |
Mark Lynch | =MID(A2,1,FIND(" ",A2,1)) | =MID(A2,FIND(" ",A2,1)+1,100) |
Which will look like:
FullName | FirstName | Lastname |
Mark Lynch | Mark | Lynch |
This basically seperates the string on the space between the names and puts it into each column

Cheers, Mark

Jmeter over SSH Socks proxy

I've been doing some testing recently where I need to connect via SSH server to a remote network to run some load testing.

To do this I used a SSH sock proxy like I have previously blogged about.

So I fired this up so that I could review the site I wanted to look at. It worked a charm through firefox but there is no where to set up the proxy in jmeter.

To make it work you need to let the JVM know what proxy to use like so:

java -DsocksProxyHost=localhost -DsocksProxyPort=8080 -jar ApacheJMeter.jar

No jmeter will use the socks proxy on port 8080 on my local machine. Nice.

Windows File Sharing (SMB/CIFS/Samba) over SSH

While working with a client recently setting up a Netgear VPN so he could securely access his internal file server. The VPN setup was straightforward but every time the VPN client connected to the VPN server the VPN server/firewall would crash - leaving no connectivity.

In order to come up with a reliable solution to this we decided to use the SSH server we had available and tunnel the windows sharing across the local port forwards, much simpler and more reliable.

Thanks to this article it was a breeze to set up.

Steps are as follows:

  • Create loopback adapter on windows
  • Configure loopback adapter on windows
  • Reboot
  • Configure SSH connection
  • Test it all out

Create loopback adapter on windows

We'll give your computer an additional (fake) IP address, and we'll port forward to that address instead of the computer's real IP. Windows XP will continue to do file sharing on the real IP address. We'll assign it an IP of 10.0.0.1 (that's what we configured putty to use above.)

  1. System->Control Panel->Add Hardware
  2. Yes, Hardware is already connected
  3. Add a new hardware device (at bottom of list)
  4. Install the hardware that I manually select
  5. Network adapters
  6. Microsoft , Microsoft Loopback Adapter
  7. (Go through the installation procedure.)

Configure loopback adapter on windows

  1. Open your new fake ethernet adapter (Network Connections) , enter a made-up IP address (I suggest 10.0.0.1, which is a privately routable address that most folk don't use.)
  2. Enable Client for Microsoft Networks.
  3. Disable File and Printer Sharing for Microsoft Networks
  4. Enable Interent Protocol (TCP/IP)
  5. Click on properties for TCP/IP.
  6. Enter your chosen IP address (10.0.0.1), subnet mask (255.255.255.0). You can leave gateway blank.
  7. Under advanced->WINS, Enable LMHosts Lookup and Disable NetBIOS over TCP/IP

Reboot

In order to make it all work now it he appropriate time to reboot so windows initialises everything correctly.

Configure SSH connection

  • Download Putty
  • Enter IP address
  • Enter Auth Key (if using SSH keys)
  • Enter Port forwards for: (these connect the ports on you local machine to
    • 10.0.0.1:137 to 127.0.0.1:137
    • 10.0.0.1:138 to 127.0.0.1:138
    • 10.0.0.1:139 to 127.0.0.1:139
    • 10.0.0.1:445 to 127.0.0.1:445
  • Save the config.

Test it all out

Now to connect you need to do the following steps:

  • Open putty, load the settings and connect.
  • Open Exporer and type in: \\10.0.0.1\

You should now be connected to your remote windows system over a secure encrypted tunnel.

Cheers, Mark

Two quick server tips

Here are two quick tips that I've recently found for server admins:

  • Automatically fixing file system errors
  • Ignoring directories from updatedb

Automatically fixing file system errors

If you have a remote server, i.e. at a data center 10km or 1000km away this should prevent some panic when rebooting the server remotely.

Ext2/3 will do a filesystem check after a certain number of reboots or time. Most of the time any errors are fixed automatically, but certain errors by default require the root shell and the administrator to fix them. I've seen a few of these happen, but I have always replied yes to the prompts as I don't know enough about file systems to fix it I said no.

So, to prevent the need to rush to a data center and plug in a keyboard and mouse just to press the "Y" key there is and option to automatically assume yes.

On Ubuntu in the file /etc/default/rcS you need to change the following:

FSCKFIX=no
to
FSCKFIX=yes

Ignoring directories from updatedb

If you have a backup server you may not want it to update the locate db for all your backup files, as it can take a very long time.

To tell locate to ignore a directory you need to add it to the PRUNEPATHS line in the /etc/updatedb.conf file like so:

PRUNE_BIND_MOUNTS="yes"
PRUNEPATHS="/tmp /var/spool /media /srv"
PRUNEFS="NFS nfs nfs4 afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf rpc_pipefs"

In the above code I have added the /srv entry to make it ignore all my backups which are held under the /srv directory.

Note: These tips were tested on Ubuntu linux, other distributions will have similar functionality but the file locations may vary.

Cheers, Mark

Installing Railo on Tomcat via Apache on Leopard - Step by Step

After a bit of fiddling and head scratching I managed to install Railo on Tomcat via Apache on my laptop running on OS X 10.5.6.

Tomcat

Firstly, download Tomcat 6

extract content:

tar xvzf apache-tomcat-6.0.18.tar.gz

Move Tomcat to a more secure place:

sudo mv apache-tomcat-6.0.18 /usr/local/tomcat

Railo

Download Railo custom version

extract and move into Tomcat lib directory:

tar zxvf railo-3.0.2.001-jars.tar.gz
sudo mv railo-3.0.2.001-jars/* /usr/local/tomcat/lib

Make Tomcat and Railo work together by modifying the web config file:

sudo nano /usr/local/tomcat/conf/web.xml

add the following inside the <web-app> element:

<servlet>
<servlet-name>CFMLServlet</servlet-name>
<servlet-class>railo.loader.servlet.CFMLServlet</servlet-class>
<init-param>
<param-name>configuration</param-name>
<param-value>{web-root-directory}/WEB-INF/railo/</param-value>
<description>Configuraton directory</description>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfc</url-pattern>
</servlet-mapping>

add the following inside <welcome-file-list> element:

<welcome-file>index.cfm</welcome-file>
<welcome-file>index.cfml</welcome-file>

Apache

Leopard OS comes with Apache 2, so you don't have to worry about installing it. However, you need to download The Apache Tomcat Connector source code.

Next you need to compile the source so that the resulting binary file is compatible with your Intel Mac architecture. I got this from Eric Rank's blog

cd into tomcat source:

cd tomcat-connectors-1.2.27-src/native

Edit the apache-2.0/Makefile.apxs.in file.

Replace

mod_jk.la:
$(APXS) -c -o $@ -Wc,"${APXSCFLAGS} ${JK_INCL}" "${JAVA_INCL}" "${APXSLDFLAGS}" mod_jk.c ${APACHE_OBJECTS}

with:

mod_jk.la:
$(APXS) -c -o $@ -Wc,"${APXSCFLAGS} -arch x86_64 ${JK_INCL}" "${JAVA_INCL}" "${APXSLDFLAGS} -arch x86_64 " mod_jk.c ${APACHE_OBJECTS}

configure the build files:

./configure --with-apxs=/usr/sbin/apxs

now go into apache-2.0 directory and build:

cd apache-2.0
make -f Makefile.apxs

Finally install

sudo make install

Now specify the connection between Apache and Tomcat. To do this you need to create workers.properties file. I created mine in /etc/apache2.

sudo nano /etc/apache2/workers.properties

Paste the following:

worker.list=default

worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

Now we need to modify the Apache httpd.conf file:

sudo nano /etc/apache2/httpd.conf

Enable The Apache Tomcat Connector:

LoadModule jk_module libexec/apache2/mod_jk.so

Underneath that tell Apache where your workers.properties file is located and add some logging info (could be useful):

# Mod_jk settings
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel debug
DirectoryIndex index.html index.htm index.cfm index.cfml

Back to Tomcat

To test our Railo installation, let's create a test site by adding a new virtual host in both Tomcat and Apache. We do this by modifying Tomcat server.xml file (/usr/local/tomcat/conf/server.xml )
<Host name="railo.local" appBase="/Users/marko/Sites/railo/www">
<Context path="" docBase=""/>
</Host>

Apache

Now we need to create a virtual host entry in Apache as well:
<VirtualHost *:80>
JkMount /*.cfm default
ServerName railo.local
DirectoryIndex index.cfm
</VirtualHost>

JkMount /*.cfm default
Tells mod_jk to use the connector specified in your workers.properties file when it encounters a .cfm extension.

Important

Notice that in my Apache VirtualHost entry there is no DocumentRoot. I originally had it in there and it was breaking my Apache-Tomcat connection. It was driving me mad. It's probably because document root is already specified in /usr/local/tomcat/conf/server.xml.

One last thing, to start your Tomcat server type in this command:

/usr/local/tomcat/bin/startup.sh

shut down

/usr/local/tomcat/bin/shutdown.sh

My assumption is that the above steps would be very similar on other operating systems as long as you use the correct file paths.

Good luck :-)

Marko

GZIP encoding in Adobe AIR/Flex - HOWTO

If you use HTTPService component in Flex or AIR to retrieve data from a server, you might want to consider gzipping the response. This can significantly reduce the packet size you get from the server, which results in a much better application performance.

This means that response packet is compressed by Apache web server and your client will need to decompress it. Fortunately, both Flex and AIR 1.5.1 natively support GZIP compression. However there are a couple of things you need to watch out for.

Firstly, you need to enable Apache Module mod_deflate in your virtual host.

In your AIR application, you need to tell HTTPService component to accept gzip encoding and AIR will take care of the rest:

<mx:HTTPService id="service" resultFormat="e4x" />
this.service.headers = {'Accept-Encoding':'gzip'};

If you are in a Flex project, specifying gzip encoding will throw the following error:

ArgumentError: Error #2096: The HTTP request header Accept-Encoding cannot be set via ActionScript.

This is because Flex apps run in a browser and the browser is responsible for determining encoding type and decompression (if required). Therefore, you cannot specify encoding type in Flex apps.

Our problem is that we use one core library for AIR and Flex applications. So the issue above can be avoided by conditionally specifying encoding type depending on the framework used. This can be done in 2 lines of code:

if(Capabilities.playerType == "Desktop")
this.service.headers = {'Accept-Encoding':'gzip'};

Note: this is not the complete solution - check out this entry for the rest of it :-)

Cheers Marko

HOWTO generate diff files from subversion

Here's a nice and quick way to generate a diff file from subversion and store it on your local machine.

svn diff filepath/myFile.ext > saveDirPath/myFile.ext.diff

Where filePath is the local path to your working directory in which your file is located. And saveDirPath is the path where you want to save your diff file.

Diff files can be very useful when contributing to open source projects.

You can also get a list of files changed between revisions.

Marko

Non-case sensitive filesystem on Linux - HOWTO

I was setting up a ColdFusion web application on my dev machine and ran into lots of errors because of the case sensitivity of Linux (which i was using) versus the non-case sensitivity of windows (where the application was developed).

I had a quick look to see if I could fix it up but quickly figured out that there were too many occurrences and so it was likely not worth fixing up at this point. To that end I set up a loopback vfat filesystem so that I could have a directory on my machine mounted as non-case sensitive.

Note: this is not recommended for production systems - but is a handy fix for a temporary development problem.

Create a virtual disk

dd if=/dev/zero of=virtual.dsk bs=1048576 count=150

Format it

mkfs.vfat virtual.dsk

Mount it

sudo mkdir /mnt/vfat
sudo mount virtual.dsk /mnt/vfat -t vfat -o loop,owner,group,umask=000

You can set this up to mount every time by putting the following line in your /etc/fstab

/path/to/virtual.dsk /mnt/vfat vfat loop,owner,group,umask=000 0 0

Note - the same trick works on OSX in reverse. I.e. if you are developing on a mac, but deploying to a linux production environment you can create a virtual disk with a case-sensitive filename, which will mean that any case sensitive issues get picked up on your dev machine, and not on your production/staging machines.

Cheers, Mark

SVN - Get list of files changed between revisions

For my own reference, here is how to get the list of files that have changed between any two subversion revisions.

svn diff --summarize -r5:10 http://svn.example.com/trunk

This will give something like:

If you want to get the revisions from a revision to the latest then you can change the 10 to HEAD - eg:

svn diff --summarize -r5:HEAD http://svn.example.com/trunk

Cheers, Mark

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.1.004.