Marius van Witzenburg "Learned my lesson in life, now setting my action to stay in life."

26Jul/100

How to upgrade CakePHP or any other package that is under subversion control with Rsync

Actually this is more simple than you might think.

First you checkout your current version. Then download and un-tar the new version and simply run the following command on your shell/terminal:

rsync -av --exclude '.svn' --exclude '._*' my/new/cakephp-cakephp-efb6e08/ my-old-cakephp/

This will exclude your Subversion .svn directories and it will also exclude the META-data files created by Mac OS X.

Good luck with upgrading! :-)

7Jul/100

How to batch rename files and use the file its own name content with Bash

In my example the files had the right content in their name only the position was wrong.

The original files their name were:

The file title - vendor_1.mp3
The file title - vendor_4.mp3
The file title - vendor_22.mp3
The file title - vendor_39.mp3

But afterwards I found this is a difficult way of searching on a vender. Which I do the most.
So, I decided to make a simple rename script to move the vendor to the beginning of the file name and the title to the end of the filename.

This would give the following filenames as result:

vendor_1 - The file title.mp3
vendor_4 - The file title.mp3
vendor_22 - The file title.mp3
vendor_39 - The file title.mp3

I hope you find this useful or that you can modify it for your own use. You can see the tiny script I used below.

#!/usr/local/bin/bash
 
root="/my/files/location"
 
find $root -type f | while read file
do
    filename=${file##*/}
    piece1=${filename%% - *}
    piece2=${filename##* - }
    extension=${filename##*.}
    newfile="${piece2%%.$extension} - ${piece1}.$extension"
    mv "${file}" "${root}/${newfile}"
done
30Jun/100

How to clear bash shell history when you log out of the command-line

On some machines I prefer to not leave a log of everything I typed on the command-line. So, I remove the logs and clear the history.
To accomplish this you have to add the lines below to ~/.bash_logout:

history -c
rm -f ~/.bash_history
rm -f ~/.history

30Jun/100

How to force your visitors to goto your website domain without www as a prefix with mod_rewrite in apache

Actually this is quite simple, you need to create a .htaccess file into your public_html / httpdocs directory and add the following piece of code:

# Force non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^mariusvw.com
RewriteRule (.*) http://mariusvw.com/$1 [R=301,L]

Of course you need to modify this to match your own domain name :-)

24Jun/100

Control a flash movie from javascript and javascript from flash movies

Personally I dislike the usage of Flash in my websites but our clients request a lot that they want animations. Now it happens that they want the animation to act upon an action to a non-flash object. This can be difficult if you have no idea how to do that. If you read below, you should have no problem with getting this job done :-)

Control your Flash Movie from Javascript:

// Play movie
document.getElementById('myFlashMovie').Play();
// Stop movie
document.getElementById('myFlashMovie').StopPlay();
// Rewind movie to beginning
document.getElementById('myFlashMovie').Rewind();
// Goto next frame of MovieClip
document.getElementById('myFlashMovie').TGetProperty(nameOfTargetMovieClip, propertyIndex);
// Goto next frame of TimeLine
document.getElementById('myFlashMovie').GotoFrame(frameNum);
// Zoom in or out the flash movie
document.getElementById('myFlashMovie').Zoom(relative percentage);
// Set variable and make it available via ActionScript
document.getElementById('myFlashMovie').SetVariable(variableName, variableValue);
// Get variable for usage in JavaScript
var myVariable = document.getElementById('myFlashMovie').GetVariable(variableName);

To control Javascript functions you can call it like this:

getURL("javascript:naam_van_functie();");

For some more information about these methods, please check out the Adobe website.

I hope this helps you out with getting that Flash Movie behave like you want it to ;-)

22Jun/100

Seven reasons why ERP (Enterprise Resource Planning) projects fail

1. Poor or undefined project objectives, roles and responsibilities, leading to unrealistic expectations being set.
2. Lack of communication between IT and the business, resulting in a mismatch of requirements and expectations.
3. No senior business sponsor and separate project manager.
4. Technology put before people: no or minimal involvement of key users during the “scoping” phase and lack of regular communication with them throughout the project implementation
5. No project success metrics.
6. No risk assessment or contingency plan.
7. Lack of regular checks to ensure the project is on track to time and budget.

17Jun/100

project: www.worldofomnia.com (terminated)

After a long period of time working on this project there is an end in the working together.

The site owner's opinion is that the building goes too slow, since I don't have much time next to my work to finish the last pieces we came at this point to pull the plug. Too bad but still it was a nice project to work for.

The future makes place for a new person to take the project, I wish the new webdeveloper good luck with building the new website for OMNIA, hope you have more time than I had :-)

Ps. I will finish the project on my own time, got some people who really wanted to see how the CMS system works. For more information about this CMS goto the page of Pim.

7Jun/100

How to use the exec() and system() function and capture the returned output.

When you want to execute a program you sometimes want to use the result of the program you executed.

exec(PROGRAM);
$result = system(PROGRAM);

Both Perl's exec() function and system() function execute a system shell command. The big difference is that system() creates a fork process and waits to see if the command succeeds or fails - returning a value. exec() does not return anything, it simply executes the command. Neither of these commands should be used to capture the output of a system call. If your goal is to capture output, you should use the backtick operator:

$result = `PROGRAM`;

Found this information in a post by Kirk Brown.

18May/100

How to Trap/Catch Keyboard Interrupt in Bash

This is a simple code snippet, I think it explains it self.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
 
myCleanup() {
  rm -f /myapp/tmp/mylog
  return $?
}
 
myExit() {
  echo -en "\n*** Exiting ***\n"
  myCleanup
  exit $?
}
 
trap myExit SIGINT
 
# main loop
while true
do
    echo -n "Enter your name: "
    read x
    echo "Hello $x"
done

If you have any questions, just ask :-)

16May/100

Download a range of files with Curl and BASH.

This is a really simple sniped how to download a range of files.

I found this very useful to download an image range of my old avatar script.
I lost my images but remembered an url where I uploaded them once. Happy me :-)

1
2
3
4
5
6
7
#!/usr/local/bin/bash
 
# Range 1 to 75
for x in {1..75}
do
    curl -O http://my.server.com/media/images_${x}.jpg
done
Page 1 of 71234567