Skip to main content

Posts

Showing posts from 2012

Different ways to use enum's in java

Technique:  Simple enum and retrieve/reverse lookup using valueOf() public class OrderService {     // Note : enums can be defined in its own file or inside a class if they are only relevant with it.     public enum Status { PROCESSING, SHIPPED, COMPLETED; }     public void update(long orderId, Status status) {          // something     } } // import static OrderService.Status; // import static OrderService.Status.* ; // OrderService service = new OrderService(); // service.update(100L, SHIPPED); // use enum // Status status = Status.valueOf("SHIPPED"); // reverse lookup by constant, throws IllegalArgumentException if no match. // System.out.println ( status.toString() ); // prints value - SHIPPED Technique:  Stores enum constant and value in a map, retrieve/reverse lookup using fromValue() public enum Status {         PROCESSING("processing"), SHIPPED("shippin...

guzra huwa jamana ata nahi dubara

guzra huwa jamana ata nahi dubara hafez khuda tumhara khushiya thi chaar din ki aason hai umr bhar ke  tanhahiyon me aksar royenge yaad karke wo waqt ke jo hum ne ek saath hai guzaara meri khasam hai mujko tum bewafa na kehna majboor thi mahabot sabh kuch pada hai sehna tuta hai zindegi ka ab aakhri sahara mere liye sahr bhi aayi hai raath bankar nikla mera janaza meri barath ban kar accha huwa jo tumne dekha na ye nazara guzra huwa jamana ata nahi dubara hafez khuda tumhara

ArrayList vs LinkedList vs HashSet Performance Comparision

Conclusions Inserting & Reading sequentially from Collection prefer LinkedList/ArrayList Inserting & Reading/Deleting by Search/equals from Collection prefer HashSet Inserting, ArrayList & LinkedList performs best while HashSet takes double the time Reading, HashSet performs best while ArrayList & LinkedList are marginally less Deleting, HashSet performs 10 times better than ArrayList & ArrayList performs 4 times better than LinkedList. LinkedList is slow because of sequencial search Bottom line : unless you are not going to iterate using for(Integer i : list ) then prefer HashSet Inserting/Reading/Deleting integer's from zero till count JDK7 Collection action count time ms ArrayList Insert 100 0/1 LinkedList Insert 100 0/1 HashSet Insert 100 0/1 ArrayList Insert 10000 5 LinkedList Insert 10000 4 HashSet Insert 10000 7 ArrayList Insert 100000 11 LinkedList Insert 100000 11 HashSet Insert 100000 21 ArrayList Get/Read 100 0 LinkedLis...

Password Security Recommendations

User credential / Password Security. Recent security related embarrassment at Yahoo, LinkedIn and Sony has only proved that securing user information needs more considerations. Security is not a product rather a process. First identifying how username/password can be leaked and its price. Basically there are four ways an adversary can find out username/password for one or more accounts stored on the server.  1. Password guessing - Assuming adversary knows username for one or more accounts and they can       deploy dictionary attack to find correct password.  2. Adversary eavesdropping on user network ( Man in Middle Attack)  3. Adversary getting access to user computer through some virus/worm  4. Adversary getting access to username/password table or system on the server. Password Guessing : Fix :   Max invalid attempts strategy should be deployed, i.e. temporary lock the account after 4 or 5 invalid...

Use project specific license in Netbeans + Maven

Use this in pom.xml and Netbeans is intelligent enough to inject appropriate license in all newly created files. <licenses>         <license>             <name>The Apache Software License, Version 2.0</name>             <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>             <distribution>repo</distribution>             <comments>A business-friendly OSS license</comments>         </license>     </licenses> And this is what it produces /*  * Copyright 2012 intesar.  *  * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *      http://w...

Forum/Questions feature request to Github & Google

Hey Github/Google why don't you add a forum/questions feature just like other "wiki" and "issues" features. Today there is no way project adopters can ask direct questions to the project community without creating an issue and this will not scale, simply because many non-contributors do not read issues and answer's them. So eventually we are keeping big knowledge base out of helping others adopt or solve problems. Lack of this feature simply discourages people asking questions fearing they are spamming the project with issues, and eventually they will end-up not using the product. And on the other hand if you add this feature it will simply create more value, increase user engagement, and addition of new knowledge base to your system. You might also argue that why we need to duplicate this feature when there are other good sites like StackOverFlow for doing this, but adding or integrating this feature to your products is more natural as users will find...

Riak vs MongoDB vs MySQL Performance tests 1

Environment 1  Intel(R) Xeon(R) CPU           X3430  @ 2.40GHz Cores: 4 8 MB Cache Memory : 6GB ulimit : 1024 OS : CentOS 5.4 Riak : 1.1 MySQL 5.1 (Highly tuned system) Test data : Object : username, email, id Both test's were run from Java clients To make this test little meaningful I've send each read/write command to mysql in its own request. MySQL Single Node (time in ms)   inserts : 50, time : 871  inserts : 100, time : 324  inserts : 200, time : 835  inserts : 500, time : 1936  inserts : 1000, time : 3275  gets : 50, time : 55  gets : 100, time : 60  gets : 200, time : 119  gets : 500, time : 304  gets : 1000, time : 582 Riak Single Node (Recommended is 3 Nodes)   inserts : 50, time : 461  inserts : 100, time : 486  inserts : 200, time : 1473  inserts : 500, time : 3609  inserts : 1000, time : 6442  gets : 50, ti...

Simple Log4J Yahoo mail setup to recieve production errors as emails

Receive all server exceptions as email, never miss one, easy to share and discuss with the others Follow these simple steps to configure Log4j to use Yahoo mail. Step 1: Add dependencies         <dependency>             <groupId>javax.mail</groupId>             <artifactId>mail</artifactId>             <version>1.4</version>         </dependency>                <!-- Log4j -->         <dependency>             <groupId>log4j</groupId>             <artifactId>log4j</artifa...

Simple setup Log4j with GMail and recieve all errors as email

Receive all server exceptions as email, never miss one, easy to share and discuss with the others Follow these simple steps to configure Log4j to use GMail. Step 1: Add dependencies         <dependency>             <groupId>javax.mail</groupId>             <artifactId>mail</artifactId>             <version>1.4</version>         </dependency>                <!-- Log4j -->         <dependency>             <groupId>log4j</groupId>             <artifactId>log4j</artifactId...

Simple reusable GMailJava class for sending Aysnc emails via Gmail

Simple reusable GMailJava class for sending Aysnc emails. Copy the class, change the username/password and use it in your next project.  Step 1: Add dependencies to your maven project <!-- mail --> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4</version> </dependency> <!-- Apache Commons Validator --> <dependency> <groupId>commons-validator</groupId> <artifactId>commons-validator</artifactId> <version>1.4.0</version> </dependency> Step 2: Copy EmailService.java to your project & set username/password code: https://github.com/intesar/GMailJava/blob/master/src/main/java/com/bia/gmailjava/EmailService.java Note: Enable pop, IMAP inside GMail --> Settings --> Forwarding and POP / IMAP Sample code EmailService ema...

Send emails using Yahoo

Simple reusable YahooMailJava class for sending Aysnc emails via Yahoo. Copy the class, change the username/password and use it in your next project.  Step 1: Add dependencies to your maven project <!-- mail --> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4</version> </dependency> <!-- Apache Commons Validator --> <dependency> <groupId>commons-validator</groupId> <artifactId>commons-validator</artifactId> <version>1.4.0</version> </dependency> Step 2: Copy YahooMailService.java to your project and set username/password code: https://github.com/intesar/YahooMailJava/blob/master/src/main/java/com/bia/yahoomailjava/YahooMailService.java Sample code YahooMailService emailService = YahooMailService.getInstance(); emailService...

GMailJava class for sending Async emails

Simple reusable GMailJava class for sending Aysnc emails. Copy the class, change the username/password and use it in your next project.  Step 1: Add dependencies to your maven project <!-- mail --> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4</version> </dependency> <!-- Apache Commons Validator --> <dependency> <groupId>commons-validator</groupId> <artifactId>commons-validator</artifactId> <version>1.4.0</version> </dependency> Step 2: Copy EmailService.java to your project & set username/password code: https://github.com/intesar/GMailJava/blob/master/src/main/java/com/bia/gmailjava/EmailService.java Sample code EmailService emailService = EmailService.getInstance(); emailService.sendEmail("<toemail>...

Free website monitor service and seo

  Website Uptime Monitor Service  is a really nice simple service to monitor websites for free, No registration or signup is required, just put the site url, email and start monitoring. Few other features they plan to offer. Free  Features! 1. Site/Web Service Monitor  2. Email Alerts  3. Weekly reports  4. Checkout site uptime status anytime 5. SEO & Social Media coverage on Twitter, G+, FB, Pinterest, Blogger, Reddit for 95+ percent uptime! They also have Android, iOS, Window's Mobile Apps also their site is compatible with all major smart phones. Here is their website...   http://www.zytoon.me/monitor

HP Cloud Services Pricing

Please refer to Official HPCloud Site for updates HP Cloud Services Pricing HP Cloud Compute Pricing Instance Type RAM (GB) Virtual Cores Disk (GB) ($/hr) ($ Monthly aprx) Standard Extra Small 1 1 30 $0.04 $30.00 Standard Small 2 2 60 $0.08 $60.00 Standard Medium 4 2 120 $0.16 $120.00 Standard Large 8 4 240 $0.32 $240.00 Standard Extra Large 16 4 480 $0.64 $480.00 Standard Double Extra Large 32 8 960 $1.28 $960.00 HP Cloud Services Non-CDN Bandwidth Pricing Bandwidth Price                  ($/GB/mo.) IN                  All Data Transfers In FREE     OUT   First 1 GB FREE Up to 10 TB $0.12 Next 40  TB $0.09 Next 100  TB $0.07 Next 350 TB $0.05 More than 500 TB Contact HP HPCloud Pricing
Twitter - Twitter, Inc. Launch Twitter FB Share with friend -- mailTo is empty so user can fill it himself Share with friend -- basic subject & body Share with friend -- with only subject Share with friend -- with only body Share with friend iMessage Me