Thursday, May 30, 2013

Good Website / Links for command line one liners

http://www.quora.com/What-are-the-most-useful-Swiss-army-knife-one-liners-on-Unix?share=1
http://www.commandlinefu.com/commands/browse/sort-by-votes

Monday, May 27, 2013

XSS Filter and Modifying POST data for Spring controller


The Context :

In some cases we have to intercept the request for which we use filter concept in J2EE framework. A typical case is the one where we have to prevent XSS attacks. I was able to take care of the common stuff by implementing httpservletresponsewrapper however there were certain cases where we were posting data in a http post request .



To read this data from the request we can use the following code.

1:  StringBuffer jb = new StringBuffer();  
2:   String line = null;  
3:   try {  
4:    BufferedReader reader = request.getReader();  
5:    while ((line = reader.readLine()) != null)  
6:     jb.append(line);  
7:   } catch (Exception e) { /*report an error*/ }   
Next step is bit complicated as the following  post explains
 
Much thanks to original contributor.
http://www.coderanch.com/t/364591/Servlets/java/read-request-body-filter 
  
My code 
 
All i did was searched and replaced nay script tag using the following regex

private static String scriptStartpattern = "(?i)<\\s*script\\s*>";
private static String scriptEndpattern = "(?i)<\\s*/\\s*script\\s*>";

Saturday, May 4, 2013

Coursera Data science Course

Had to choose a setup for python as the course uses python.
I chose pydev as i am already well aquainted with Eclipse.
I also downloaded and installed Python.
However when i copy pasted a sample code i got some errors for imported oauth module.

as i was totally new to python i had no idea how to install modules . I soon discovered that there are two ways of doing it.

Using the following command
python.exe C:\Downloads\oauth2-1.5.211.tar\oauth2-1.5.211\oauth2-1.5.211\setup.py install

but oauth requires setup tools
for that i had to do the following

ez_setup.py was downloaded from
http://peak.telecommunity.com/dist/ez_setup.py

python.exe C:\ez_setup.py


THe other way is to download the module and specify the path in Eclipse.
In the properties for your pydev project, there's a pane called "PyDev - PYTHONPATH", with a sub-pane called "External Libraries". You can add source folders (any folder that has an __init__.py) to the path using that pane. Your project code will then be able to import modules from those source folders.