Thursday, May 31, 2012

Fatal error: Call to undefined function session_start() in Php 6

you may get this error you are not a PHP guy ,

Fatal error: Call to undefined function session_start()
run phpinfo session is enabled.

image

then what’s wrong? the answer is short. this functio has been removed since php 5.4, so your php is too new for this code.
image

Tuesday, May 22, 2012

C#, Chained lambda expression to validate Email

image

>

image

JAVA regular expression, encode &#[0-9]+ form html

private static String ReplceSpecialChars(String s) {
        String orig=s;
        Pattern pnum=Pattern.compile("&#([0-9]+);");
        Matcher m=pnum.matcher(s);
        while(m.find())
        {
            int t=Integer.parseInt(m.group(1));
            char ch=(char)t;
            orig=orig.replaceFirst(m.group(0), ""+ch);
        }
        return orig;
    }

CàT will be parsed to CàT
CàáT , will be CàáT

Thursday, May 17, 2012

How to: Get ProcessID of a given application pool on IIS

there are couple ways to get the processed of a given application pool, here is some quick ways to do that.

Using WMIC, this works for IIS6/IIS7

Go command prompt, type “wmic”
  put the query like “process where name=”w3wp.exe” get processid, commandline” , you will see the app pool name and the processid.
image

or just put in one line,
image 

using task manager for windows 7 or 2008,add commandline to the columns
image

Or run cmd as admin, go to “c:\Windows\System32\inetsrv” run “appcmd.exe list wp”, using the IIS admin tools , this works only for iis 7 and above

image

or using DebugDiag, this works for all IIS version,
go to the process tab, it has the web application pool name,
image

Monday, May 14, 2012

Using the async node.js library to get twitter content in a parallel

Quick test: setup the node.js to pull the contents from twitter in a parallel, and parse the json data back,
  If search, http://search.twitter.com/search.json?q=lakers&rpp=5&include_entities=true&result_type=mixed, will show lakes news. 
  Here is one quick code to search 5 NBA teams, and get the text back.
 


var async=require("async");var http=require("http"); var fs=require("fs");

function getwebPageContents(keyword,callback)
{
    var client=http.get({"host":"search.twitter.com","port":"80",
        "path":"/search.json?q=" + keyword + "&rpp=5&include_entities=true&result_type=mixed"
    }, function(data)
    {   
        var p="";
        data.on("data",function(chunk)
        {
            p+=chunk;
        } );
        data.on("end",function()
        {
            callback(null, p);
        })
    })
}

async.parallel([
    function(callback){
            getwebPageContents("lal",callback)
    },
    function(callback){
            getwebPageContents("lac",callback)
    },
     function(callback){
            getwebPageContents("okc",callback)
    },
    function(callback){
            getwebPageContents("mia",callback)
    }, function(callback){
            getwebPageContents("phi",callback)
    }
], function(e,data)
{
    
    for(p in data)
    {
        console.log( "result- " +p +  "  " +JSON.parse(data[p]).results[0].text);
    }
    
});


you will get some data, like this,
image

Node.js and Sublime auto completion and Build integration / windows 7

Sublime Text is a Super IDE for developers, if you are looking the same experience for Node.js, there is one plug-in which supports Both.  you can check it here, https://github.com/tanepiper/SublimeText-Nodejs

for the installation, if you don’t have any GIT on windows, just go to https://github.com/tanepiper/SublimeText-Nodejs
click the zip to download all the bits,
image
then unzip the file, to  F:\Users\Androidyou\AppData\Roaming\Sublime Text 2\Packages\Nodejs, must be no further subfoder in this directory. otherwise, the build wont work, so the final resutlsl looks like<

image

once done, restart the sublime, you can see the node.js build /and run profle are there.
image

image

Friday, May 11, 2012

Java regular expression to extract Date format like April 12, 2012

String s = "Department May 89 , 2012 - May 09 , 2011, June 12, 2011";
        Pattern p = Pattern.compile(
                "(jan|feb|mar|apr|may|jun|jul|aug|sep|nov|dec)[a-z]{0,6}[\\s]*[0-9]{1,2}[\\s]*,[\\s]*[0-9]{4}",
                Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(s);
        while (m.find()) {
                System.out.println(m.group(0));
        }


You will get all 3 dates,
image

Monday, May 7, 2012

How to: Using R to Analysis IIS Logs

IIS Logs are basically CSV files, except it might have several headers in one file. like the following, R is one open-source powerful analytics language, I will do one quick demo see how we can use the R to do ad-hoc analysis for IIS logs.
  the IIS log files looks like the following,
image
the comments begin with # and the same for headers.  R has the built-in data importer for CSV file. and it has a lot options as here,
image

FOR IIS log file, we only need to uncomment one header file, this will tell R how to parse the correct Log files and using # as the comment.char. so you may just uncomment the 4th lines above by remove the #Fields: in the line beginning.

image
then open you fav R IDE, I will use RStudio.
load the raw files to one list named IIS. and run names to get the column names, this will make sure it parse the file correctly.
image
then you can run typeof(iis) to get it’s list object, and nrow and ncol to query the record count, and column count.
image

Now, let’s do some basic analysis

Q1: grouping the result by response code,And plot it.
image

Or group by request,
image

Q2: get the top 5 url by request count,
image

Q3: Count all the .css request ,get top 10s
image

Q4: Combine all the logs in one folder, and put all the data together

basedir="F:/inetpub/logs/LogFiles/W3SVC1/"
LoadData=function (filename)
{
  data=read.csv(filename,header=TRUE,comment.char="#",sep=" ");
  data
}

data=data.frame();

files=list.files(basedir,pattern="*.log")
for(i in 1:length(files))
{
  temp= LoadData(paste(basedir,files[i],sep=""));
  print(nrow(temp));
  data=rbind(data,temp)
}
nrow(data)


Q5: Get the number of request distribution by client, ( identity who request the more)

reqbyiptop10= head(sort(table(iis$c.ip),decreasing=TRUE),10)

ba=barplot(reqbyiptop10,col=rainbow(length(reqbyiptop10)),ylim=c(0,max(reqbyiptop10)*1.2),ylab="req Count")
text(ba,reqbyiptop10,reqbyiptop10,pos=3)


get something like this,
image

 
Locations of visitors to this page