Pages

Sunday, September 18, 2011

SQL WHILE Begin End

USE CommunityUseOfPublicSchools;





DECLARE @name VARCHAR(MAX);
DECLARE @sql VARCHAR(MAX);



DECLARE table_cursor CURSOR FOR
SELECT  ST.name FROM sys.tables ST



OPEN table_cursor
FETCH NEXT FROM table_cursor INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN

SET @sql= 'drop table "'+@name+'" ';
EXECUTE(@sql);

FETCH NEXT FROM table_cursor INTO @name
END
CLOSE table_cursor
 DEALLOCATE table_cursor

Wednesday, July 27, 2011

Discover query for SSAS server

<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
  <
RequestType>MDSCHEMA_CUBESRequestType>
  <
Restrictions
/>
  <
Properties
>
    <
PropertyList
>
      <
Catalog>Adventure Works DWCatalog>
    PropertyList
>
  Properties
>
Discover>


<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
   <
RequestType>DBSCHEMA_CATALOGSRequestType>
   <
Restrictions
/>
   <
Properties
/>
Discover>


<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
  <
RequestType>MDSCHEMA_CUBESRequestType>
  <
Restrictions
/>
  <
Properties
/>Discover>



 
 

Monday, July 25, 2011

SharePoint tutorials

http://www.sharepointhosting.com/video_tutorials.html
contain this list of videos


Adding Documents to a SharePoint Site
Create a new SharePoint Site Collection Administrator
Add Links to a SharePoint List
Add SharePoint Site to your Trusted Sites in Internet Explorer
Add Users to a SharePoint Security Group
Approve another user's SharePoint Blog Post
Change SharePoint Navigation to a Site Tree View
Change the SharePoint Site Image
Change the SharePoint Site Title and Description
Change a SharePoint User's e-mail address
Change a SharePoint User's password
Create a SharePoint Calendar Appointment
Create a Document-specific SharePoint Alert
Create a New SharePoint User
Create a SharePoint Announcements List
Create a SharePoint Blog Posting
Create a SharePoint Calendar
Create a SharePoint Contacts List
Create a SharePoint Discussion Board
Create a SharePoint Document Library
Create a SharePoint Document Work Space
Create a SharePoint Gantt Project Management Chart
Create a SharePoint InfoPath form Library
Create a SharePoint Links List
Create a SharePoint Meeting Site
Create a SharePoint Picture Library
Create a new SharePoint Security Group
Create a new SharePoint Sub-site
Create a new Task in a SharePoint Tasks list and assign it to a user
Create a SharePoint Wiki Document
Create a SharePoint Wiki Library
Customize a SharePoint Meeting Site
Delete a SharePoint Meeting Site when you are finished with it
Edit SharePoint Blog Categories
E-mail a SharePoint Document Library
E-mail Enable a SharePoint Discussion Forum
Enable Multiple SharePoint Blog Categorizations
Edit the SharePoint Quick Launch Menu to Customize with your own navigation options
Enable SharePoint Document Versioning
Change SharePoint Top Link bar navigation options
Manage Access Requests to your Site
Move Documents between SharePoint Document Libraries
Remove Permission Inheritance from SharePoint Sub-sites
Remove the SharePoint Quick Launch Menu
Remove Top Link Bar Inheritance from a SharePoint Site
Restore Deleted Items As the Site Collection Administrator
Restore SharePoint Site Permission Inheritance (sub-sites)
Work with the SharePoint Recycle Bin
Create a SharePoint Sales CRM Application
Work with your SharePoint Themes
Add Tabbed SharePoint Navigation Options to your Site
Add SharePoint Web Parts
Sign in as a different SharePoint User
Work with a SharePoint Gantt Project Chart
Create a Custom Site Column

Sunday, July 17, 2011

JUnit

package examples.test;

import java.io.*;
import java.net.*;

import examples.rss.*;
import junit.framework.Assert;
import junit.framework.TestCase;


public class RSSReaderTest extends TestCase {

