Tuesday, 25 October 2011

Demand for a product increases when the prices of its complements decrease

Demand for a product increases when the prices of its complements decrease.
This quote comes from Strategy Letter V (Joel on software). It's useful for selling products.
Every product in the marketplace has substitutes and complements. 
A substitute is another product you might buy if the first product is too expensive. 
Chicken is a substitute for beef. 
If you're a chicken farmer and the price of beef goes up, 
the people will want more chicken, and you will sell more.
When computers become cheaper, more people buy them, and they all need operating systems, 
so demand for operating systems goes up, which means the price of operating systems can go up.
Smart companies try to commoditize their products' complements.
When IBM designed the PC architecture, they used off-the-shelf parts instead of custom parts, 
and they carefully documented the interfaces between the parts in the (revolutionary) IBM-PC Technical Reference Manual. 
Why? So that other manufacturers could join the party. As long as you match the interface, you can be used in PCs. 
IBM's goal was to commoditize the add-in market, which is a complement of the PC market, and they did this quite successfully. 
Within a short time scrillions of companies sprung up offering memory cards, hard drives, graphics cards, printers, etc. 
Cheap add-ins meant more demand for PCs.
When IBM licensed the operating system PC-DOS from Microsoft, Microsoft was very careful not to sell an exclusive license. 
This made it possible for Microsoft to license the same thing to Compaq 
and the other hundreds of OEMs who had legally cloned the IBM PC using IBM's own documentation. 
Microsoft's goal was to commoditize the PC market. Very soon the PC itself was basically a commodity, with ever decreasing prices, 
consistently increasing power, and fierce margins that make it extremely hard to make a profit. The low prices, of course, increase demand.
 Increased demand for PCs meant increased demand for their complement, MS-DOS. 
All else being equal, the greater the demand for a product, the more money it makes for you. 
And that's why Bill Gates can buy Sweden and you can't.

Sunday, 16 October 2011

Retrieve CPU brand by C and Win32 API


In order to retrieve CPU brand, information in red square on above photo, please use following code:

string GetCPUBrand() {
 char pszCPUBrand[49];
 memset(pszCPUBrand, ' ', 49);

 _asm {
  mov eax, 80000002h
  cpuid

  // getting information from EAX

  mov pszCPUBrand[0], al
  mov pszCPUBrand[1], ah
  ror eax, 16
  mov pszCPUBrand[2], al
  mov pszCPUBrand[3], ah

  // getting information from EBX

  mov pszCPUBrand[4], bl
  mov pszCPUBrand[5], bh
  ror ebx, 16
  mov pszCPUBrand[6], bl
  mov pszCPUBrand[7], bh

  // getting information from ECX

  mov pszCPUBrand[8], cl
  mov pszCPUBrand[9], ch
  ror ecx, 16
  mov pszCPUBrand[10], cl
  mov pszCPUBrand[11], ch

  // getting information from EDX

  mov pszCPUBrand[12], dl
  mov pszCPUBrand[13], dh
  ror edx, 16
  mov pszCPUBrand[14], dl
  mov pszCPUBrand[15], dh

  mov eax, 80000003h
  cpuid

  // getting information from EAX

  mov pszCPUBrand[16], al
  mov pszCPUBrand[17], ah
  ror eax, 16
  mov pszCPUBrand[18], al
  mov pszCPUBrand[19], ah

  // getting information from EBX

  mov pszCPUBrand[20], bl
  mov pszCPUBrand[21], bh
  ror ebx, 16
  mov pszCPUBrand[22], bl
  mov pszCPUBrand[23], bh

  // getting information from ECX

  mov pszCPUBrand[24], cl
  mov pszCPUBrand[25], ch
  ror ecx, 16
  mov pszCPUBrand[26], cl
  mov pszCPUBrand[27], ch

  // getting information from EDX

  mov pszCPUBrand[28], dl
  mov pszCPUBrand[29], dh
  ror edx, 16
  mov pszCPUBrand[30], dl
  mov pszCPUBrand[31], dh

  mov eax, 80000004h
  cpuid

  // getting information from EAX

  mov pszCPUBrand[32], al
  mov pszCPUBrand[33], ah
  ror eax, 16
  mov pszCPUBrand[34], al
  mov pszCPUBrand[35], ah

  // getting information from EBX

  mov pszCPUBrand[36], bl
  mov pszCPUBrand[37], bh
  ror ebx, 16
  mov pszCPUBrand[38], bl
  mov pszCPUBrand[39], bh

  // getting information from ECX

  mov pszCPUBrand[40], cl
  mov pszCPUBrand[41], ch
  ror ecx, 16
  mov pszCPUBrand[42], cl
  mov pszCPUBrand[43], ch

  // getting information from EDX

  mov pszCPUBrand[44], dl
  mov pszCPUBrand[45], dh
  ror edx, 16
  mov pszCPUBrand[46], dl
  mov pszCPUBrand[47], dh

 }

 pszCPUBrand[48] = '\0';

 return string(pszCPUBrand);
}

Saturday, 15 October 2011

