Pages

Tuesday, November 12, 2013

EDI - Copy only specific transaction to a folder

Hi!

Here is a simple tutorial how to copy only a specific functional group type of EDI transaction.

In my example I need to copy all the 997 ( Functional Acknowledgment) to a specific folder.

My folder hierachy is /myhome/source/folder/CLIENT / (job / folder-in / folder-out) / YEAR / MONTH / DAY / myfile

where myfile is a single ISA per file and could be gzipped.


1 - Extract all gzipped EDI files under folder-in and folder-outfind /myhome/source/folder -type f -iwholename *folder* -iwholename *.gz  -exec zgrep -l '^ISA' {} \; -exec gunzip {} \;


2 - Copy all the 997 to /home/MY_FOLDER (Where FA is the GS Transaction code of the 997)find /myhome/source/folder -type f -iwholename *folder* -exec pcregrep -Ml '^ISA.*GS.FA'  {} \; -exec cp -rf {} /home/MY_FOLDER/ \;



Wednesday, October 23, 2013

Split a big text file into many files

Hi!

Suppose that we have a big text file with 2 000 000 lines and you want to split it in 1 000 files containing 20 000 lines each.

You only have one command to type!

split -l 20000 myfile.txt

You will get 1 000 files.

If you are on Windows, you just have to install Cygwin Terminal

Wednesday, October 2, 2013

Batch - Deleting all the files and directories under a root directory

Hi!

With Windows 7, I need to delete all the files and subdirectory under a root directory.

I was able to achieve this task with theses two commands in a batch script

rmdir /S /Q MY_DIRECTORY
md MY_DIRECTORY

The first one deletes all the files and directory under MY_DIRECTORY but it deletes also the root directory. I recreate after the root directory.

It may not be the best way to achieve this but it works.

Sunday, September 29, 2013

java.lang.NoSuchMethodError: antlr.collections.AST.getLine()

After adding Velocity to my Spring Web Application, I'm getting this error:


29.09.2013 22:44:26  WARN (AbstractMessageListenerContainer.java:696) - Execution of JMS message listener failed, and no ErrorHandler has been set.
java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I

...

The error is due by the conflicts between two differents version of "antlr". You need to exclude the version from velocity-tool.

So add the following exclusion to the velocity-tools maven dependency.


  <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-tools</artifactId>
            <version>2.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>antlr</artifactId>
                    <groupId>antlr</groupId>
                </exclusion>
            </exclusions>
   </dependency>

Wednesday, September 25, 2013

Tar following symlinks

Hi!

Suppose that we have to tar gzip a directory that contains two symlinks.

ROOT_DIRECTORY
     SYMLINK_A
     SYMLINK_B



SYMLINK_A
     FILE_A
     FILE_B

SYMLINK_B
     FILE_C
     FILE_D



If you use the usual command tar -zcvf ROOT_DIRECTORY.tgz ROOT_DIRECTORY

You will get an archive that contains two symbolic links.

ROOT_DIRECTORY
     SYMLINK_A
     SYMLINK_B



If you want to include the content of symbolic links, you need to add a "h" just after the "c",

The command is tar -zchvf ROOT_DIRECTORY.tgz ROOT_DIRECTORY

You will get the directory including all the files under the ROOT_DIRECTORY

ROOT_DIRECTORY
     SYMLINK_A
          FILE_A
          FILE_B

     SYMLINK_B
          FILE_C
          FILE_D


Thursday, September 19, 2013

Nice Grep tool for Windows - grepWin

Hi!

I've found a great tool to do greps in Windows.




Please have a look at https://code.google.com/p/grepwin/

Thursday, September 12, 2013

Ruby Application Server - Installation notes for Nginx and Passenger

Hi!

Here's how to install Passenger and Nginx. You will get a very fast Ruby application server.

Compile nginx :
tar -xzvf nginx-1.3.14.tar.gz
cd nginx-1.3.14
./configure --prefix=/etc/nginx --with-http_ssl_module

cd /etc/init.d/
ln -snf /etc/nginx/sbin/nginx

Compile passenger :

cd /usr/local/ruby/bin
./passenger-install-nginx-module

 1. Yes: download, compile and install Nginx for me. (recommended)
    The easiest way to get started. A stock Nginx 1.0.6 with Passenger
    support, but with no other additional third party modules, will be
    installed for you to a directory of your choice.

 2. No: I want to customize my Nginx installation. (for advanced users)
    Choose this if you want to compile Nginx with more third party modules
    besides Passenger, or if you need to pass additional options to Nginx's
    'configure' script. This installer will  1) ask you for the location of
    the Nginx source code,  2) run the 'configure' script according to your
    instructions, and  3) run 'make install'.

Whichever you choose, if you already have an existing Nginx configuration file,
then it will be preserved.

Enter your choice (1 or 2) or press Ctrl-C to abort: 2