    public void testParsLocalfile() {
        String resourceLocation="/examples/documents/ABC_Catalyst.xml";
        URL result = getClass().getResource(resourceLocation);
        InputStream stream=null;
        try {
            stream = result.openStream();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        RSSReader reader=RSSReader.getInstance(stream);
        Feed feed=    reader.readFeed();

        Assert.assertTrue("Invalid Feed Title", feed.getTitle().equals("Learning, reference repository Cli"));
        Assert.assertTrue("Invalid Feed Link", feed.getLink().equals("http://lrr.cli.det.nsw.edu.au/"));

        Assert.assertTrue("Invalid Feed Entries", feed.getEntries().toArray().length>0);

    }
}

Friday, July 15, 2011

Export and Running Java project

1- Export the project as Runnable JAR file via eclips
2- Use the command line  shell>java -jar  your_exported_jar.jar

Java Hibernate code

 Hibernate sample code using MySQL

public class FirstExample {
    public static void main(String[] args) {
        Session session = null;

        try{
       
            SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

             Contact contact = new Contact();
            contact.setId(0);
            contact.setFirstName("Deepak");
            contact.setLastName("Kumar");
            contact.setEmail("deepak_38@yahoo.com");

            session =sessionFactory.openSession();
         Transaction tx=        session.beginTransaction();
        session.save(contact);
        tx.commit();

            session.flush();
            session.close();

        }catch(Exception e){
            System.out.println(e.getMessage());
        }finally{
            // Actual contact insertion will happen at this step
            session.flush();
            session.close();
        }
    }
}
----------------------------

MySQL scripts

shell> mysql -h host -u user -p
Enter password: ********
 mysql -u root -p
Enter password: ********


show databases;

shell> use [database];
use lportal

show tables;

shell> describe [tablename];
describe website
select DATABASE();     //current databse

mysql> SELECT USER(),VERSION(), CURRENT_DATE;

Saturday, June 25, 2011

JAVA Code Snippet

String.Format(for (int i = 0; i < names.length; i++) {
                    //out.println("
" + names[i]);
                    out.print(String.format("%s %s", "
", names[i])
);
                }



Enumeration
 Enumeration params = request.getParameterNames();
        while (params.hasMoreElements())
        {
// Get the next parameter name.
            String paramName = params.nextElement();






Reading Resource File
public void testParsLocalfile() {
        String resourceLocation="/examples/documents/ABC_Catalyst.xml";
        URL result = getClass().getResource(resourceLocation);
        InputStream stream=null;
        try {
            stream = result.openStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        assertTrue("File is not exists", stream!=null);
   
        try {
            stream.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }


Uploading files

InputStream in = request.getInputStream();

// The file is always saved with the same name (just for this demo).
String path =this.getServletContext().getRealPath("/tmp/uploaded_file.txt");
OutputStream fileOut = new BufferedOutputStream(
new FileOutputStream(path));
// Create a buffer for reading bytes from the input stream.
byte[] buff = new byte[4096];
int len;

// Read bytes from the input stream, and write them to the file.
while ((len = in.read(buff)) > 0)
{
fileOut.write(buff, 0, len);
}
fileOut.close();

Saturday, June 18, 2011

MVC JNSON

// 
public ActionResult GetContactsJSON(string id)
{
if (string.IsNullOrEmpty(id))
{
return Json(_ctx.Contacts.OrderBy(cnt => cnt.FirstName).Take(100).ToList(), JsonRequestBehavior.AllowGet);
}
else
{

return Json(_ctx.Contacts.Where(cnt => cnt.FirstName.StartsWith(id)).OrderBy(cnt => cnt.FirstName).Take(100).ToList(), JsonRequestBehavior.AllowGet);

}
}
public ActionResult GetContactJSON(int id)
{

return Json(_ctx.Contacts.SingleOrDefault(cnt => cnt.ContactID == id), JsonRequestBehavior.AllowGet);

}

JSON webservice

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using Cli.Lsp.Web2Services.RatingService.Bll.Adapters;

///

/// Summary description for RatingService_JSONP
///

[WebService(Namespace = "http://ws.cli.det.nsw.edu.au/ns/Web2Services/RattingService",
           Description = "Ratting service, this service will be plugable in any application, to support rating with comments, including reports and summaries")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class RatingService_JSONP : RatingService
{
    [WebMethod, ScriptMethod(UseHttpGet= true)]
    public override int GetNoOfLiked(int applicationID, string applicationItemID)
    {
        return RateServiceAdapter.GetNoOfLiked(applicationID, applicationItemID);
    }
   
    [WebMethod, ScriptMethod(UseHttpGet = true)]
    public override void Rate(int applicationID, string applicationItemID, int rate, string comment, string userID)
    {
         RateServiceAdapter.LightRate(applicationID, applicationItemID, rate, comment, userID);

    }
    [WebMethod(Description = @"Sample Please remove it")]
    [ScriptMethod(UseHttpGet=true)]
    public string[] Sample()
    {
        return new string[] { "AAA", "BBB", "CCC", "DDD" };
    }

}

Simple JSP code

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"
      import="de.vogella.wtp.jsp.controller.*,java.util.*"%>
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Show all namestitle>
head>
<body>

      <form method="GET" action='HomeController' name="showall">
            <table>
                  <%
                        ArrayList users = new ArrayList();
                        if (request.getSession(true).getValue("users") instanceof ArrayList) {
                              users = (ArrayList) request.getSession(true).getValue("users");
                        }
                        for (User user : users) {
                  %>
                  <tr>
                        <td><input type="checkbox" name="<%=user.getID()%>" />
                        td>
                        <td><%=user.getFirstName()%>td>
                        <td><%=user.getLastName()%>td>
                  tr>

                  <%
                        }
                        ;
                  %>

            table>

            <p>
                  <input type="submit" name="delete" value="delete" />  <input
                        type="submit" name="edit" value="edit" />  <input type="reset"
                        value="reset" />
            p>
      form>



body>
html>

Simple AWT Java Application

//MyFirstUI.java
package ui;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;


public class MyFirstUI extends JFrame implements ActionListener{

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private JCheckBox checkbox;
    private JTextField firstName;
    private JTextField lastName;

    public MyFirstUI() {

        // Lets make it look nice
        // This you can ignore / delete if you don't like it
        // try {
        // for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        // if ("Nimbus".equals(info.getName())) {
        // UIManager.setLookAndFeel(info.getClassName());
        // break;
        // }
        // }
        // } catch (Exception e) {
        // e.printStackTrace();
        // }

        setTitle("My First UI");

        // We create a panel which will hold the UI components
        JPanel pane = new JPanel(new BorderLayout());
        // We always have two UI elements (columns) and we have three rows
        int numberOfRows = 3;
        int numberOfColumns = 2;
        pane.setLayout(new GridLayout(numberOfRows, numberOfColumns));

        // create and attach buttons
        // create a label and add it to the main window
        JLabel firstNamelabel = new JLabel(" Firstname: ");
        pane.add(firstNamelabel);
        firstName = new JTextField();
        pane.add(firstName);

        JLabel lastNamelabel = new JLabel(" Lastname: ");
        pane.add(lastNamelabel);
        lastName = new JTextField();
        pane.add(lastName);

        JButton sayHello = new JButton("Say something");
        pane.add(sayHello);

        checkbox = new JCheckBox("Nice");
        pane.add(checkbox);

        // Add the pane to the main window
        getContentPane().add(pane);

        // Pack will make the size of window fitting to the compoents
        // You could also use for example setSize(300, 400);
        pack();

        // Set a tooltip for the button
        sayHello.setToolTipText("This button will say something really nice of something bad");
        // sayHello need to do something
        sayHello.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e) {
        if (!checkbox.isSelected()) {
            JOptionPane.showMessageDialog(null, "I don't like you, "
                    + firstName.getText() + " " + lastName.getText() + "!");
        } else {
            JOptionPane.showMessageDialog(null, "How are you, "
                    + firstName.getText() + " " + lastName.getText() + "?");
        }
    }


}

//MainTester.java
package test;

import ui.MyFirstUI;

public class MainTester {
    public static void main(String[] args) {
        MyFirstUI view = new MyFirstUI();
        view.setVisible(true);
    }
}

Thursday, February 17, 2011

Objective C

1-
self.[propertynam]=value;      //you have to use @property otherwise it will not work
 

Wednesday, January 26, 2011

Managing Application Pools in IIS 7

http://technet.microsoft.com/en-us/library/cc753449%28WS.10%29.aspx

  • In IIS 7, application pools run in one of two modes: integrated mode and classic mode
Most managed applications should run successfully in application pools with integrated mode, but you may have to run in classic mode for compatibility reasons. Test the applications that are running in integrated mode first to determine whether you really need classic mode.


Application Pool Identity Accounts

Worker processes in IIS 6.0 and IIS 7 run as NETWORKSERVICE by default. NETWORKSERVICE is a built-in Windows identity. It doesn't require a password and has only user privileges; that is, it is relatively low-privileged. Running as a low-privileged account is a good security practice because then a software bug can't be used by a malicious user to take over the whole system.
However, a problem arose over time as more and more Windows system services started to run as NETWORKSERVICE. This is because services running as NETWORKSERVICE can tamper with other services that run under the same identity. Because IIS worker processes run third-party code by default (Classic ASP, ASP.NET, PHP code), it was time to isolate IIS worker processes from other Windows system services and run IIS worker processes under unique identities. The Windows operating system provides a feature called "Virtual Accounts" that allows IIS to create unique identities for each of its Application Pools. Click here for more information about Virtual Accounts.

Securing Resources

Whenever a new Application Pool is created, the IIS management process creates a security identifier (SID) that represents the name of the Application Pool itself. For example, if you create an Application Pool with the name "MyNewAppPool," a security identifier with the name "MyNewAppPool" is created in the Windows Security system. From this point on, resources can be secured by using this identity. However, the identity is not a real user account; it will not show up as a user in the Windows User Management Console.
You can try this by selecting a file in Windows Explorer and adding the "DefaultAppPool" identity to the file's Access Control List (ACL).
  1. Open Windows Explorer
  2. Select a file or directory.
  3. Right click the file and select "Properties"
  4. Select the "Security" tab
  5. Click the "Edit" and then "Add" button
  6. Click the "Locations" button and make sure you select your machine.
  7. Enter "IIS AppPool\DefaultAppPool" in the "Enter the object names to select:" text box.
  8. Click the "Check Names" button and click "OK".
By doing this, the file or directory you selected will now also allow the "DefaultAppPool" identity access.

Sunday, January 23, 2011

SQL commands

osql -L 
//for browsing all SQL instances

Tuesday, January 18, 2011

Monday, January 17, 2011

JQuery XML parsing

<script type="text/javascript">
        $(document).ready(function () {
 
            $.each(($.browser), function (i, val) {
 
            });
 
            $("#btnlookup").click(function () { lookup(); });
 
 
        });
           if (!$.browser.msie) {
                alert('this utility is available only for IE, please try JSONP for other browsers');
                 return;
            }
            var addressURL = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + $("#txtAddress").val() + "&sensor=false";             alert(addressURL);             $("#output").text("");             $.ajax({                 url: addressURL,                 dataType: "xml",                 success: function (response) {                     if (!$.isXMLDoc(response)) {                         var outputStr = "Result is not valid XML Format";                         $(outputStr).appendTo($("#output"));                     }                     $.each($(response).find('result'), function () {                         var outputStr = "
" + "" + $(this).find('formatted_address').text() + " lat:" + $(this).find("location").find("lat").text() + ", lng" + +$(this).find("location").find("lng").text() + " " + "
"
;                         $(outputStr).appendTo($("#output"));                     });                 }, //sccess                 error: function (response) {                     var outputStr = "" + response.status + "";                     $(outputStr).appendTo($("#output"));                 }             }//ajax options                             );         }     script>

JSON via webservices Using JSONP

//Step1  add ScriptService  for the class & [ScriptMethod(UseHttpGet = true)]
//to the method
/// 
/// Summary description for RatingService_JSONP
/// 
[WebService(Namespace = "http://ws.cli.det.nsw.edu.au/ns/Web2Services/RattingService",
           Description = "Ratting service, this service will be plugable in any application, to support rating with comments, including reports and summaries")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class RatingService_JSONP : RatingService
{
    }
    [WebMethod(Description = @"Sample Please remove it")]
    [ScriptMethod(UseHttpGet = true)]
    public string[] Sample()
    {
        return new string[] { "AAA""BBB""CCC""DDD" };
    }
 
}
 
//Step2 
// use format=json  for json format
// use callback=?    for JSONP
  
 $(document).ready(function () {
            $("#btnlookup").click(function () { lookup(); });
        });
        function lookup() {
            var addressURL = "http://localhost/Web2Services/WebServices/JSON/RatingService_JSONP.asmx/Sample?format=json&callback=?";
            var outputStr = "";
            $("#output").text(outputStr);
            $.getJSON(addressURL, nullfunction (response) {
                $.each(response.d, function (i, val) {
                    outputStr = "
" + val.toString() + "
"
;                                          $(outputStr).appendTo("#output");                 });             });     // getJson