Tag Archives: programming

Simple Java AD/LDAP Authenticaion Code


There are so much of code and reference available for AD/LDAP integration in Java. I also searched a lot and the below code worked for me.
As a non-java developer I found so interesting while working on some complex java stuff.

 

import java.util.*;
import javax.naming.*;
import javax.naming.directory.*;
public class ADTestNew {
    public static void main(String[] args) {
    try {
        Hashtable env = new Hashtable();

        env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

        env.put(Context.PROVIDER_URL,"ldap://192.168.100.225:389"); //replace with your server URL/IP

        // This line is optional based on environment. You can try with comment or without comment also.
        env.put(Context.SECURITY_AUTHENTICATION,"DIGEST-MD5"); //No other SALS worked with me

        env.put(Context.SECURITY_PRINCIPAL,"login"); // the user name.

        env.put(Context.SECURITY_CREDENTIALS, "Passw0rD"); //the password.

        DirContext ctx = new InitialDirContext(env);

        ctx.close();

    } catch(NamingException ne) {
        System.out.println("Error authenticating user:");
        System.out.println(ne.getMessage());
        return;
    }
    //if no exception, the user is already authenticated.
    System.out.println("OK, successfully authenticating user");
    }
}

Happy Java.

Get time in millisecond in groovy


I found there are 2 ways to get time in millisecond

 def m1 = System.currentTimeMillis()
 println m1

def m2 = new Date()
 println m2.getTime()
 

How to get Google Page-Rank from Perl Script


Today got good package by which directly we can get the google page rank.

This is the easiest way to find the google page rank from Perl Code.

I tried this code in 2 ways
1. By list in the code
2. By putting the site from command prompt.

#!/usr/bin/perl
use warnings;
use strict;

use WWW::Google::PageRank;
my $pr = WWW::Google::PageRank->new;

my $page = $ARGV[0];

my @sites = (
  'http://www.yahoo.com',
  'http://www.wordpress.org',
  'http://www.wordpress.com',
  'http://www.labnol.org'
);
if(!$page) {
  foreach(@sites) {
	  print "$_ : ";
	  print scalar($pr->get($_)), "\n";
  }
} else {
  print "$page : ";
  print scalar($pr->get($page)), "\n";
}

2 Ways to run this code

ankur@ankur:~> perl googlerank.pl
http://www.yahoo.com : 9
http://www.wordpress.org : 9
http://www.wordpress.com : 9
http://www.labnol.org : 6
ankur@ankur:~> perl googlerank.pl http://www.apple.com
http://www.apple.com : 9
ankur@ankur:~>

This is the simplest code, we can change based on requirement.

Happy Perl.

my initial understanding on project management


Some years spent on Web Development, worked for hours n hours, written thousands of lines of code, learnt a lot, enjoyed too much.

I learnt new things always, things what I learnt as –

  • Live your dream, work what you like.
  • Always try to improve. Learning is a lifelong process.
  • Nothing is easy.
  • Project management is not a easy job.
  • Be a team player first.
  • Error is belongs to humans. This is human’s default property.
  • I understood that Research and Development both are different things.
  • Tell truth, be brave. Only technical people understand how tough it is to fullfill the business need.
  • Respect your competitors and peers and colleagues. As you bow as you reap.
  • 3 things Ethics, honest and reliable with your team. Its tough but this is better way to keep yourself safe.
  • Note down every thing, what you did. where you spent your time everything in bad time you will need all these things.
  • Past achievement has no guarantee of future achievement, give your 100% every time.
  • Luck and lady Luck are important not everything done by handwork.
  • Project Plan. Project Plan. Project Plan. NO substitute for Accute Project Plan.
  • Get Help/support from all/team/colleague/peer/manager, no matter how intelligent you are you need help from someone, sometime.
  • Dont trust/belive on star performer. Everyone in team has to perform.
  • Work for root cause of the issue not for effects.
  • Not necessary A fundu technical person is a good manager and visa-versa. Let him think technically and give other option to other person.
  • Estimate with your buffer. No matter how intelligent we are, errors and problems always occur.

3 things Time (Speed), Money (Cost), Quality. Any 2 things can be achievable simultaneously. Have to suffer with one thing.

I just love these 3 links and try to follow these rules. Any way this will be helpfull to you too.

http://docs.yahoo.com/info/values/
http://docs.yahoo.com/info/values/page2.html
http://www.insidecrm.com/features/Manager-Common-Sense-Rules-082207/

Happy Project Management.

MoneyBookers Dummy Credit-Card Numbers for testing


MoneyBookers Dummy Credit-Card Numbers. I used this for testing. I hope this will be helpfull for you also.