The next step is to point passenger to the source directory. Is this example, the source is in my home folder so it’s -> /home/xxx/nginx-1.3.14.

Than point the installation of nginx to /etc/nginx

Passenger is now installed. Here’s what your nginx config should look like this:
____________________________________________
worker_processes  2;

error_log  logs/error.log  debug;

#pid        logs/nginx.pid;

events {
    worker_connections  2000;
}

http {
    passenger_root /usr/local/ruby-1.8.7-p352/lib/ruby/gems/1.8/gems/passenger-3.0.9;
    passenger_ruby /usr/local/ruby-1.8.7-p352/bin/ruby;
    passenger_max_pool_size 3;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

  server {
     listen 8666;
     server_name localhost;
    
     root /data/opt/local/ruby/myapp/public/;   # <--- be sure to point to 'public'!
     passenger_enabled on;
     passenger_use_global_queue on;

     auth_basic "myapp Access"; # <--- For password auth
     auth_basic_user_file /home/myapp/passwd;
    
   }

     #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
}
______________________________________________________
Start:
/etc/init.d/nginx

Stop :
/etc/init.d/nginx -s stop

Tuesday, September 10, 2013

JPA / Hibernate - On Delete Set NULL

It's impossible to configure a ON DELETE SET NULL with JPA / Hibernate.

To achieve this, you could define a @PreRemove method that specify the fields to set NULL.

Here's an example:

...

/**
 * The persistent class for the user database table.
 */
