Credit goes to the original author / artist.
Thursday, December 15, 2022
Thursday, July 12, 2018
Introduction to Aspect Oriented Programming
https://glynnforrest.com/talks/php-aop/
Saturday, August 26, 2017
Enable both .py and .psp in Apache2
- Install the mod_python module for Apache2
- Open the default file at /etc/apache2/sites-available/
(Note that you will need super-user privileges for editing this)gedit /etc/apache2/sites-available/default - Go to the section
Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all #Uncomment this directive is you want to see apache2's #default start page (in /apache2-default) when you go to / #RedirectMatch ^/$ /apache2-default/ - Append this to the end of section
AddHandler mod_python .py .psp PythonHandler mod_python.publisher|.py PythonHandler mod_python.psp|.psp PythonDebug OnTo read more about Apache directives, visit http://httpd.apache.org/docs/1.3/mod/mod_mime.html - Restart Apache2:
/etc/init.d/apache2 resart - That’s all folks!
Now you can play with .py and .psp
Thursday, October 16, 2014
Create a Phar for SwiftMailer
<?php
$phar = new Phar('swiftmailer.phar', 0, 'swiftmailer.phar');
// add all files in the project
$phar->buildFromDirectory(dirname(__FILE__) . '/swiftmailer');
$phar->setStub($phar->createDefaultStub('swift_required.php'));
?>
Friday, April 4, 2014
MS SQL Server 2000 Row Numbering
select rank=count(*), a1.au_lname, a1.au_fname from authors a1, authors a2 where a1.au_lname + a1.au_fname >= a2.au_lname + a2.au_fname group by a1.au_lname, a1.au_fname order by ranksource: http://support.microsoft.com/default.aspx?scid=kb;en-us;186133
Tuesday, April 1, 2014
Moving old Subversion repositories to a new server
- Dump old repositories to files.
I used the shell script below, a customization of the script found in http://www.hossainkhan.info/content/shell-script-backup-all-your-svn-repositories
svn-dump.sh
#!/bin/sh ################################################ # # Backup SVN repos to local folder # # @author Hossain Khan # @email contact [at] hossainkhan [dot] info # @version v0.01 # @reldate 2010-03-27 ################################################ # Copyright (c) 2010 Hossain Khan # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, # copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following # conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # ----------------------- END OF LICENSE TEXT ---------------------- # Record todays date # -------------------- bakdate=$(date +%Y%m%d%H%M) echo "--------------------------------" echo "Running SVN backup $bakdate" echo "--------------------------------\n" # From where to backup repos? # --------------------------- svnrepos="/mnt/datadisk/svnrepo" echo "\nGoing to backup all SVN repos located at: $svnrepos \n" # Where to save the dump? # ------------------------ bakdest="/home/sdu/svn-backups-20140331" # Location for USB drive? (to copy backup) # ---------------------------------------- baktousb="/media/USB/Extra-BACKUP" # _________NO-COFIG-REQUIRED-BELOW-THIS-LINE___________ # First go to SVN repo folder cd $svnrepos # Just make sure we have write access to backup-folder if [ -d "$bakdest" ] && [ -w "$bakdest" ] ; then # Now $repo has folder names = project names for repo in *; do # do svn dump for each project echo "Taking backup/svndump for: $repo" echo "Executing : svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump \n" # Now finally execute the backup svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump # You can go an extra mile by applying tar-gz compression to svn-dumps # We also would like to save the dump to remote place/usb if [ -d "$baktousb" ] && [ -w "$baktousb" ] ; then # USB/other directory exists, copy the dump there echo "Going to copy $repo dump to $baktousb directory...\n" cp $bakdest/$repo-$bakdate.svn.dump $baktousb fi done else echo "Unable to continue SVN backup process." echo "$bakdest is *NOT* a directory or you do not have write permission." fi # End of backup script echo "\n\n=================================" echo " - Backup Complete, THANK YOU :-]"
- Install, configure and start subversion in the new server.
help: https://injustfiveminutes.com/2013/01/24/how-to-install-subversion-on-centos-6-x/
yum install subversion
/usr/sbin/useradd svn
passwd svn
cd /var
mkdir repos_svn
This is where our repositories will residechown -R apache:svn repos_svn/ You can use cat /etc/passwd | cut -d: -f1 and cat /etc/group |cut -d: -f1 list users & groups
chmod -R 774 repos_svn/
chmod -R 774 /var/repos_svn/
chmod g+s /var/repos_svn/
- Configure the svnserve.conf file. This file can be obtained by creating a test repository.
svnadmin create /var/repos_svn/test
cp /var/repos_svn/test/conf/svnserve.conf .
- Made the folowign modifications to the svnserve.conf file.
auth-access = write anon-access = none realm = SDU
I did not enable the "password-db = passwd" line because I'm going to use sasl2 passwords file instead of the default plain text password file. I will create the sasl2 password file first for testing and later replace it with the file from my old server (in order to migrate existing users). saslpasswd2 -f /var/repos_svn/sasl2db -u SDU testusername
svnserve -d --root=/var/repos_svn/ --config-file=/var/repos_svn/svnserve.conf
Start the subversion daemon with the global configuration file.netstat -tulpn
Check whether the daemon is listening on port 3690- Since iptables is "on" by default on CentOS and rejects any traffic on ports except 22, I had to add rules to allow svn port before testing.
/etc/init.d/iptables start chkconfig iptables on
help: http://www.cyberciti.biz/faq/turn-on-turn-off-firewall-in-linux/iptables --line-numbers -n -L # HTTP iptables -I INPUT 5 -p tcp --dport 80 -j ACCEPT # SVN iptables -I INPUT 6 -p tcp --dport 3690 -j ACCEPT /etc/init.d/iptables save
- The test repository created was available at svn://192.248.10.122/test
- Restore repository dumps.
svn-restore.sh
#!/bin/sh # From where to load repos? # --------------------------- svnrepos="/var/repos_svn" echo "\nGoing to restore all SVN repos to: $svnrepos \n" # Where to load the dump from? # ------------------------ bakdest="/root/svn-backups" # _________NO-COFIG-REQUIRED-BELOW-THIS-LINE___________ # First go to SVN repo dumps folder cd $bakdest # Just make sure we have write access to backup-folder if [ -d "$svnrepos" ] && [ -w "$svnrepos" ] ; then # Now $repo has folder names = project names for repo in *; do # do svn dump for each project echo "Restoring backup/svndump of: $repo" echo "Executing : svnadmin create $svnrepos/$repo \n" svnadmin create $svnrepos/$repo echo "Executing : svnadmin load $svnrepos/$repo < $repo \n" svnadmin load $svnrepos/$repo < $repo done else echo "Unable to continue SVN restoration." echo "$svnrepos is *NOT* a directory or you do not have write permission." fi # End of backup script echo "\n\n=================================" echo " - Restoration Complete, THANK YOU :-]"
- Copy the sasl2db password file from old server to the new server
- Relocate working copies to point to the new server
Notes
If your subersion client gives the error "Could not obtain the list of SASL mechanisms" try installing the
cyrus-sasl-md5 package and restarting the subversion daemon.If you get the error "SASL(-1): generic failure: unable to find a callback: 2" make sure that the /etc/sasl2/svn.conf file looks like below
/etc/sasl2/svn.conf
pwcheck_method: auxprop auxprop_plugin: sasldb sasldb_path: /var/repos_svn/sasl2db mech_list: DIGEST-MD5
in detail: http://www.question-defense.com/2009/06/16/could-not-obtain-the-list-of-sasl-mechanisms
Additional Resources
A shell script for easily starting and stopping subversion daemon.
svnserve.sh
#!/bin/sh
REPO_ROOT=/var/repos_svn
#SVN_UID=subversion
#SVN_GID=subversion
#. /etc/rc.status
#rc_reset
case "$1" in
start)
echo -n "Starting svnserve ... "
#startproc -u $SVN_UID -g $SVN_GID -e svnserve -d -R -r $REPO_ROOT
svnserve -d --root=$REPO_ROOT/ --config-file=$REPO_ROOT/svnserve.conf
echo "[OK]"
#rc_status -v
;;
stop)
echo -n "Shutting down svnserve ... "
#killproc -TERM svnserve
killall svnserve
#rc_status -v
;;
restart)
$0 stop
$0 start
#rc_status
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
#rc_exit
exit 0
A shell script for easily creating new project repositories.
svn-new.sh
#!/bin/bash
if [ "$#" != 1 ]; then
echo "You need exactly one parameter ."
else
if [ -d /var/repos_svn/$1 ]; then
echo "[Error]: Repository \"$1\" already exists."
else
cd /var/repos_svn
echo "Initializing the project in the repository ..."
svnadmin create /var/repos_svn/$1
chown -R www-data:svn repos_svn/
chmod -R 774 repos_svn/
echo "Done."
echo "Please use the convention of directories \\trunk \\tags \\branches for storing your project"
#echo "You may need to start the svn-server using the command \"/etc/init.d/svnserve start\""
echo "Please note that you have to Check-Out the project from the repository before working."
echo "Your repository URL is: svn://192.248.10.122/$1"
#echo "Don't forget to create the users with: htpasswd /etc/apache2/dav_svn.passwd "
echo "Don't forget to create users with: \"saslpasswd2 -f /var/repos_svn/sasl2db -u SDU \" command"
fi
fi
NAT rules for public IP access
I also defined NAT rule to the new server from my primary server to allow it access via a public IP address.
Made the folowign modification to the /etc/sysctl.conf file.
/etc/sysctl.conf
net.ipv4.ip_forward = 1
Issued following commands to configure the NAT forwarding.
sysctl -p /etc/sysctl.conf iptables -I FORWARD -i eth1 -p tcp -d 192.168.22.143 --dport 3690 -j ACCEPT # delete the reject rule to allow opening of random port to forward request iptables -D FORWARD 2 # add NAT rules iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 3690 -j DNAT --to-destination 192.168.22.143:3690 iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE # check whether successful /etc/init.d/iptables status # save /etc/init.d/iptables save
Enable listing of repositories via HTTP
yum install mod_dav_svn
# edit /etc/httpd/conf.d/subversion.conf
<Location /svn>
DAV svn
SVNParentPath /var/repos_svn
SVNListParentPath On
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
</Location>
<Location ~ "/svn/.+">
Require valid-user
</Location>
# restart httpd service httpd restart
Wednesday, August 28, 2013
NATting with iptables on Ubuntu
net.ipv4.ip_forward = 1
sysctl -p /etc/sysctl.conf
/etc/init.d/networking restart
# list rules
iptables -L
iptables -t nat -L
iptables -t nat -L -n -v
# flush rules & NATs
iptables --flush
iptables --table nat --flush
iptables -t nat -A PREROUTING -p tcp –-dport 80 -j DNAT –-to-destination 192.168.22.122:80
iptables -t nat -A PREROUTING -p tcp –-dport 3306 -j DNAT –-to-destination 192.168.22.122:3306
iptables -t nat -A PREROUTING -p tcp –-dport 2222 -j DNAT –-to-destination 192.168.22.122:22
iptables -t nat -A POSTROUTING -j MASQUERADE
####### Auto Loading Rules at System Start-up #######
#1 save rules to file
iptables-save > /etc/iptables.rules
#2 find interfaces
iwconfig
ifconfig
#3 edit config file
vi /etc/network/interfaces
#4 add line to relevent interface (iface eth1)
pre-up iptables-restore < /etc/iptables.rules
Thursday, March 21, 2013
MySQL Data Types & Sizes
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
Why DATETIME and TIMESTAMP?
http://www.tech-recipes.com/rx/22599/mysql-datetime-vs-timestamp-data-type/
Thursday, January 10, 2013
See all connected users to MySQL
Caveat: you need to execute this command as a user with the PROCESS privilege in order to see all of the other users who are connected to the database. Otherwise, you see only those server threads that belong to the same user as the one making the query.
Thanks to : David Harper - Cambridge, England
Reference: http://dev.mysql.com/doc/refman/5.0/en/show-processlist.html
Wednesday, January 2, 2013
Proxying via Apache
<Proxy *> Order deny,allow Allow from all </Proxy> ProxyRequests Off ProxyPreserveHost Off ProxyPass /proxy/ http://www.newurl.com/ ProxyPassReverse /proxy/ http://www.newurl.com/
Friday, November 2, 2012
A fork in the road...
Alice came to a fork in the road.
'Which road do I take?' she asked.
'Where do you want to go?' responded the Cheshire cat.
'I don't know,' Alice answered.
'Then,' said the cat, 'it doesn't matter.'
Lewis Carroll, 1832-1898
English Author, Mathematician and Deacon
Thursday, August 9, 2012
Mono for Android
Android SDK/AVD Manager
http://dl.google.com/android/installer_r20.0.1-windows.exe
Android SDK Platforms
Download from http://{repository url}/{relevant file-name} (hint: see repository.xml)
e.g. - Platform 4.0 http://dl.google.com/android/repository/android-14_r03.zip
Move the ZIP file to {sdk-path}\temp directory and use SDK Manager to install the respective platform.
SDK Tools
http://dl.google.com/android/repository/tools_r20.0.1-windows.zip
JDK (1.6) for Mono (4.2.4)
http://download.xamarin.com/Installer/MonoForAndroid/jdk-6u31-windows-i586.exe
Note: JDK 1.7 is not supported
Mono for Android 4.2.4
http://download.xamarin.com/MonoforAndroid/Windows/mono-android-4.2.4.167234518.msi
MonoDevelop
Locate the downloads from: http://monodevelop.com/Download (listed below)
MonoDevelop 3.0.3.5 Installer
http://download.xamarin.com/monodevelop/Windows/MonoDevelop-3.0.3.5.msi
GTK# for .NET 2.12.10http://download.mono-project.com/gtk-sharp/gtk-sharp-2.12.10.win32.msi
.NET Framework 4.0 Standalone Installer
http://www.microsoft.com/en-us/download/details.aspx?id=17718
--------------------------------------------------------------------------------------------------------
Resource files:
http://dl.google.com/android/repository/repository-7.xml
http://xamarin.com/download/installer/Windows/MonoForAndroid/InstallationManifest.xml
Sources:
http://qdevarena.blogspot.com/2010/05/download-android-sdk-standalone-for.html
http://stackoverflow.com/questions/2766713/android-download-the-android-sdk-components-for-offline-install
Friday, November 18, 2011
C# - Draw a Rectangle on a Picture Box on Mouse-Move
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
pictureBox1.Refresh();
System.Drawing.Graphics g = pictureBox1.CreateGraphics();
System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.Blue);
g.DrawRectangle(p, new Rectangle(e.X, e.Y, 40, 80));
p.Dispose();
g.Dispose();
}
Thursday, November 17, 2011
Monday, October 17, 2011
අපි හැමදාමත් ආදරෙයි !

