Tuesday, November 19, 2013

Java - String Rotate

import java.io.*;


class StringRotate {   

    public static void main(String[] args) {

            String inpstring = "";
            InputStreamReader input = new InputStreamReader(System.in);
            BufferedReader reader = new BufferedReader(input);

            try
            {
                  System.out.println("Enter a string to rotate:");
                  inpstring = reader.readLine();

                  int len = inpstring.length();
                  int lastindex = len - 1;

                  char[] outstring = inpstring.toCharArray();


                  for (int i = 0; i < len; i++)
                  {
                        char ch = outstring[0];
                        for (int j = 0; j < len - 1; j++)
                        {
                              outstring[j] = outstring[j + 1];
                        }
                        outstring[len - 1] = ch;
                        {
                              for (int k = 0; k < outstring.length; k++)
                                    System.out.print(outstring[k]);
                              System.out.println();
                        }
                  }

                  System.out.println();
                  System.out.println();

                  for (int i = 0; i < len; i++)
                  {
                        char ch = outstring[len - 1];
                        for (int j = len - 1; j > 0; j--)
                        {
                              outstring[j] = outstring[j - 1];
                        }
                        outstring[0] = ch;
                        {
                              for (int k = 0; k < outstring.length; k++)
                                    System.out.print(outstring[k]);
                              System.out.println();
                        }
                  }
                 
            }
            catch (Exception e)
            {
                  e.printStackTrace();
            }
    }
}



Pascal Triangle

import java.io.*;
import java.lang.*;


class PascalTriangle { 

    public static void main(String[] args) {

            String inpstring = "";
            InputStreamReader input = new InputStreamReader(System.in);
            BufferedReader reader = new BufferedReader(input);

            try
            {
                  System.out.print("Enter number of rows for pascal triangle:");
                  inpstring = reader.readLine();
                  int n = Integer.parseInt(inpstring, 10);

                  for (int y = 0; y < n; y++)
                  {
                        int c = 1;

                        for(int q = 0; q < n - y; q++)
                        {
                              System.out.print("   ");
                        }

                        for(int x = 0; x <= y; x++)
                        {
                              System.out.print("   ");
                              System.out.print(c); // 3 digits
                              System.out.print(" ");
                              c = c * (y - x) / (x + 1);
                        }

                        System.out.println();
                        System.out.println();
                  }
                 
                  System.out.println();
            }
            catch (Exception e)
            {
                  e.printStackTrace();
            }
    }
}

OutPut:

Enter number of rows for pascal triangle:6
                     1

                  1    1

               1    2    1

            1    3    3    1

         1    4    6    4    1

      1    5    10    10    5    1

Friday, October 18, 2013

How sort list of object with multiple data sort in java



package example;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Demo {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Demo demo = new Demo();
        List<Student> list = new ArrayList<Student>(); // your Car list
        Student st = demo.new Student();
        st.setName("sekhar");
        st.setCity("bbsr");
        st.setRoll(23);
        list.add(st);
        st = demo.new Student();
        st.setName("himanshu");
        st.setCity("agra");
        st.setRoll(23);
        list.add(st);
        st = demo.new Student();
        st.setName("nitin");
        st.setCity("delhi");
        st.setRoll(23);
        list.add(st);
        st = demo.new Student();
        st.setName("nitin");
        st.setCity("delhi");
        st.setRoll(22);
        list.add(st);
        st = demo.new Student();
        st.setName("nitin");
        st.setCity("bbsr");
        st.setRoll(23);
        list.add(st);
        st = demo.new Student();
        st.setName("arun");
        st.setCity("patna");
        st.setRoll(23);
        list.add(st);
        st = demo.new Student();
        st.setName("arun");
        st.setCity("kendrapara");
        st.setRoll(23);
        list.add(st);
        System.out.println("before sort");
        System.out.println("Name:" + "-------------------" + "City...........roll");
        for (Student st1 : list) {
            System.out.println(st1.getName() + " --------------" + st1.getCity() + "------------" + st1.getRoll());
        }

        Collections.sort(list, demo.new CarHorsePowerComparator());
        System.out.println("after sort");
        System.out.println("Name:" + "-------------------" + "City...............roll");
        for (Student st1 : list) {
            System.out.println(st1.getName() + " --------------" + st1.getCity() + "------------" + st1.getRoll());
        }
    }

    public class Student {

        String name;
        String city;
        int roll;

        public int getRoll() {
            return roll;
        }

        public void setRoll(int roll) {
            this.roll = roll;
        }

        public String getCity() {
            return city;
        }

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

        public String getName() {
            return name;
        }

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

    class CarHorsePowerComparator implements Comparator<Student> {
        private final Collator collator = Collator.getInstance(); //Default local is taken.

          public int compare(Student left, Student right) {

            int result = collator.compare(left.getName(),right.getName());

            if(result == 0) {
                result = collator.compare(right.getCity(),left.getCity());
            }

            if(result == 0) {
                result = Integer.compare(left.getRoll(), right.getRoll()); //JDK 7
               //result = Double.compare(left.getRoll(), right.getRoll());
            }

            return result;
        }
    }
}