@Entity
@Table(name = "`user`")
public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(unique = true, nullable = false)
    private Long id;

    @Column(length = 255)
    private String address;

    @Column(length = 255)
    private String city;

    @Column(nullable = false, length = 2)
    private String country;

    @Column(nullable = false, length = 255)
    private String email;

    @Column(name = "is_active", nullable = false)
    private Boolean isActive;

    @Column(nullable = false, length = 255)
    private String name;

    @Column(nullable = false, length = 40)
    private String password;

    @Column(length = 15)
    private String phone;

    @Column(name = "postal_code", length = 7)
    private String postalCode;

    @Column(nullable = false, length = 2)
    private String province;

    @Column(length = 1)
    private String role;

    @ManyToMany
    @JoinTable(
            schema = "stratageme_ca",
            name = "favourite_product"
            , joinColumns = {
            @JoinColumn(name = "user_id", nullable = false)
    }
            , inverseJoinColumns = {
            @JoinColumn(name = "product_id", nullable = false)
    }
    )
    private List<Product> products;

    @OneToMany(mappedBy = "user")
    private List<PurchaseOrder> purchaseOrders;

    @OneToOne(mappedBy = "user")
    private SavedCart savedCart;

    @OneToMany(mappedBy = "specialist")
    private List<Store> storesSpecialist;


    @OneToMany(mappedBy = "director")
    private List<Store> storesDirector;

    @OneToMany(mappedBy = "vp")
    private List<Store> storesVp;

    @OneToMany(mappedBy = "conseiller")
    private List<Store> storesConseiller;

    @OneToMany(mappedBy = "user")
    private List<Territory> territories;

    @ManyToOne
    @JoinColumn(name = "all_under_banner_id")
    private Banner banner;

    @ManyToOne
    @JoinColumn(name = "title_id")
    private Title title;

    public User() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAddress() {
        return this.address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return this.city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return this.country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean getIsActive() {
        return this.isActive;
    }

    public void setIsActive(Boolean isActive) {
        this.isActive = isActive;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return this.phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPostalCode() {
        return this.postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public String getProvince() {
        return this.province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getRole() {
        return this.role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public List<Product> getProducts() {
        return this.products;
    }

    public void setProducts(List<Product> products) {
        this.products = products;
    }

    public List<PurchaseOrder> getPurchaseOrders() {
        return this.purchaseOrders;
    }

    public void setPurchaseOrders(List<PurchaseOrder> purchaseOrders) {
        this.purchaseOrders = purchaseOrders;
    }

    public SavedCart getSavedCart() {
        return this.savedCart;
    }

    public void setSavedCart(SavedCart savedCart) {
        this.savedCart = savedCart;
    }


    public List<Store> getStoresSpecialist() {
        return storesSpecialist;
    }

    public void setStoresSpecialist(List<Store> storesSpecialist) {
        this.storesSpecialist = storesSpecialist;
    }

    public List<Store> getStoresDirector() {
        return storesDirector;
    }

    public void setStoresDirector(List<Store> storesDirector) {
        this.storesDirector = storesDirector;
    }

    public List<Store> getStoresVp() {
        return storesVp;
    }

    public void setStoresVp(List<Store> storesVp) {
        this.storesVp = storesVp;
    }

    public List<Store> getStoresConseiller() {
        return storesConseiller;
    }

    public void setStoresConseiller(List<Store> storesConseiller) {
        this.storesConseiller = storesConseiller;
    }

    public List<Territory> getTerritories() {
        return this.territories;
    }

    public void setTerritories(List<Territory> territories) {
        this.territories = territories;
    }

    public Banner getBanner() {
        return this.banner;
    }

    public void setBanner(Banner banner) {
        this.banner = banner;
    }

    public Title getTitle() {
        return this.title;
    }

    public void setTitle(Title title) {
        this.title = title;
    }


    /**
     * Pre Remove to set ON DELETE SET NULL
     */
    @PreRemove
    public void preRemove(){
        for(Store s : storesConseiller){
            s.setConseiller(null);
        }

        for(Store s : storesSpecialist){
            s.setSpecialist(null);
        }

        for(Store s : storesDirector){
            s.setDirector(null);
        }

        for(Store s : storesVp){
            s.setVp(null);
        }

    }


}

Monday, September 9, 2013

Linux - find file in specific directory

If you want to search for all files under a specific directory and remove them, you could use the following command:

find . -type f -wholename '*/DIRECTORY/*' -exec rm -rf {} \;

Where DIRECTORY is the name of your directory.

For example, you will be able to find all theses files


/home/toto/test/DIRECTORY/toto.txt
/home/toto/test1/DIRECTORY/tata.txt
/home/toto/test2/DIRECTORY/titi.txt

You must execute the command from /home/toto

Friday, September 6, 2013

Eclipse / SVN - Attempted to lock an already-locked dir

After an Eclipse crash, impossible to commit / update files. I'm getting this error

org.apache.subversion.javahl.ClientException: Attempted to lock an already-locked dir
svn: Working copy 'D:\XXX' locked.
svn: 'D:\XXX' is already locked.



In Eclipse- Right Click- Team / Refresh Cleanup

Thursday, August 15, 2013

DBVisualizer - Content not allowed in prolog

Hi!

After a Windows crash while DBVisualizer was opened. I lost everything under by DBViz.

When I start the app, I'm getting this error message:


>>>>

Could not read XML file C:\ ..... \dbvis.xml

Error is : Content not allowed in prolog.

<<<<

When I look at the file dbvis.xml, I saw the file was corrupted.


To correct the situation, there are backup files in the directory.

My directory is  C:\Users\ylaviole\.dbvis\config70

Simply delete all the files and remplace .bak files by there original file name.

dbvis.xml.bak => dbvis.xml
editorstyles.xml.bak => editorstyles.xml
favorites.xml.bak => favorites.xml
tablefilters.xml.bak => tablefilters.xml

Restart DBVisualizer and you should have restored all you settings.

Generate many files of a particular size in Windows



I was recently performing some performance testing that required me to copy many files of a particular size from one Windows XP workstation to a Windows 2003 server. I had a heck of a time figuring out how to batch generate the test files.


Finally I cam across the fsutil tool, which is included on both Windows XP and Windows Server 2003.


The syntax for using fsutil is:


fsutil file createnew filename filesize


I used a simple loop to create files of a particular size using fsutil. Running from a command prompt:


For /L %i in (1,1,25000) do fsutil file createnew A%i.tmp 12288


will create 25,000 files of 12288 bytes (12KB) named A1.tmp, A2.tmp, A3,tmp…


to run this loop in a .cmd file instead of from the command line replace single % with double percent signs


For /L %i in (1,1,10000) do fsutil file createnew B%i.tmp 65536


will create 10,000 files of 65536 bytes (64KB) named B1.tmp, B2.tmp, B3,tmp…


For /L %i in (1,1,2500) do fsutil file createnew C%i.tmp 131072


will create 2,500 files of 131072 bytes (128KB) named C1.tmp, C2.tmp, C3,tmp…


For /L %i in (1,1,1000) do fsutil file createnew D%i.tmp 1048576


will create 1,000 files of 1048576 bytes (1024KB or 1MB) named D1.tmp, D2.tmp, D3,tmp…


I was able to create hundreds of thousands of files of a very specific size in a short amount of time using this procedure.


















For /L %i in (1,1,10000000) do fsutil file createnew %i.copy 15

Apache Virtual Host with certificate

Here is a simple example for Virtual Host with Apache & certificates


<VirtualHost 111.222.333.444:443>
        DocumentRoot /var/www/html/xyz.ca
        ServerName xyz.ca
        ServerAlias www.xyz.ca

        SSLEngine on
        SSLProtocol all
        ServerAdmin admin@xyz.ca
        SSLCertificateFile /usr/local/ssl/crt/xyz_certificate.crt
        SSLCertificateKeyFile /usr/local/ssl/private/star_xyz_ca.key
        SSLCertificateChainFile /usr/local/ssl/crt/intermediate.crt
        SSLCACertificateFile /usr/local/ssl/crt/intermediate.crt
</VirtualHost>