Monday, December 19, 2011

Connecting to HTTPS site with specific certificate in PHP

Here is an example how you could connect to a server, which requires that you identify yourself with a certificate.
Your certificate and the server certificate are signed by an authority whose certificate is in ca.ctr.

Wednesday, December 14, 2011

Match multiple patterns with a single regex expression

I wanted to add multiple patterns to single regex expression. Such as password check. For example:

Friday, October 21, 2011

solved maven error "NoClassDefFoundError" ComponentLifecycleException


niskia:/xxyyzz# mvn jar:jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/component/repository/exception/ComponentLifecycleException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.privateGetPublicMethods(Class.java:2547)
at java.lang.Class.getMethods(Class.java:1410)
at org.codehaus.classworlds.Launcher.getEnhancedMainMethod(Launcher.java:195)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:294)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.component.repository.exception.ComponentLifecycleException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195)
at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255)
at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 9 more

The solution was reinstalling maven. For debian is done by:

apt-get remove maven2
apt-get install maven2

Monday, October 10, 2011

Problems with graphics in Mantis bugtracker in Linux

I installed Mantis BT, but graphic summaries do not show up. I went to Summary -> Per state and all i saw was:

Synthesis graphs by status
Unable to read/find font

It was shown for all graphic screens in summary menu.

With little tuning I get success in Debian:

Thursday, September 22, 2011

Problems with Expose Gallery (for Joomla) under PHP 5.3

Note: A fixed version of the module is available here.

The main issue is that the gallery do not shows. If you try to open the gallery in Internet Explorer, you will see a JavaScript error notification. It is caused by added "PHP deprecated" warning in a string value, which breaks some of the application's logic. This could be easily corrected manually. The file is:

Monday, September 12, 2011

OOO - Out Of Office email

Здравейте колеги,
На дати ХХХХХХХХХХХХХ ще бъда в отпуска.
Ако ви стане мъчно за мен, може да ме потърсите на някой от следните телефони:
0xxx-xxx-xxx
0xxx-xxx-xxx

За съжаление няма да имам достъп до компютър и до интернет.

Поздрави

Saturday, September 3, 2011

Unpacking with tar

Unpacking .tar.gz (.tgz) files:

tar xvzf archive.tar.gz

Thursday, September 1, 2011

Installing bugzilla on Debian

Download latest Bugzilla and unpack the archive in apache document root (or configure a virtualhost).

Pre-check in shell with command:

./checksetup.pl --check-modules


I get some missing modules:

Monday, August 29, 2011

Excel: Data validation - select a value from a list from other sheet

You could select a values for a list in other sheet. Steps for MS Office 2007 are:
1. Select the cell you want to change.
2. Data -> Data Validation -> Settings
3. Field: Allow = List
4. In Source field, enter a value similar to:

=Sheet2!$A$2:$A$5

This is the range from Sheet2 cells A2 to A5

The result is a dropdown for the value of the cell.

Tuesday, August 16, 2011

Database initialization and getting the last db schema - .bat file template

Batch file template:

@echo Setting database configuration...
@call db-config.bat
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
@echo .
@echo .
@echo .
@echo .
@echo .
@echo .
@echo .
@echo .
mysql -u %USER% --password=%PASS% --execute="DROP database %WORKING_DB%;"
@rem IF NOT %ERRORLEVEL% == 0 GOTO ERROR
mysql -u %USER% --password=%PASS% --execute="CREATE database %WORKING_DB%;"
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
mysql -u %USER% --password=%PASS% %WORKING_DB% < %MYMYSQLDIR%schema.sql @IF NOT %ERRORLEVEL% == 0 GOTO ERROR mysql -u %USER% --password=%PASS% %WORKING_DB% < %MYMYSQLDIR%update.sql @IF NOT %ERRORLEVEL% == 0 GOTO ERROR @rem mysqldump -u %USER% --password=%PASS% %WORKING__DB% --skip-add-drop-table --no-create-info --complete-insert --skip-triggers > %DB_DIR%latest-schema.sql
mysqldump -u %USER% --password=%PASS% %WORKING_DB% --skip-add-locks --skip-disable-keys --skip-set-charset --skip-triggers --skip-quote-names > %DB_DIR%latest-schema.sql
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR

@echo Seems everything to be fine, end with success
@Goto :END

:ERROR
@echo Error, stopping script...
@rem Pause if the script is run in a window (not from command prompt)
@ping -n 10 localhost > nul
@exit /b 1

:END
@exit /b 0


File db-config.bat contains some SET commands, for example:

@SET MYMYSQLDIR=G:\projects\xxx\etc\db\mysql\
@SET USER=root
@SET PASS=superlongandsecretpassword
@SET WORKING_DB=wb2
@exit /b 0

Monday, August 15, 2011

Modify primary key syntax

MySQL:

ALTER TABLE your_table DROP PRIMARY KEY, ADD PRIMARY KEY ( some_field, other_field );


There is no problem some_field to be AUTO_INCREMENT.

Friday, August 12, 2011

Easier Command prompts recognition

If you use more that one Command Prompts in Windows, you probably mess them up. An easy way to distinguish them is with color command. Write in each of them color command with different arguments. Letter color changes, yeah!

Command Prompt window #1:
color A

Command Prompt window #2:
color B

Functions in DOS Batch files

A nice tutorial:

http://www.dostips.com/DtTutoFunctions.php

MS DOS batch tips

So, by way of tribute to the dying art of the DOS Batch file, I present my top ten batch file tricks:

1 Use PUSHD / POPD to change directories
Read Scott Hanselman's writeup on PUSHD. The basic idea is that it keeps a stack, so at the simplest level you can do something like this:

PUSHD "C:\Working Directory\" ::DO SOME WORK POPD

That allows you to call the batch file from any directory and return to the original directory when you're done. The cool thing is that PUSHD can be nested, so you can move all over the place within your scripts and just POPD your way out when you're done.

Thursday, August 11, 2011

Generating JAR via batch file with error checks

@SET JAR=miteff.com.jar
del %JAR%
cd some-folder\
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
del *.class
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
javac *.java
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
cd ..\..\..
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
javac *.java
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
jar -cf %JAR% .
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
@dir %JAR%
IF NOT %ERRORLEVEL% == 0 GOTO ERROR
@echo Copy the jar to dest folder...
@copy /y %JAR% X:\

@echo Seems everything to be fine, end with success
@Goto :END

:ERROR
@echo Error, stopping script...
@rem Pause if the script is run in a window (not from command prompt)
@ping -n 10 localhost > nul

:END

Importing comma separated values in mysql

mysql -uroot -p --execute="USE databasename;LOAD DATA INFILE 'd:/path/sql-file.txt' INTO TABLE table_name FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'; SHOW WARNINGS"


There are a lot of problems which comma separated files make. For example:
- new lines
- commas in field

This is not recommended for migration between different kinds of databases (MySQL <-> Oracle)

Note: mysqlimport is not recommended, because it cannot show the warnings (it is feature request from year 2005, so i suppose will not be implemented)

Tuesday, August 9, 2011

Importing Oracle databases from binary dump

imp full=yes file=file-name.sql

You are not sure that file you have is in "imp" format? Check the header (birst bytes) of the file. Oracle imp binary dumps have a format similar to:

??EXPORT:V10.02.01
DSYS
RUSERS
4096
0
32
0

Thursday, July 28, 2011

Adding JAXB / jxc support in maven

Put your schemas (*.xsd) and bindings (*.xjb) into the src/main/resources folder.
Correct pom.xml as you add:
<build>
 <plugins>
  <plugin>
   <groupId>org.jvnet.jaxb2.maven2</groupId>
   <artifactId>maven-jaxb2-plugin</artifactId>
   <executions>
    <execution>
     <goals>
      <goal>generate</goal>
     </goals>
     <configuration>
      <args>
       <arg>-nv</arg><!-- this disable strict schema validation -->
      </args>
     </configuration>
    </execution>
   </executions>
  </plugin>
  <plugin>
   <inherited>true</inherited>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
    <source>1.5</source>
    <target>1.5</target>
   </configuration>
  </plugin>
 </plugins>
</build>

First steps in maven - empty project

First way - iteractive
Go to the directory, where you want to place the folder of the new project (d:\projects)
mvn archetype:generate
Some output from maven show. We run the interaction version. Here are my answers to it:
Choose a number: 112:
Choose version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6: 5
Define value for property 'groupId': : com.YOUR_COMPANY.YOUR_PROJECT_PACKAGE
Define value for property 'artifactId': : PROJECT_NAME
Define value for property 'version':  1.0-SNAPSHOT: : PROJECT_VERSION
Define value for property 'package':  com.YOUR_COMPANY.YOUR_PROJECT_PACKAGE: :
Confirm properties configuration:
groupId: com.YOUR_COMPANY.YOUR_PROJECT_PACKAGE
artifactId: PROJECT_NAME
version: PROJECT_VERSION
package: com.sepbulgaria.eshop.messages
You are ready!

Second way - non-interactive

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -Dversion=1.0-SNAPSHOT -DinteractiveMode=false

Wednesday, July 27, 2011

Extending enums in Java

public enum DataStatus
{
    DECLINED_BY_USER("DECLINED-BY-USER"),
    SUCCESSFUL("SUCCESSFUL"),
    SPAM("SPAM");

    private String code;
    
    private DataStatus(String code) {
         this.code = code;
    }
    
    public String getCode() { return code; }
    
    public String toString(){ return code; } // if you want it so
    
    public static DataStatus parse( String s ){
        s = s.toUpperCase();
        if( s.equals( "SUCCESSFUL" ) )
            return SUCCESSFUL;
        if( s.equals( "DECLINED-BY-USER" ) )
            return DECLINED_BY_USER;
        if( s.equals( "SPAM" ) )
            return SPAM;
        return null;
    }
}    

Monday, July 18, 2011

kickstart commands for mysql (create database & user)

mysql -u root -p --port=3306

CREATE DATABASE database_name;

CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';

GRANT SELECT,INSERT,UPDATE,DELETE,DROP,CREATE       ON database_name.* TO 'user1'@'localhost';
GRANT SELECT,INSERT,UPDATE,DELETE,DROP,CREATE,ALTER,INDEX ON database_name.* TO 'user1'@'localhost';

FLUSH PRIVILEGES;


(mysql database) UPDATE user SET Password=PASSWORD('new_pass') WHERE User='username';

(mysql database) UPDATE user SET User='username_new' WHERE User='username_old';


For everyone host use '%' instead of 'localhost'

Wednesday, July 13, 2011

svn.exe for Windows

The problem is that tortoise svn comes without svn.exe, no command utility exists... Bad for all black screen fans.

The solution is to download svn-win32-1.6.6.zip from here, or newer version, if available. Point PATH variable to bin folder and you are done. All needed DLL are inside the archive.