OutPut:

before sort
Name:-------------------City...........roll
sekhar --------------bbsr------------23
himanshu --------------agra------------23
nitin --------------delhi------------23
nitin --------------delhi------------22
nitin --------------bbsr------------23
arun --------------patna------------23
arun --------------kendrapara------------23
after sort
Name:-------------------City...............roll
arun --------------patna------------23
arun --------------kendrapara------------23
himanshu --------------agra------------23
nitin --------------delhi------------22
nitin --------------delhi------------23
nitin --------------bbsr------------23
sekhar --------------bbsr------------23

Tuesday, October 8, 2013

Javascript StartsWith And How to Check Plugin in Firfox and Crome

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script>
function demo(){
    var L = navigator.plugins.length;
    if (typeof String.prototype.startsWith != 'function') {
  // see below for better implementation!
  String.prototype.startsWith = function (str){
    return this.indexOf(str) == 0;
  };
}

document.write(
  L.toString() + " Plugin(s)<br>" +
  "Name | Filename | description<br>"
);

for(var i = 0; i < L; i++) {
  document.write(
    navigator.plugins[i].name +
    " | " +
    navigator.plugins[i].filename +
    " | " +
    navigator.plugins[i].description +
    " | " +
    navigator.plugins[i].version +
    "<br>"
  );
  var data = navigator.plugins[i].name;
var input = 'Dynamic Web TWAIN';
alert(data.startsWith(input));
}

}
  </script>
 </head>

 <body onLoad="demo();">
 
 </body>
</html>

Tuesday, October 1, 2013

Remove Delta Search features from Internet Explorer

Remove Delta Toolbar from Add-ons manager

  1. Open Internet Explorer.
  2. Click the Tools icon (Cogwheel) and select Manage add-ons.
  3. Under Add-on Types, select Toolbars and Extensions.
  4. In the right pane, select Delta Toolbar & Delta helper Object and click the Disable button.

Remove Delta Toolbar from Windows programs

  1. Click the Start button and select Control Panel.
  2. Select Programs and Features.
  3. Select the Delta Toolbar from the Programs list and right click to uninstall.

Remove Delta Search from default search engines

  1. Open Internet Explorer.
  2. Click the Tools icon (Cogwheel) and select Manage add-ons.
  3. Under Add-on Types, select Search Providers.
  4. Set your preferred default search engine.
  5. Select Delta Search and click the Remove button.

Remove Delta Search home page

  1. Open Internet Explorer.
  2. Click the Tools icon (Cogwheel) and select Internet Options.
  3. In the General tab, delete the Delta URL from the Home page text box.
  4. Click OK to save the changes

Remove Delta Search home page

If you open a new tab in Internet Explorer, and Delta Search home page is still there, please do the following:
  1. Open Internet Explorer, click the Tools icon (Cogwheel) and select Internet Options.
  2. In General tab, click the Tabs button (in the Tabs section).
  3. In the new window, click the drop down menu (When a new tab is opened, open: ), and select the option: Your first home page.
  4. Click OK, Apply and OK in the next window as well.
  5. Restart Internet Explorer.