Call JSONP with jQuery

In order to call JSONP with jQuery, please use following code

function jsonp() {

  this.request = function(url, args, callbackVar, bufferID) {
    var super = this;
    var callback = 'jsonp_response_' + Math.floor(Math.random() * 100000);
    window[callback] = function(data) {
      super.response(args, data);
      delete window[callback];
    }
    var params = { callbackVar : callback };
    var buffer = $('#' + bufferID);
    buffer.append("<script src='" + url + '&' + jQuery.param(params) + "'></script>");
  }

  this.response = function(args, data) {
  }

}

callbackVar: name of GET variable containing JSONP callback, eg. api.php?jsonp=response
bufferID: id of empty div tag which is used for temporarily adding script tag
args: arguments is passed to callback function

Friday, 14 October 2011

Upload file to SharePoint site

In order to upload file to SharePoint site, please use following code:

private String uploadFile(String site, String username, String password, String library, String filename) {
     String tag = "";
     try {
      CopySoapStub stub = SharePointWSDL.newCopy(new URL(site + "/_vti_bin/Copy.asmx"), new CopyLocator());
      stub.setUsername(username);
      stub.setPassword(password);

      String name = (new File(filename)).getName();
      String tagPath = site + "/" + library + "/" + name; 
      FieldInformation[] fis = new FieldInformation[1];
      UnsignedIntHolder uih = new UnsignedIntHolder(new UnsignedInt());
      CopyResultCollectionHolder crch = new CopyResultCollectionHolder(new CopyResult[] { new CopyResult() });

      fis[0] = new FieldInformation();
      fis[0].setInternalName("Title");
      fis[0].setDisplayName(name);
      fis[0].setType(FieldType.Text);
      fis[0].setValue(name);
       
      stub.copyIntoItems(tagPath, new String[] { tagPath }, fis, readFile(filename), uih, crch);
      boolean success = true;
      for (int i = 0; i < crch.value.length; i++) {
       if (CopyErrorCode._Success.equals(crch.value[i].getErrorCode().getValue())) continue;
       logger.error(crch.value[i].getErrorCode().getValue() + " : " + crch.value[i].getErrorMessage());
       logger.info(crch.value[i].getDestinationUrl());
       success = false;
      }
      if (success) {
          tag = tagPath;
      }
     } catch (Exception e) {
      logger.error("", e);
     }
     return tag;
    }
    
    private byte[] readFile(String filename) {
     File file = new File(filename);
     byte[] tag = new byte[0];
     try {
         tag = new byte[(int)file.length()];
         InputStream is = new FileInputStream(file);     
         int offset = 0;
            int numRead = 0;
            while (offset < tag.length && (numRead = is.read(tag, offset, tag.length - offset)) >= 0) {
                offset += numRead;
            }     
     } catch (Exception e) {
      logger.error("", e);
     }
     return tag;
    }

Above code use Java WSDL for SharePoint

You should use domain name in site URL instead of IP.

Using IP will cause error. Please checkout Get 'Object reference not set to an instance of an object' error when upload file to SharePoint

Thursday, 13 October 2011

Accessing SharePoint web service requires Basic Authentication

In order to access SharePoint web service through java WSDL, you need to enable Basic Authentication for IIS. 

Please checkout Get '(401)Unauthorized' error when calling SharePoint web service and wsdl2java with Basic Authentication (Axis 1.6.1)

Retrieve list of libraries on SharePoint site

In order to retrieve list of libraries on SharePoint site, please use following code:

private List getLibraries(String site, String username, String password) {
     List tag = new ArrayList();
     try {
      ListsSoapStub stub = SharePointWSDL.newLists(new URL(site + "/_vti_bin/Lists.asmx"), new ListsLocator());
      stub.setUsername(username);
      stub.setPassword(password);
      com.microsoft.schemas.sharepoint.soap.GetListCollectionResponseGetListCollectionResult lcr = stub.getListCollection();
      if (lcr.get_any().length > 0) {
          NodeList children = lcr.get_any()[0].getChildNodes();
          for (int i = 0; i < children.getLength(); i++) {
           Node node = children.item(i);
           String baseType = node.getAttributes().getNamedItem("BaseType").getNodeValue();
           if (!"1".equals(baseType)) continue;
           String template = node.getAttributes().getNamedItem("ServerTemplate").getNodeValue();
           String title = node.getAttributes().getNamedItem("Title").getNodeValue();
           if ("|101|115|109|".indexOf("|" + template + "|") < 0) continue;
           tag.add(title);
          }
      }
     } catch (Exception e) {
      logger.error("", e);
     }
     return tag;
    }
Above code use Java WSDL for SharePoint

Tuesday, 11 October 2011

Install java plugin on Ubuntu 10.04.3 LTS

1. Open FireFox or Chromium
2. Go go http://java.com
3. Click on "Free Java Download"

4. Scroll to Linux section
5. Click on "Verify Now" link


6. When you are asked to install missing plugin, choose to install "Icedtea Java Plugin"
7. Close browser and open it again, java is enabled for your browser now.