Articles in the ‘Programming’ Category

Crystal Reports for Visual Studio 2010 DisplayGroupTree is obsolete

Monday, February 6th, 2012

Public Property DisplayGroupTree As Boolean’ is obsolete.

In this version Crystal Reports can have a parameter panel. I now have to tell crystal reports what will be displayed in the left panel:

  • the group tree
  • the parameter panel
  • nothing

The parameter is ToolPanelView. If you don’t want to show nothing in the left panel:

rptViewer.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None

Convert MYSQL tables to INNODB script

Tuesday, July 12th, 2011

If you want to convert MYSQL tables to INNODB use the following script:

mysql -u root -p -e "SHOW TABLES IN DATABASE-NAME;" | tail -n +2 | xargs -I '{}' echo "ALTER TABLE {} ENGINE=INNODB;" > alter_table.sql
and then run:
perl -p -i -e 's/(search_[a-z_]+ ENGINE=)INNODB/\1MYISAM/g' alter_table.sql

Replace “DATABASE-NAME” with your database name. You also need root access (preferably).

How to add MSSQL support in PHP5 cPanel CENTOS

Thursday, June 2nd, 2011

If you want to add MSSQL support in PHP5 cPanel CENTOS, follow the next steps:

1. First, we need to install FreeTDS
wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar -zxvf freetds-stable.tgz
cd freetds-*

2. Begin the configuration process:
./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld

Note
Use tdsver=8.0 if you have SQL 2000/2005, tdsver=7.0 if you have SQL 7.0….

3. Compile FreeTDS
make && make install

4. Add the following line in the file /etc/ld.so.conf :
include /usr/local/freetds/lib

5. Run the following command
ldconfig -v

6. Add mssql to compile options of EasyApache
nano /var/cpanel/easy/apache/rawopts/all_php5
and add:
--with-mssql=/usr/local/freetds

7. Run /scripts/easyapache or build it from WHM. You don’t need to select any additional options here. Just build it. Once the build completes, you should now be able to use PHP’s MSSQL connector functions.

Note
If you are running a 64bit OS and get an error about configure: error:
Could not find /usr/local/freetds/lib64/libsybdb.a|so
then you need to do the following:


ln -s /usr/local/freetds/lib/libsybdb.so.5 /usr/lib64/libsybdb.so.5
ln -s /usr/local/freetds/lib/libsybdb.so.5 /usr/local/freetds/lib64/libsybdb.so
ldconfig -v

Debug imap connections in Ruby Rails or Redmine

Wednesday, February 2nd, 2011

If you want to debug IMAP connections / operations in Ruby Rails or Redmine follow these steps:

nano /var/www/redmine/lib/redmine/imap.rb

and add after require ‘net/imap’


Net::IMAP.debug = true

How to install PECL uploadprogress for Drupal?

Friday, December 17th, 2010

Installing from cPanel will mostly sure fail. If you want a quick fix, here is how to do it.

Download the latest uploadprogress package from here
wget http://pecl.php.net/get/uploadprogress-1.0.1.tgz
tar xvfz uploadprogress-1.0.1.tgz
cd uploadprogress-1.0.1
phpize
./configure
make
make install

Edit /usr/local/lib/php.ini
nano /usr/local/lib/php.ini
and copy paste at the end of the file:
extension=uploadprogress.so
and at last, restart Apache:
service httpd restart

How to install Memcache in cPanel?

Tuesday, September 28th, 2010

Take a coffee, this is going to be a long process.

Step 1: Configure Apache
Login to cPanel and start EasyApache. At the Exhaustive Option List choose Memcache. Compile Apache & Restart it.

Step 2: Memcache requires LibEvent
LibEvent can be downloaded from Monkey.org. Download the last 1.4.x available version.

wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
tar xvfz libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure; make; make install

Step 3: Register LibEvent

nano /etc/ld.so.conf.d/libevent-i386.conf

Add the following text inside:

/usr/local/lib/

and at last, run:

ldconfig

Step 4: Compile and install Memcache (deamon)
Now you can install Memcache with the last version from their site.

wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
tar xvfz memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure; make; make install

Step 5: Install PHP extension for Memcache
Normall, you should be able to do this from cPanel but i get a compiling error. So here is an alternative:

wget http://pecl.php.net/get/memcache-3.0.3.tgz
tar xvfz memcache-3.0.3.tgz
cd memcache-3.0.3
phpize
./configure
make
make install

Edit /usr/local/lib/php.ini

nano /usr/local/lib/php.ini

and copy paste at the end of the file:

extension=memcache.so

and at last, restart Apache:

service httpd restart

Step 6: Run Memcache as a deamon on the startup files

nano /etc/memcached.conf

and add inside:

#Memory a usar
-m 16
# default port
-p 11211
# user to run daemon nobody/apache/www-data
-u nobody
# only listen locally
-l 127.0.0.1

create the startup files

touch /etc/init.d/memcached
chmod +x /etc/init.d/memcached

and add inside it

nano /etc/init.d/memcached

the following text

then run:

touch /usr/local/bin/start-memcached
chmod +x /usr/local/bin/start-memcached