* Restart your computer after completing all the above steps.

Remove Delta Search features from Google Chrome

Remove Delta Toolbar Extension

  1. Open Chrome.
  2. Click the Customize and control button ("3 streaks” icon or wrench icon in older versions) and select Settings.
  3. Click Extensions in the left menu.
  4. Remove/Disable the Delta Toolbar.

Remove Delta Toolbar from Windows programs

  1. Click on the Start button and select Control Panel.
  2. Select Programs and Features.
  3. Select the Delta Toolbar from the Programs list and right click to uninstall
  4. Click YES on the popup message.

Remove Delta Search from default Search engines

  1. From the Customize and control button ("3 streaks” icon or wrench icon in older versions), select Settings.
  2. In the Search section, click Manage search engines and remove Delta Search from the default search engines list.
  3. Click OK to save the changes.

Remove Delta Search home page

  1. Open Chrome.
  2. Click the Customize and control button ("3 streaks” icon or wrench icon in older versions), select Settings.
  3. In the On Startup section, Click on Set Pages and delete the Delta URL (you can set a different home page by entering a URL of your choice).
  4. Click Ok to save the changes.
  5. In the Appearance section, click on Change and delete the Delta URL (you can set a different home page).
  6. Click Ok to save the changes.


* Restart your computer after completing all the above steps.

Remove Delta Search features from Mozilla Firefox

Remove Delta Toolbar from Add-ons manager

  1. Open Mozilla Firefox.
  2. From the Firefox orange button (Or from the standard Tools menu), click Add-ons.
  3. In Add-ons manager left side menu bar, make sure Extensions is selected
  4. Disable or remove the Delta Toolbar add-on
  5. Restart the browser.

Remove Delta Toolbar from Windows programs

  1. Click the Start button and select Control Panel.
  2. Select Programs and Features.
  3. Select Delta Toolbar from the Programs list and right click to uninstall.
  4. Click YES on the popup message.

Remove Delta Search from default search engines

  1. Open Mozilla Firefox.
  2. Click inside the Search text field and press the F4 key
  3. Select Manage Search Engines from the drop down list
  4. Select Delta Search and click the Remove button.

Remove Delta Search home page

  1. Open Mozilla Firefox.
  2. From the Firefox orange button (or from the standard Tools menu), select Options.
  3. In the General tab, delete the Delta URL from the Home page text box.
  4. Click OK to save the changes.

Remove Delta Search home page from New Tab

If you open a new tab in Firefox, and delta Search home page is still there, please do the following:
  1. Type: about:config in the address bar and press enter
  2. Confirm the message.
  3. Type: browser.newtab.url in the Search text field
  4. Right click on the result and select Toggle (or Reset in older versions)


* Restart your computer after completing all the above steps.

Thursday, September 26, 2013

How to scan document in zul using TWAIN

 Download sample provided by Dyansoft here


<zk xmlns:x="xhtml" xmlns:zk="zk" >

<window   title="scan" closable="true" width="600px" height="400px" mode="modal" popup="true" border="normal" apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('com.csdcsystems.amanda.jems.web.viewmodel.ScanToInsertAttachmentViewModel')" >

 <script type="text/javascript">

            <![CDATA[

            var DWObject;
            var seed;
            function pageonload() {
                     seed = setInterval(initControl, 500);//Wait 500ms after opening the webpage, call “ControlDetect” function
            }
           
            function initControl() {
                if (DWObject) {
                    //alert("init");
                    if (DWObject.ErrorCode == 0) {
                        clearInterval(seed);
                        DWObject.BrokerProcessType = 1;
                    }
                    //alert("init"+DWObject.SourceCount);
                    for (var i = 0; i < DWObject.SourceCount; i++) {
                       
                        document.getElementById("deviceSetup").options.add(new
                        Option(DWObject.SourceNameItems(i),
                                DWObject.SourceNameItems(i)));
                       
                    }
                    DWObject.attachEvent('onTopImageInTheViewChanged', Dynamsoft_OnTopImageInTheViewChanged);
                    DWObject.attachEvent('onPostAllTransfers', Dynamsoft_OnPostAllTransfers);
                   
                }
            }

            function acquireImage() {
                if (DWObject) {
                    if (DWObject.SourceCount > 0) {
                        DWObject.SelectSourceByIndex(document.getElementById("deviceSetup").selectedIndex);
                        DWObject.CloseSource();
                        DWObject.OpenSource();
                        DWObject.IfShowUI = document.getElementById("ShowUI").checked;
                        DWObject.Resolution = document.getElementById("resolution").value;
                        DWObject.IfFeederEnabled = document.getElementById("ADF").checked;
                        DWObject.IfDuplexEnabled = document.getElementById("Duplex").checked;
                        DWObject.IfDisableSourceAfterAcquire = true;
                        DWObject.AcquireImage();
                      
                   
                    }
                    else
                        alert("No TWAIN compatible drivers detected.");
                }
            }

            function Dynamsoft_OnTopImageInTheViewChanged(index) {
                if (DWObject) {
                    DWObject.CurrentImageIndexInBuffer = index;
                }
            }
            function Dynamsoft_OnPostAllTransfers() {
                btnUpload();
            }

            function btnUpload() {
                    var pageUrl=document.getElementById("hdnActionPageUrl").value;
                      var strActionPage;
                    var CurrentPathName = unescape(location.pathname); // get current PathName in plain ASCII
                    var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
                    strActionPage = CurrentPath + pageUrl; //the ActionPage's file path
                    strHTTPServer = location.hostname;
                    DWObject.HTTPPort = location.port==""?80:location.port;
                    DWObject.HTTPUploadThroughPost(strHTTPServer,0,strActionPage,"imageData.jpg");

                    if (DWObject.ErrorCode != 0)
                        alert(DWObject.ErrorString);
                    else //succeded
                        alert("Image Uploaded successfully");
               
            }   

            zk.afterMount(function() {
                var    ua=navigator.userAgent;
                var IE=false;
                var IE64=false;
                if(ua.indexOf('msie') != -1 || ua.indexOf('trident') != -1 ||ua.indexOf('MSIE') != -1 ){
                    IE=true;
                }
                if(ua.indexOf('win64') != -1 || ua.indexOf('x64') != -1){
                    IE64=true;
                }
                if(IE){
                    if(IE64){
                        //alert("IE64");
                        DWObject = document.getElementById("dwtcontrolContainer_ObjIE");
                    }else{
                        //alert("IE32");
                        DWObject=document.getElementById("dwtcontrolContainer_ObjIE32");
                    }
                }else{
                    //alert("None IE");
                    DWObject = document.getElementById("dwtcontrolContainer_Obj");
                }
                //DWObject = document.getElementById("dwtcontrolContainer_Obj");
                DWObject.ProductKey = "";
                DWObject.isTrial = false;
                var attLabel = $("#attachmentLabel").val();
                var attValue = $("#attachmentValue").val();
                var labelArray = attLabel.split('-');
                var valueArray = attValue.split('-');
           
                for (var i = 0; i < labelArray.length; i++) {
                    document.getElementById("attachmentType").options.add(new
                    Option(labelArray[i],
                            valueArray[i]));
                }
                pageonload();
            } );
           
            ]]>
</script>


 <hlayout>
     <separator width="10px"></separator>
     <x:table border="0" width="520px">
         <x:tr>
             <x:td colspan="2">
                 <space></space>
             </x:td>
         </x:tr>

         <x:tr>
             <x:td align="right">
                 <label value="Attachment Description"></label>
             </x:td>
             <x:td>
                 <x:select id="attachmentType" style="WIDTH: 408px" onChange="demo();">
                        </x:select>
             </x:td>
         </x:tr>
         <x:tr>
             <x:td align="right">
                 <label value="Attachment Detail"></label>
             </x:td>
             <x:td>
                 <x:input type="textbox" id="attachmentDetail"
                     style="WIDTH: 400px; HEIGHT: 42px;" value="" maxlength="4000" />
             </x:td>
         </x:tr>
     </x:table>
 </hlayout>
 <hlayout>
     <separator width="15px"></separator>
     <x:table border="0" width="520px">
         <x:tr>
             <x:td colspan="3">
                 <x:img id="idDetailTableLoadingBar"
                     src="/resource/image/loading-bar.gif" />
             </x:td>
         </x:tr>
         <x:tr>
             <x:td style="WIDTH: 130px" colspan="2">
                 <label value="Scan Mode"></label>
             </x:td>

             <x:td style="WIDTH: 180px">
                 <label value="Scan File Name"></label>
             </x:td>
         </x:tr>
         <x:tr>
             <x:td colspan="2" width="300px">

                 <x:table width="100%">
                     <x:tr>
                         <x:td width="100px">
                             <x:input type="radio" name="bwOrColour"
                                 value="B" checked="true" />
                             <label value="BW" />
                         </x:td>
                         <x:td width="100px">
                             <x:input type="radio" name="bwOrColour"
                                 value="G" />
                             <label value="Gray" />
                         </x:td>
                         <x:td width="100px">
                             <x:input type="radio" name="bwOrColour"
                                 value="C" />
                             <label value="Color" />
                         </x:td>
                     </x:tr>
                 </x:table>
             </x:td>
             <x:td width="173px">
                 <x:input type="textbox" id="FileName"
                     style="WIDTH: 190px" value="@load(vm.fileName)" />
             </x:td>
         </x:tr>
         <x:tr>
             <x:td width="85px">
                 <label value="Resolution"></label>
             </x:td>
             <x:td width="173px">
                 <x:select id="resolution" style="WIDTH: 150px">
                     <x:option value=""></x:option>
                     <x:option value="75">75</x:option>
                     <x:option value="100">100</x:option>
                     <x:option value="150">150</x:option>
                     <x:option value="200">200</x:option>
                     <x:option value="250">250</x:option>
                 </x:select>
             </x:td>
             <x:td width="173px">
                 <label value="File type"></label>
             </x:td>
         </x:tr>
         <x:tr>
             <x:td width="300px" colspan="2">
                 <x:table border="0" width="100%">
                     <x:td width="100px">
                         <x:input type="checkbox" id="ShowUI" />
                         <label value="ShowUI" />
                     </x:td>
                     <x:td width="100px">
                         <x:input type="checkbox" id="ADF" />
                         <label value="ADF" />
                     </x:td>
                     <x:td width="100px">
                         <x:input type="checkbox" id="Duplex" />
                         <label value="Duplex" />
                     </x:td>
                 </x:table>
             </x:td>
             <x:td width="173px">
                 <x:select id="FileType" style="WIDTH: 195px">
                     <x:option value="JPG">JPG</x:option>
                     <x:option value="PNG">PNG</x:option>
                     <x:option value="PDF">PDF</x:option>
                     <x:option value="TIF">TIF</x:option>
                     <x:option value="BMP">BMP</x:option>
                 </x:select>
             </x:td>
         </x:tr>
         <x:tr>
             <x:td style="WIDTH: 300px" colspan="2"></x:td>
             <x:td width="173px">
                 <label value="Device Setup"></label>
             </x:td>
         </x:tr>
         <x:tr>
             <x:td style="WIDTH: 300px" colspan="2"></x:td>
             <x:td width="173px">
                 <x:select id="deviceSetup" style="WIDTH: 195px">
                     <x:option value=""></x:option>
                 </x:select>
             </x:td>
         </x:tr>
     </x:table>
 </hlayout>

 <hlayout>
     <separator width="15px"></separator>
     <x:table border="0" width="520px">

         <space width="30px"></space>
         <x:tr>
             <x:td align="right">
                 <x:input type="textbox" id="attachmentLabel"
                     value="@load(vm.attachmentLabel)" visible="false" />

                 <x:input type="textbox" id="attachmentValue"
                     value="@load(vm.attachmentValue)" visible="false" />
                 <x:input type="textbox" id="lid" width="210px"
                     value="@bind(vm.sessionId)" visible="false" />
                 <x:input type="textbox" id="agencyType" width="210px"
                     value="@bind(vm.agencyType)" visible="false" />
                 <x:input type="textbox" id="folderRSN" width="210px"
                     value="@bind(vm.folderRSN)" visible="false" />
                 <x:input type="textbox" id="folderType" width="210px"
                     value="@bind(vm.folderType)" visible="false" />

                 <x:input type="hidden" id="hdnActionPageUrl"
                     value="@bind(vm.actionPageURL)" />

                 <x:input type="hidden" id="scanProductKey"
                     value="@bind(vm.scanProductKey)" />

                 <x:input type="button" value="Scan"
                     onClick="acquireImage();" id="btnScan" style="WIDTH: 80px">
                 </x:input>
                 <space></space>

                 <x:input type="button" value="Close" id="btnSClose"
                     style="WIDTH: 80px" onClick="@command('doCancel')">
                 </x:input>
             </x:td>
         </x:tr>

         <x:tr>
             <x:td>
                 <x:embed id='dwtcontrolContainer_Obj'
                     style='display: inline; width:0px;height:0px'
                     type='Application/DynamicWebTwain-Plugin'
                     onPostAllTransfers="Dynamsoft_OnPostAllTransfers"
                     onTopImageInTheViewChanged="Dynamsoft_OnTopImageInTheViewChanged"
                     pluginspage='/resource/scanresources/DynamicWebTWAINPlugIn.msi'>
                 </x:embed>

             </x:td>
         </x:tr>
         <x:tr>
             <x:td>
                 <x:object style="display: inline;"
                     classid="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">
                     <x:param name="LPKPath"
                         value="/resource/scanresources/DynamicWebTwain.lpk">
                     </x:param>
                     </x:object>
                 <x:object style="width: 0px; height: 0px;"
                     id="dwtcontrolContainer_ObjIE"
                     codeBase="/resource/scanresources/DynamicWebTWAINx64.cab#version=9,1"
                     classid="clsid:E7DA7F8D-27AB-4EE9-8FC0-3FEC9ECFE758"
                     viewastext="">
                     <x:PARAM NAME="_cx" VALUE="2645"></x:PARAM>
                     <x:PARAM NAME="_cy" VALUE="2645"></x:PARAM>
                     <x:PARAM NAME="JpgQuality" VALUE="80"></x:PARAM>
                     <x:PARAM NAME="Manufacturer"    VALUE="DynamSoft Corporation"></x:PARAM>
                     <x:PARAM NAME="ProductFamily"    VALUE="Dynamic Web TWAIN"></x:PARAM>
                     <x:PARAM NAME="ProductName"    VALUE="Dynamic Web TWAIN"></x:PARAM>
                     <x:PARAM NAME="VersionInfo"    VALUE="9, 1, 0, 806"></x:PARAM>
                     <x:param name="ProductFamily" value="Dynamic Web TWAIN">
                </x:param>
            </x:object>
            <x:object style="width: 0px; height: 0px;"
                     id="dwtcontrolContainer_ObjIE32"
                     codeBase="/resource/scanresources/DynamicWebTWAIN.cab#version=9,1"
                     classid="clsid:E7DA7F8D-27AB-4EE9-8FC0-3FEC9ECFE758"
                     viewastext="">
                     <x:PARAM NAME="_cx" VALUE="2645"></x:PARAM>
                     <x:PARAM NAME="_cy" VALUE="2645"></x:PARAM>
                     <x:PARAM NAME="JpgQuality" VALUE="80"></x:PARAM>
                     <x:PARAM NAME="Manufacturer"    VALUE="DynamSoft Corporation"></x:PARAM>
                     <x:PARAM NAME="ProductFamily"    VALUE="Dynamic Web TWAIN"></x:PARAM>
                     <x:PARAM NAME="ProductName"    VALUE="Dynamic Web TWAIN"></x:PARAM>
                     <x:PARAM NAME="VersionInfo"    VALUE="9, 1, 0, 806"></x:PARAM>
                     <x:param name="ProductFamily" value="Dynamic Web TWAIN">
                </x:param>
            </x:object>
             </x:td>
         </x:tr>
     </x:table>
 </hlayout>

</window>

</zk>

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...