VISA: 4000001234567890
AMEX: 371234500012340
MASTERCARD: 5232000000123456
DINERS: 36123456789000
LASER: 5612345678900001
MAESTRO: 51234567912345670
SOLO: 631234567891234560
JCB: 3555123456789120
CARTBLEUE: 5817840047112340

** NOTE – Not sure for current status, I am NOT sure that is this still available as dummy-numbers or NOT. Use this with your concern.

Start working with symfony 1.4


My colleague Subedar has started using Symfony 1.4. Today he shared me this list that how to install symfony 1.4 into your machine.

This is tested in windows, I have not tried in my ubuntu lappy. I will try and setup in my linux lappy and buzz you will more updates. I have some idea with 1.4 let see… Stay tuned…

Step for symfony 1.4 installation

  1. create a folder for your project on your local machine
    Ex project name  “testproject”
  2. Create “lib” folder in  project folder and create “vendor” in lib folder
    now the directory structure become  projectname/lib/vendor
  3. Now put symfony1.4 file in vendor folder and rename it as symfony
  4. Now execute the following command
    if  you want project with propel then execute

    php lib\vendor\symfony\data\bin\symfony generate:project testproject --orm=Propel

    if you want project in doctrine

    php lib\vendor\symfony\data\bin\symfony generate:project testproject --orm=none
  5. Now set database and password
    php symfony configure:database "mysql:host=localhost;dbname=dbname"  root rootPassword
  6. you can directly change in the file database.yml and propel.ini
  7. Now create application by executing
    php symfony generate:app frontend
  8. Create module
    php symfony generate:module frontend default
  9. Check php.ini if extension=php_pdo.dll not open then open it also check extension=php_pdo_mysql.dll

Hope this will be helpfull. Happy Programming.

WWW-Web Site Essentials


I was reading a book couple of months back.

That book contains what are the fields you require for a good website. I noted down the points.

  • Testimonials
  • Promotions/offers
  • Photo Gallery
  • Blog
  • A good domain name
  • A good hosting company
  • CMS
  • Content update facility
  • Social media integration
  • RSS
  • Newsletter
  • Sitemap
  • About Us Page
  • Contact Us Page
  • Location Page
  • Client List / Affiliate List
  • Site Backup Facility
  • Site Analytics
  • Email Processes
  • Press Releases
  • Download
  • Search site
  • Notifications.
  • Security

Huff!! That contain so many things. This is not all.

If a site has all these things then this is complete site for ready for users.
Then it depends that what are the target users and who will use the site.
Based on that dynamic content can be added into the site.

Happy Web.

Symfony Criteria for table alias with join of same table


Symfony Criteria for table alias and join a quick example.

Yesterday got a good situation, A kind of join with same table and with table alias.
I need to use the first query with symfony criteria.

I got this, hope this will be usefull to you too.

SELECT u1.USR_FNAME AS a, u1.USR_LNAME AS b, u2.USR_FNAME AS c, u2.USR_LNAME AS d, u3.USR_FNAME AS e, u3.USR_LNAME AS f
FROM tbl_test
LEFT JOIN tbl_users u1 ON ( tbl_test.TEST_USER1_ID = u1.USR_ID )
LEFT JOIN tbl_users u2 ON ( tbl_test.TEST_USER2_ID = u2.USR_ID )
LEFT JOIN tbl_users u3 ON ( tbl_test.TEST_USER3_ID = u3.USR_ID )
ORDER BY tbl_test.TST_ID ASC
LIMIT 10
$c = new Criteria();
   	$c->clearSelectColumns();
   	$c->addAlias('u1','tbl_users');
   	$c->addAlias('u2','tbl_users');
    $c->addAlias('u3','tbl_users');
   	$c->addSelectColumn(TblProjectPeer::TST_NAME);
   	$c->addAsColumn('a','u1.USR_FNAME');
   	$c->addAsColumn('b','u1.USR_LNAME');
    $c->addAsColumn('c','u2.USR_FNAME');
    $c->addAsColumn('d','u2.USR_LNAME');
  	$c->addAsColumn('e','u3.USR_FNAME');
   	$c->addAsColumn('f','u3.USR_LNAME');
   	$c->addJoin(TblTestPeer::TEST_USER1_ID,'u1.USR_ID',Criteria::LEFT_JOIN);
   	$c->addJoin(TblTestPeer::TEST_USER2_ID,'u2.USR_ID',Criteria::LEFT_JOIN);
  	$c->addJoin(TblTestPeer::TEST_USER3_ID,'u3.USR_ID',Criteria::LEFT_JOIN);

Or take another example