and add inside the following text

Now, let’s test the scripts:

/etc/init.d/memcached restart

and review if the conf file is parsed ok:

ps aux | grep memcached

and last, add memcached as autostart deamon

/sbin/chkconfig memcached on
/sbin/chkconfig --list | grep memcached

it should output:

memcached 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Step 7: Test Memcache in PHP
Create the memcache.php file and add this text
You should have in the browser:

String to store in memcached.

How to configure UTF8 default collation in MySQL?

Wednesday, July 14th, 2010

How to configure MySQL to use UTF8 (UTF8_general_ci) as default collation in MySQL for the new databases?

Step 1:
Add in in /etc/my.cnf the following lines:


[mysql]
default-character-set=utf8
[mysqld]
collation_server=utf8_unicode_ci
character_set_server=utf8
default-character-set=utf8
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'

Step 2: Restart MySQL
/etc/init.d/mysql restart

Solve uninitialized constant ApplicationController in Rails 2.3 , Rails 2.3.2

Wednesday, July 7th, 2010

Once you upgrade to Rails 2.3.X you might get:


uninitialized constant ApplicationController

To solve this run in the application folder:

rake rails:update

In Rails 2.3.x application controller is no longer called application.rb but application_controller.rb.

Working with DBF file (dBase IV) from vb .net (create dbf, insert into, select from)

Friday, March 5th, 2010

I search a lot for this, it’s a little old, but if you needed, here it is the sample code:

Dim con As New OleDb.OleDbConnection
Dim com As New OleDb.OleDbCommand
con.ConnectionString = “Provider=vfpoledb.1;Data Source=dir.dbf;Collating Sequence=machine”
con.Open()
com.Connection = con
com.CommandText = “INSERT INTO dir (col1) VALUES (‘” & val1 & “‘)”
com.ExecuteNonQuery()

If you want a select, it is similar, replace the sql command.

And here is the code for creating a dbf file:

Dim dBaseConnection As New System.Data.OleDb.OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0;” & _
“Data Source=” & path & “;” & _
“Extended Properties=dBase IV”)

dBaseConnection.Open()

‘New table
Dim SQLCreateCommand As String
SQLCreateCommand = “CREATE TABLE SUBDIR ” & _
“(subdir TEXT(50))”

Dim dBaseCommand As New System.Data.OleDb.OleDbCommand(SQLCreateCommand, dBaseConnection)

dBaseCommand.ExecuteNonQuery()
dBaseConnection.Close()

In the code above, path is the directory where you want to create the DBF file, it does not include the filename!

Update:
You can download Microsoft OLE DB Provider for Visual FoxPro 9.0 for the above code from
here.

Adding a function or procedure description in vb.net

Tuesday, February 16th, 2010

A searched a lot for this issue,  and although some sites suggested that it is a hard thing to do in VB.NET and that in C# is much easier, I finally found the code for adding a description to a function or to a procedure and it’s quite easy:

”’ <summary>
”’<para>Non-HTML files like Adobe Acrobat PDF files and Word
”’documents are stored with their original URLs partially
”’encoded in their filenames. This function will return the
”’original URL of the file.</para>
”’<para>The encoding done by the Index Server Companion removes
”’characters that cannot be present in Windows filenames
”’(these are: \/:*?”<>|). The decoding performed is:</para>
”’ <list type=”table”>
”’ <listheader><term>Find</term><description>Replace</description></listheader>
”’ <item><term>^f</term><description>\</description></item>
”’ <item><term>^b</term><description>/</description></item>
”’ <item><term>^c</term><description>:</description></item>
”’ <item><term>^s</term><description>*</description></item>
”’ <item><term>^q</term><description>?</description></item>
”’ <item><term>^d</term><description>\</description></item>
”’ <item><term>^l</term><description><</description></item>
”’ <item><term>^g</term><description>></description></item>
”’ <item><term>^p</term><description>|</description></item>
”’ </list>
”’ </summary>
”’ <param name=”FileName”>The document’s original filename.</param>
”’ <returns>Decoded filename</returns>
”’ <exception cref=”System.Exception”>Throws an exception when something goes wrong.</exception>
Private Function VBCreateURLFromFileName(ByVal FileName As String) As String

Try
‘Remove o_ prefix from URL
FileName = FileName.Substring(2, FileName.Length – 2)

‘Remove other encoded characters
FileName = FileName.Replace(“^f”, “\\”)
FileName = FileName.Replace(“^b”, “/”)
FileName = FileName.Replace(“^c”, “:”)
FileName = FileName.Replace(“^s”, “*”)
FileName = FileName.Replace(“^q”, “?”)
FileName = FileName.Replace(“^d”, “”"”)
FileName = FileName.Replace(“^l”, “<”)
FileName = FileName.Replace(“^g”, “>”)
FileName = FileName.Replace(“^p”, “|”)
FileName = FileName.Replace(“^f”, “\\”)
FileName = FileName.Replace(“^f”, “\\”)
FileName = FileName.Replace(“^f”, “\\”)
FileName = FileName.Replace(“^f”, “\\”)
Catch

End Try

Return FileName

End Function

The code was found here.