For smart Primates & ROBOTS (oh and ALIENS ).

Wednesday, September 03, 2014

Spilt in C# with word and character

Spilt in C# with word and character



// Split using single character 
String nms1="aa,bb,cc,dd,ee";
string[] nm1 = nms1.Split(',');


// Split using word 
using System.Text.RegularExpressions;

String nms2="aa<name>bb<name>cc<name>dd<name>ee";
string[] nm2 = Regex.Split(nms2, "<name>");

Share:

Dictionary in C#

Dictionary in C#

Dictionary is faster that ArrayList and HashTable in C#, here is the example that how to use Dictionary in C#.



Dictionary<int, string> dict = new Dictionary<int, string>();
//You are free to use either :
//Dictionary<string,int> dict = new Dictionary<string,int>();
dict.Add(1, "AA");
dict.Add(2, "BB");
dict.Add(3, "CC");

foreach (var data in dict) {
      nmCode = data.Key.ToString();
      nm = data.Value.ToString();
}



Share:

Parse single line JSON data in C#

Parse Single line JSON data in C# without objects

If you have received this JSON data string as listed below:
[‘aa’,’bb’,’cc’ ,’dd’,’ee’ ,’ff’,’gg’ ,’hh’,’ii’ ,’jj’,’kk’ ,’ll’,’mm’ ,’nn’,’oo’]

This is the array of JSON, you can see there are no Object data in that JSON string.
So, how you retrieve this JSON data in C#?
I have used JSON.Net from Newtonsoft.Json. it is a free library so you can download it from their site.






using Newtonsoft.Json.Linq;

String jsonData=”[‘aa’,’bb’,’cc’ ,’dd’,’ee’ ,’ff’,’gg’ ,’hh’,’ii’ ,’jj’,’kk’ ,’ll’,’mm’ ,’nn’,’oo’]”;
JArray names= JArray.Parse(jsonData);
//By foreach loop
foreach (Object nm in names){
    MessageBox.show(nm.toString());
}
// By For loop
for (int j=0; i< names.Count;j++) {
String nm = names [j].ToString();
MessageBox.show(nm.toString());
}

Share:

Saturday, August 30, 2014

Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in

Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in

While connecting with Google gmail via PHP , Java or any other code you may be face this error and get the message as listed below:
"Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX"

To overcome this problem logon your gmail and set permission via this link:
https://www.google.com/settings/security/lesssecureapps

After that you will be able to login via any programming languages.




Share:

Thursday, August 14, 2014

Rotate any Div in jquery