Thursday, October 6, 2011
Wednesday, September 21, 2011
Drag Drop with a Custom Icon in C#
Code:
http://www.switchonthecode.com/tutorials/winforms-using-custom-cursors-with-drag-drop
http://www.switchonthecode.com/tutorials/csharp-tutorial-how-to-use-custom-cursors
http://stackoverflow.com/questions/1733912/how-do-i-handle-dragging-of-a-label-in-c
Wednesday, August 17, 2011
PHP mail() on WAMP
- Install the fake sendmail. (http://glob.com.au/sendmail/)
- Configure fake sendmail to use a valud SMTP server.
example: Gmail
smtp_server=smtp.gmail.com
auth_username=your gmail username
auth_password=your gmail password
sources:
https://mail.google.com/support/bin/answer.py?answer=13287
http://www.geekzone.co.nz/tonyhughes/599
- Configure "php.ini" to use fake sendmail.
example:
sendmail_path = "c:\wamp\sendmail\sendmail.exe -t"
source:
http://www.joshstauffer.com/send-test-emails-with-wampserver/
- Restart Apache/WAMP.
- Write a call to mail() in PHP & run it.
Monday, July 25, 2011
Weather Report
Nevertheless, to be on the safe side, he replied to his Tribe that the winter was indeed going to be cold and that the members of the village should collect wood to be prepared.
But also being a practical leader, after several days he got an idea. He went to the phone booth, called the National Weather Service and asked 'Is the coming winter going to be cold?'
'It looks like this winter is going to be quite cold indeed,'the weather man Responded.
So the Chief went back to his people and told them to collect even more wood. A week later, he called the National Weather Service again. 'Is it going to be a very cold winter?'
'Yes,' the man at National Weather Service again replied, 'It's definitely going to be a very cold winter.'
The Chief again went back to his people and ordered them to collect every scrap of wood they could find. Two weeks later, he called the National Weather Service again. 'Are you absolutely sure that the winter is going to be very cold?'
'Absolutely,' The Man replied. 'It's going to be one of the coldest winters ever..''
'How can you be so sure?' the Chief asked.
The weatherman replied, 'The Red Indians are collecting wood like Crazy!!!'
Friday, July 22, 2011
Reset MySQL Root Password
Resetting the root password of a MySQL database is trivial if you know the current password if you don't it is a little tricker. Thankfully it isn't too difficult to fix, and here we'll show one possible way of doing so.
If you've got access to the root account already, because you know the password, you can change it easily:
steve@steve:~$ mysql --user=root --pass mysql Enter password: mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root'; Query OK, 2 rows affected (0.04 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.02 sec) mysql> exit ByeHowever if you don't know the current password this approach will not work - you need to login to run any commands and without the password you'll not be able to login!
Thankfully there is a simple solution to this problem, we just need to start MySQL with a flag to tell it to ignore any username/password restrictions which might be in place. Once that is done you can successfully update the stored details.
First of all you will need to ensure that your database is stopped:
root@steve:~# /etc/init.d/mysql stop
Now you should start up the database in the background, via the mysqld_safe command:
root@steve:~# /usr/bin/mysqld_safe --skip-grant-tables & [1] 6702 Starting mysqld daemon with databases from /var/lib/mysql mysqld_safe[6763]: started
Here you can see the new job (number "1") has started and the server is running with the process ID (PID) of 6702.
Now that the server is running with the --skip-grant-tables flag you can connect to it without a password and complete the job:
root@steve:~$ mysql --user=root mysql Enter password: mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root'; Query OK, 2 rows affected (0.04 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.02 sec) mysql> exit Bye Now that you've done that you just need to stop the server, so that you can go back to running a secure MySQL server with password restrictions in place. First of all bring the server you started into the foreground by typing "fg", then kill it by pressing "Ctrl+c" afterwards.
This will now allow you to start the server:
root@steve:~# /etc/init.d/mysql start Starting MySQL database server: mysqld. Checking for corrupt, not cleanly closed and upgrade needing tables..
Now everything should be done and you should have regained access to your MySQL database(s); you should verify this by connecting with your new password:
root@steve:~# mysql --user=root --pass=new-password-here Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> exit Bye