SELECT a.id FROM article a RIGHT JOIN article b ON a.article_id = b.id ORDER BY a.name DESC, b.date DESC
$c=new Criteria();
$c->addAlias('a', 'article');
$c->addAlias('b', 'article');
$c->addSelectColumn('b.id');
$c->addSelectColumn('a.article_id');
$c->addDescendingOrderByColumn('a.name');
$c->addDescendingOrderByColumn('b.date');
$c->addJoin('a.arcticle_id','b.id','RIGHT JOIN');
$rs = ArticlePeer::doSelectRS($c);  

Happy Programming. 😎

prototype and jquery conflict-clash-compatibility issue


Yesterday we got major clash/compatibility issue or conflict 😯 with jQuery and Prototype.
We were using javascript slider and menu with jQuery and some popup window with prototype window.

Searched a lot 👿 , Then finally came up with 2 solution.

  1. Every one says change in jQuery, prototype doesnt have any thing like this.
  2. we got this link solving the conflict/clash/compatibility withing jQuery and Prototype
var $j = jQuery.noConflict();

     // Use jQuery via $j(...)
     $j(document).ready(function(){
       $j("div").hide();
     });

     // Use Prototype with $(...), etc.
     $('someid').hide();

So where ever you are getting “$” change this to “$j” or any variable what ever you like.

Really, jQuery is built is such at superb way, so this proves that this is fully dynamic.

What a solution sir ji, wah!! 3 cheers to jQuery guys.

Lession learnt : first see the requirment, dont just use any js library that suites your requirment. See the dependency then go ahead. 😎

PHP & MySQL quick search bookmarklets


If you want to quick search to MySQL, here is the fast quick bookmarklet

javascript:q=document.getSelection();
if(!q)void(q=prompt('MySQL%20Keyword:',''));
if(q)location.href='http://search.mysql.com/search?q='+escape(q)

And the same goes for PHP too same like above…

javascript:term=document.getSelection();
if(!term)void(term=prompt('PHP%20Keyword:',''));
if(term)location.href='http://in2.php.net/'+escape(term)

Happy Programming. 😀

quick symfony tips.


I am learning symfony. Just got some good tips to share with you.
Symfony rocks. 🙂

I will update this regularly.

1> How to write OR condition query in symfony.
$c = new Criteria();
$c->clearSelectColumns();
$c->addSelectColumn(TablePeer::TBL_ID);
$cton1 = $c->getNewCriterion(TABLEPEER::TBL_ID1, $some_condition , Criteria::EQUAL);
$cton2 = $c->getNewCriterion(TABLEPEER::TBL_ID1, $some_condition , Criteria::EQUAL);
$cton1->addOr($cton2);
$c->add($cton1);

2> How to get query where first date greater then and less then last date.
$date1 = date('Y-m-d 00:00:00');
$date2 = date('Y-m-d 23:59:59');
$cton1 = $gUser->getNewCriterion(TABLEPEER::TBLE_CREATEDAT, $date1, Criteria::GREATER_EQUAL);
$cton1->addAnd($gUser->getNewCriterion(TABLEPEER::TBLE_CREATEDAT, $date2, Criteria::LESS_EQUAL));
$gUser->add($cton1);

3> how to run the update query in symfony.

“update table TableName set TableField1=’1′ where TableField2=$some_value.”

$update = new TableName();
$update->setNew(false);
$update->setTableField1(1);
$update->setTableField2($imageId); // this is primary key of the table. include this line.
$update->save();
?>

technorati tags:
, , , , Continue reading

velue of programming code – hindi version


एक चुटकी कोड की क़ीमत तुम क्या जानो बाबू? 
ईश्वर का आशीर्वाद होता है एक चुटकी कोड.

डेवेलपर के सर का ताज होता है एक चुटकी कोड, 
हर टेसटर का को चाहिए एक चुटकी कोड.

हर पी.एम. का डेड-लाइन होता है एक चुटकी कोड,
हर सी.ई.ओ. का भविष्य होता है एक चुटकी कोड.

हर बेंच रीसोर्स का ख्वाब होता है एक चुटकी कोड,
हर क्लाइंट का एक-एक डॉलेर/पौंड होता है एक चुटकी कोड.

अरे तुम क्या जानो क्या होता है एक चुटकी कोड ??
हर सॉफ्टवेर – इंजिनियर की आन – बान और शान होता है एक चुटकी कोड.

got 4 line poem in english, other 6 lines are mine. :)

Technorati Tags: , , , , , ,, , ,

Find last day of the month in PHP


Yday I was working with dates and got the situation to get the last day of the month so got this piece of code.

date(’Y-m-d’,strtotime(’-1 second’,strtotime(’+1 month’,strtotime(date(’m').’/01/’.date(’Y').’ 00:00:00′))));

And this piece of code will gv you the last day of the your corrent month. 

tags: , , ,