Pages

Thursday, October 25, 2012

invalid multibyte escape (ArgumentError)

Hi! After updating from Ruby 1.8.7 to Ruby 1.9.3, I've got errors with the gem validate_as_email at line
pattern = /\A#{addr_spec}\z/
Error Message:
D:/Ruby193/lib/ruby/gems/1.9.1/gems/validates_as_email-0.5.1/lib/validates_as_email.rb:28:in `': invalid multibyte escape (ArgumentError)
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/validates_as_email-0.5.1/lib/validates_as_email.rb:13:in `'
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in `require'
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in `each'
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in `block in require'
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in `each'
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in `require'
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler.rb:128:in `require'
 from H:/BRPB2B/config/application.rb:7:in `'
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:53:in `require'
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:53:in `block in '
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
 from D:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `'
 from H:/BRPB2B/script/rails:6:in `require'
 from H:/BRPB2B/script/rails:6:in `'
 from -e:1:in `load'
 from -e:1:in `
'
The problem is that using /my_regex/ is not valid anymore. You must use instead.
pattern =  Regexp.new "\A#{addr_spec}\z", nil, 'n'

Wednesday, October 24, 2012

PHPExcel - Image in a cell

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('test_img');
$objDrawing->setDescription('test_img');
$objDrawing->setPath('assets/images/success.png');
$objDrawing->setCoordinates('A4');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

Tuesday, October 16, 2012

Remove all Ruby Gems in one command


  • Open the command manager
  • Type powershell
  • Type gem list | %{$_.split(' ')[0]} | %{gem uninstall -Iax $_ }

Thursday, August 9, 2012

DB2 Error Codes List

This site contains all DB2 Error Codes

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db2z9.doc.codes/src/tpc/db2z_n.htm

Batch Unzipping

Hi!

If you have a lot of files to unzip, you can do it by this single command.
 find . -name "*.gz" -exec gunzip {} \;

It will find all .gz files and unzip them.

Wednesday, May 16, 2012

Derby - DBVisualizer

Hi

When trying to do a simple query, with Apache Derby Database, on a table name written in CamelCase.


select *
from TBL.TmpEndpoints


I'm getting this error

 13:58:44  [SELECT - 0 row(s), 0.000 secs]  [Error Code: -1, SQL State: 42X05]  Table/View 'TBL.TMPENDPOINTS' does not exist.
... 1 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.000/0.000 sec  [0 successful, 0 warnings, 1 errors]


In order to be able to query the table, I need to add double quotes to the table name. My query is :

select *
from TBL."TmpEndpoints"

Wednesday, March 28, 2012

Excel - Padding Left

Hi!

If you want to do a left side padding, just do the following.

=REPT("0",7-LEN(A1))&A1

Where

0 = Character to be repeated
7 = Final desired lenght
A1 = Cell where to apply the transformation

For example, if the original content of cell A1 was TOTO, you will get 000TOTO

Wednesday, March 21, 2012

SOAP Web Services - Generating Java artifacts with WSIMPORT

Hi

The Java JDK comes with an easy tool to generate Java Web Services artifacts. Prefer this method instead of JBoss wsconsume because if your JBoss is too old, it will lead to some random error (ClassCastException...)

You just have to type the following command.

wsimport -s source -p com.mypackage http://mywsdlpath
:8080/method?wsdl

Friday, February 17, 2012

IP Aliasing with ifconfig (Mac)

Hi

If you want to bind another IP address to your network card, you need to do IP aliasing. It will give you many IP address for a single nic.

It will help you if you need to start two server that listen on the same ports.

For example, I need to runs two differents systems that runs on 2 differents JBoss. I need to bind each JBoss to a specific IP to prevents port collision.

Here's how to add a new IP to your Mac or Linux.

Here's my IP informations

yannlaviolette@mac:~> ifconfig
lo0: flags=8049 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010 mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8963 mtu 1500
ether 00:1e:c2:0a:d6:2e
inet6 fe80::21e:c2ff:fe0a:d62e%en0 prefixlen 64 scopeid 0x4
inet 10.19.140.103 netmask 0xffffff00 broadcast 10.19.140.255
media: autoselect (100baseTX )
status: active
en1: flags=8863 mtu 1500
ether 00:1e:c2:a1:91:d1
inet6 fe80::21e:c2ff:fea1:91d1%en1 prefixlen 64 scopeid 0x5
inet 192.168.0.122 netmask 0xffffff00 broadcast 192.168.0.255
media: autoselect
status: active
fw0: flags=8863 mtu 4078
lladdr 00:1e:52:ff:fe:68:49:72
media: autoselect
status: inactive


To add a new IP, run this command: sudo ifconfig en0 alias 10.19.140.222 10.19.140.255 where 10.19.140.222 is the IP that I want to add and 10.19.140.255 is my broadcast address.


sudo ifconfig en0 alias 10.19.140.222 10.19.140.255

After the command I'm getting the following.

yannlaviolette@mac-jeanmat:~> ifconfig
lo0: flags=8049 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010 mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8963 mtu 1500
ether 00:1e:c2:0a:d6:2e
inet6 fe80::21e:c2ff:fe0a:d62e%en0 prefixlen 64 scopeid 0x4
inet 10.19.140.103 netmask 0xffffff00 broadcast 10.19.140.255
inet 10.19.140.222 netmask 0xff000000 broadcast 10.19.140.255
media: autoselect (100baseTX )
status: active
en1: flags=8863 mtu 1500
ether 00:1e:c2:a1:91:d1
inet6 fe80::21e:c2ff:fea1:91d1%en1 prefixlen 64 scopeid 0x5
inet 192.168.0.122 netmask 0xffffff00 broadcast 192.168.0.255
media: autoselect
status: active
fw0: flags=8863 mtu 4078
lladdr 00:1e:52:ff:fe:68:49:72
media: autoselect
status: inactive

To remove an IP, type the following command: sudo ifconfig en0 -alias 10.19.140.222 10.19.140.255

IMPORTANT!

If you need to ping your machine, you need to add a route to told your kernel that the new address is binded to 120.0.0.1. Type the following command

sudo route add -host 10.19.140.222 127.0.0.1



Friday, February 10, 2012

SOAP Web Services - Generating Java artifacts, JAX-WS

If you want to consume web services with Java and JBoss, you can use the JBoss tool "wsconsume" to build all the artifacts used to talk with the SOAP Web Service.

You need JBoss to achieve this.

The tool is in JBoss/bin. It is named wsconsume.sh

Here are the steps to generates the aritfacts
  1. Use the following command to generate the artifacts: wsconsume.sh -k -p com.mypackage http://127.0.0.1:8080/ws/jaxws/test?wsdl
  2. The tool will generate all the Java class required

Have fun!