Rotate any Div in html jquery.
==========================



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Multirotation test</title>
        <script type="text/javascript" src="../js/jquery-1.6.js"></script>
        <script type="text/javascript" src="jquery.multirotation-1.0.js"></script>
    </head>
    <style type="text/css">
        div{text-align:center;margin:auto}
        div.rotable{background:#00CC66;border:solid 2px #f00;color:#fff;width:10px;height:10px;padding:5px;margin-top:60px;margin-bottom:60px}
    </style>
    <body>
        <div><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
           <div id="img_test" class="rotable">Amit
               
            </div>
            <p id="degs"></p>
        </div>
    </body>
      <script type="text/javascript">
        function plus(id) {
            $(id).rotate({ angle: 10 });
            get(id);
            return false;
        }

        function minus(id) {
            $(id).rotate({ angle: 90, direction: false });
            get(id);
            return false;
        }

        function reset(id) {
            $(id).clearRotation();
            get(id);
            return false;
        }

        function get(id) {
            var degs = $(id).getCurrentDegrees();
            //$('p#degs').html("Current degs: <b>" + degs + "°</b>");
        }
        var ang=1;
        intervalID=setInterval("setRotate('#img_test');",100);
       
        function setRotate(id) {
            $(id).rotate({ angle: 5 });
            get(id);
        }
       
       
    </script>
</html>



HERE IS THE jquery.multirotation-1.0.js CODE:
-----------------------------------------------------------------------

(function($){
    //global array to save the current rotation of the elements
    $.elems_rotation_history = [];

    $.fn.extend({
        clearRotation: function() {
            return this.each(function() {
                //get the element's identifier
                var id = this.id;
                //remove element from array
                $.elems_rotation_history[id] = null;
            });
        },

        getCurrentDegrees: function() {
            var id = this.attr('id');
            if (!$.elems_rotation_history[id]) {
                return 0;
            }
            return degs = $.elems_rotation_history[id].rotation;
        },

        rotate: function(options) {
            //create console
            if (!window.console) console = {};
            console.log = console.log || function(){};
            console.warn = console.warn || function(){};
            console.error = console.error || function(){};

            //set the default values
            var defaults = {
                  angle: 0
                , direction: true
                , speed: 0
                , deg2radians: Math.PI * 2 / 360
                ///debug
                , debug: false
                ///end
            };

            //to access options values use this: options.option_name
            var options = $.extend(defaults, options);

            return this.each(function() {
                //get the element's identifier
                var id = this.id;

                //if there aren't elements and there isn't the element into the array, sets rotation to 0
                if ($.elems_rotation_history && !$.elems_rotation_history[id]) {
                    $.elems_rotation_history[id] = { rotation: 0 };
                }

                //sets the rotation direction
                if (!options.direction) {
                    options.angle = options.angle * (-1);
                }

                //increments angle rotation of the element
                $.elems_rotation_history[id].rotation = (parseInt($.elems_rotation_history[id].rotation) + options.angle) % 360;

                ///debug
                if (options.debug) {
                    console.log("Angle = " + $.elems_rotation_history[id].rotation + " degree");
                }
                ///end

                rad = $.elems_rotation_history[id].rotation * options.deg2radians;
                costheta = Math.cos(rad);
                sintheta = Math.sin(rad);

                var a = parseFloat(costheta).toFixed(8);
                var b = parseFloat(sintheta).toFixed(8);
                var c = parseFloat(-sintheta).toFixed(8);
                var d = parseFloat(costheta).toFixed(8);

                var sMatrix = "matrix(" + a + ", " + b + ", " + c + ", " + d + ", 0, 0)";

                if ($(this).get(0).filters) {
                    if (options.speed > 0) {
                        console.warn("You set the speed options but IE doesn't support CSS3 transitions");
                    }

                    //if the browser is IE
                    try {
                        var x = $(this).get(0).filters.item("DXImageTransform.Microsoft.Matrix").enabled;
                    }
                    catch(e) {
                        $(this).get(0).style.filter += "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand');";
                    }

                    var matrix = $(this).get(0).filters.item("DXImageTransform.Microsoft.Matrix");
                    matrix.M11 = costheta;
                    matrix.M21 = sintheta;
                    matrix.M12 = -sintheta;
                    matrix.M22 = costheta;
                    matrix.enabled = true;

                    ///debug
                    if (options.debug) {
                        console.log("Set transform = matrix[" + matrix.M11 + ", " + matrix.M21 + ", " + matrix.M12 + ", " + matrix.M22 + "]");
                    }
                    ///end
                } else {
                    //animate rotation if speed > 0s
                    if (options.speed > 0) {
                        $(this).css("-moz-transition", "all " + options.speed + "s ease-in-out");
                        $(this).css("-webkit-transition", "all " + options.speed + "s ease-in-out");
                        $(this).css("-o-transition", "all " + options.speed + "s ease-in-out");
                    }
                    $(this).css("-moz-transform", sMatrix);
                    $(this).css("-webkit-transform", sMatrix);
                    $(this).css("-o-transform", sMatrix);

                    ///debug
                    if (options.debug) {
                        console.log("Set transform = " + sMatrix);
                    }
                    ///end
                }
            });
        }
    });
})(jQuery)

Share:

PHP with MSSQL Server Simple Query

PHP with MSSQL Server Simple Query.

<?php
session_start();
$sqlServerIP = '127.0.0.1';
$link = mssql_connect($sqlServerIP, 'sa', 'amit123');
if (!$link) {
    die('Wrong connection');
}

mssql_select_db('AssetMgmt', $link);
$User_Email="email@email.com";
$User_Pass='test';
$ssql="select *from USER_MASTER where User_Email='".$User_Email."' and User_Pass='" .$User_Pass ."'";
$result = mssql_query($ssql);
$numrow=mssql_num_rows($result);
if (!mssql_num_rows($result)) {
    echo 'Login/Pass is invalid';
}
else
{
    echo '<ul>';
    while ($row = mssql_fetch_assoc($result)) {
        echo '<li>' . $row['Name'] . ' (' . $row['EmpID'] . ')</li>';
    }
    echo '</ul>';
}
mssql_free_result($result);
?>
Share:

PHP with MSSql Server Stored procedure return records

Connect PHP with MSSql Server Stored procedure and return records.


<?php
$sqlServerIP = '127.0.0.1';
$link = mssql_connect($sqlServerIP, 'sa', 'amit123');
if (!$link) {
    die('wrong connection');
}
mssql_select_db('amittest', $link);
$stmt = mssql_init('ListEmp');
$ID = 100;
mssql_bind($stmt, '@ID',            $ID,              SQLINT4,     false, false, 4);
$result=mssql_execute($stmt);
$num = mssql_num_rows($result);

if($num>0) {
    while($row = mssql_fetch_assoc($result)) {
        echo "<li>" . $row['ID'] . $row['EmpID']."</li>";
    }
    mssql_free_statement($stmt);
}
else {
    echo "No records found";
}
echo mssql_get_last_message();
/*
CREATE PROCEDURE dbo.ListEmpmp
    @ID bigint
    as
begin
    select ID,EmpID from Employee where ID>=@ID
End
*/
?>
Share:

PHP with MSSQL Server Stored Procedure

Here is the code to connect PHP with Mssql Server Stored procedure.



<?php
$sqlServerIP = '127.0.0.1';
$link = mssql_connect($sqlServerIP, 'sa', 'amit123');
if (!$link) {
    die('wrong connection.');
}
mssql_select_db('amittest', $link);
$stmt = mssql_init('LoginChk');
$ID = 1;
$EmpID = 'Emp001';
$OutputLogin=0;
// Bind values
mssql_bind($stmt, '@ID',            $ID,              SQLINT4,     false, false, 60);
mssql_bind($stmt, '@EmpID',         $EmpID,           SQLVARCHAR,  false, false, 20);
mssql_bind($stmt, '@OutputLogin',     $OutputLogin,   SQLINT4,     true,  false, 20);
mssql_execute($stmt);
mssql_free_statement($stmt);
echo $OutputLogin;
echo mssql_get_last_message();
/*
////////////////////////////////////////////////////////
CREATE PROCEDURE dbo.LoginChk
    @ID varchar(50),
    @EmpID varchar(50),
    @OutputLogin bigint OUTPUT
    as
begin
    IF(EXISTS(select ID,EmpID, from Employee where ID=@ID and EmpID=@EmpID))
        begin
            --select  @OutputFirstName=vFirstName from AdminInfo where vUserId=@UserId and vPassword=@Password
            select @OutputLogin =1
        End
    else
        begin
            select @OutputLogin =0
        End
End
*/
?>
Share:

Exact date problem in ms access sql

Exact date problem in ms access sql
===============================

Suppose you have a column in the table of ms access database with DateTime. and you are storing Date and Time values. After that if you use query "select *from tbl where creationDate>=#07/30/2014# and creationDate<=#07/30/2014#  then you will surprise that no result will come as output. this is because your column is have both Data "DateTime".
So the problem is that how to show the data even data are exists in the table?
Append the time in the query as listed below:

"select *from tbl where creationDate>=#07/30/2014 00:00 AM# and creationDate<=#07/30/2014 23:59 PM#"









Share:

Generate CSV in jsp without third party utility

Generate CSV in jsp without third party utility

There are lot of third party paid and free utility that generate CSV file in JSP/Java. but the problems are to hard to implement. and may utility first create CSV file in the server, so Server space will be consumed.
To overcome all the problem I have created listed below the code. You are free to use it in you project.

<%@ page import="java.util.ArrayList"%>
<%
response.setContentType("application/csv");
response.setHeader("content-disposition","filename=test.csv");
// the session.getAttribute("listResult") is containg of comma sepearte multiple lines as listed below
//aa,10,20,30
//bb,10,20,30
//cc,10,20,30
//dd,10,20,30

ArrayList<String> list = (ArrayList<String>)session.getAttribute("listResult");
out.println("<table border='1'>");
for(int i = 0; i < list.size(); i++) {
    String myString = (String)list.get(i);

    out.println(myString);


}

out.flush();
out.close();
%>
Share:

Ads Inside Post

Powered by Blogger.

Archive