Posted by: jango on: December 17, 2009
see it here:
http://code.google.com/p/memcached-session-manager/
Posted by: jango on: December 17, 2009
Now a days it is obvious that most web rely on thirdparty authentication – and use oauth for that – twitter uses that: and here is where you add your application : http://twitter.com/oauth_clients/new
Posted by: jango on: December 17, 2009
Often developers especially whom with python (Django) , ruby (on rails), php, find difficult to get their caching subsystem – memcached [http://memcached.org]- run on windows. Though there hasn’t much work to port memcached to windows it is easy to get it working using colinux [http://www.colinux.org/]
Steps to do
1. Install colinux
2. Download the fedora image – I did with it
3. Enabled networking between the host os and guest os (between windows and linux) see it here [http://colinux.wikia.com/wiki/Network]
4. Download latest memcached to linux – install it – Remember you should have libevent installed prior to it
5. Using any of the apis access the memcached running on the linux from windows – I checked with python api
Update: You can get memcached on windows here : http://labs.northscale.com/memcached-packages/
Happy programming in windows
Posted by: jango on: October 6, 2009
download the latest from http://www.python.org/download/
Unzip it, change to that directory and run ./configure –prefix=< Your custom python install path>
then make,make install
You have new version of python at <Your custom python install path>/bin (ie <Your custom python install path>/bin/python will be the new python) . without disturbing the existing version
Posted by: jango on: August 14, 2009
Create a server key: openssl genrsa -des3 -out server.key.pass 1024
Remove the pass: openssl rsa -in server.key.pass -out server.key
Generate CSR: openssl req -new -key server.key -out server.csr
Posted by: jango on: April 27, 2009
This filter is based on YUI Compressor. So for performance you must use any caching filter. The code is
package com.vinu.web.performance;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import org.mozilla.javascript.ErrorReporter;
import org.mozilla.javascript.EvaluatorException;
import com.yahoo.platform.yui.compressor.CssCompressor;
import com.yahoo.platform.yui.compressor.JavaScriptCompressor;
/**
* @author Vinu Varghese (Email: vinu@x-minds.org) Minifies JS and CSS on the fly, based on the YUI Compressor The minification is a heavy process so use this
* filter along with a caching filter for performance.
*/
public class JsCssMinifyFilter implements Filter
{
private FilterConfig config;
/*
* (non-Javadoc)
*
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
*/
public void init(FilterConfig filterConfig) throws ServletException
{
this.config = filterConfig;
}
/*
* (non-Javadoc)
*
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
HttpServletRequest originalRequest = (HttpServletRequest) request;
HttpServletResponse originalResponse = (HttpServletResponse) response;
// Create the response wrapper
MinifiedResponse minifiedResponse = new MinifiedResponse(originalResponse);
// Continue the chain - get the contents
chain.doFilter(originalRequest, minifiedResponse);
// The data
String data = new String(minifiedResponse.getData());
// Create the reader
StringReader reader = new StringReader(data);
//Create the writer
StringWriter writer = new StringWriter();
String requestURI = originalRequest.getRequestURI();
try
{
//Do JS minification
if (requestURI.endsWith(".js"))
{
minifyJS(reader, writer);
}
// Do Css minification
else if (requestURI.endsWith(".css"))
{
minifyCSS(reader, writer);
}
//Else - we can't do any other minification
else
{
writer.write(data);
}
}
catch (Exception ex)
{
// We do a generic exception handling
//Log error
config.getServletContext().log("Error in minifying : " + requestURI, ex);
// Write the data as it is
writer.write(data);
}
//Write the data to the original response
// Get the data from the writer (Compressed data)
String compressed = writer.toString();
//Set the content length correctly
originalResponse.setContentLength(compressed.length());
//Write the data
originalResponse.getOutputStream().write(compressed.getBytes());
}
/**
* @param reader
* @param writer
* @throws IOException
*/
private void minifyCSS(StringReader reader, StringWriter writer) throws IOException
{
CssCompressor cssCompressor = new CssCompressor(reader);
cssCompressor.compress(writer, -1);
}
/**
* @param reader
* @param writer
*/
private void minifyJS(StringReader reader, StringWriter writer) throws IOException
{
JavaScriptCompressor compressor = new JavaScriptCompressor(reader, new ErrorReporter() {
public void warning(String message, String sourceName, int line, String lineSource, int lineOffset)
{
if (line < 0)
{
System.err.println("\n[WARNING] " + message);
}
else
{
System.err.println("\n[WARNING] " + line + ':' + lineOffset + ':' + message);
}
}
public void error(String message, String sourceName, int line, String lineSource, int lineOffset)
{
if (line < 0)
{
System.err.println("\n[ERROR] " + message);
}
else
{
System.err.println("\n[ERROR] " + line + ':' + lineOffset + ':' + message);
}
}
public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource, int lineOffset)
{
error(message, sourceName, line, lineSource, lineOffset);
return new EvaluatorException(message);
}
});
// Does the compression
compressor.compress(writer, -1, true, false, true, false);
}
/*
* (non-Javadoc)
*
* @see javax.servlet.Filter#destroy()
*/
public void destroy()
{
}
/**
* A response wrapper, the content is saved to the output buffer, the stream returned is ServletOutputStreamWrapper
*
* @author Vinu Varghese (Email: vinu@x-minds.org)
*
*/
class MinifiedResponse extends HttpServletResponseWrapper
{
private ByteArrayOutputStream output = new ByteArrayOutputStream();
/**
* @param response
*/
public MinifiedResponse(HttpServletResponse response)
{
super(response);
}
/*
* (non-Javadoc)
*
* @see javax.servlet.ServletResponseWrapper#getOutputStream()
*/
@Override
public ServletOutputStream getOutputStream() throws IOException
{
return new ServletOutputStreamWrapper(this.output);
}
/*
* (non-Javadoc)
*
* @see javax.servlet.ServletResponseWrapper#getWriter()
*/
@Override
public PrintWriter getWriter() throws IOException
{
PrintWriter localPrintWriter;
try
{
localPrintWriter = new PrintWriter(new OutputStreamWriter(getOutputStream(), "UTF-8"), true);
}
catch (Exception localException)
{
localPrintWriter = new PrintWriter(getOutputStream(), true);
}
return localPrintWriter;
}
/**
* Returns the data
*
* @return
*/
public byte[] getData()
{
try
{
output.flush();
}
catch (IOException e)
{
//ignore
}
return output.toByteArray();
}
}
/**
* Output stream wrapper I have overriden the write method, is that enough?
*
* @author Vinu Varghese (Email: vinu@x-minds.org)
*
*/
class ServletOutputStreamWrapper extends ServletOutputStream
{
private ByteArrayOutputStream output;
/**
*
*/
public ServletOutputStreamWrapper(ByteArrayOutputStream output)
{
this.output = output;
}
/*
* (non-Javadoc)
*
* @see java.io.OutputStream#write(int)
*/
public void write(int b) throws IOException
{
output.write(b);
}
}
}
Posted by: jango on: August 13, 2008
See this link: http://www.agentbob.info/agentbob/79-AB.html
Posted by: jango on: July 29, 2008
Check this: http://java.decompiler.free.fr
A free java decompiler
Posted by: jango on: July 22, 2008
/**
* A simple tar reader
* Just reads through tar file, parses the headers and writes file.
*/
package com.jango.tarreader;
import java.io.IOException;
import java.io.InputStream;
/**
* @author vinu
*
*/
public abstract class AbstractTarReader {
public void read(InputStream in) throws IOException {
while (true) {
Header head = parseHeader(in);
if (head == null)
break;
if (head.isFile && head.filesize > 0) {
int remainder = head.filesize % 512;
int skiplen = 0;
if (remainder != 0)
skiplen = 512 – remainder;
byte[] fileContents = new byte[head.filesize];
in.read(fileContents);
in.skip(skiplen);
createFile(head.filename, fileContents);
} else if (!head.isFile) {
createDir(head.filename);
}
}
}
/**
* Creates the file – dependent on implementation
*
* @param filename
* @param fileContents
* @throws IOException
*/
public abstract void createFile(String filename, byte[] fileContents)
throws IOException;
/**
* Creates the directory as in the tar
*
* @param dirname
*/
public abstract void createDir(String dirname);
// Parses the header
private Header parseHeader(InputStream in) throws IOException {
Header head = new Header();
byte buf[] = new byte[512];
int len = in.read(buf);
// EOF or not fully read
if (len == -1 || len != 512)
return null;
StringBuffer sBufFilename = new StringBuffer();
byte linkIndicator = buf[156];
for (int i = 0; i < 100; i++) {
if (buf[i] != 0) {
sBufFilename.append((char) buf[i]);
}
}
StringBuffer sBufFilesize = new StringBuffer();
for (int i = 124; i < 136; i++) {
sBufFilesize.append((char) buf[i]);
}
head.filename = sBufFilename.toString();
head.filesize = Integer.parseInt(“0″ + sBufFilesize.toString().trim(),8);
if(head.filesize==0 && head.filename.length()==0)
return null;
if ((char) linkIndicator == ‘5′) {
head.isFile = false;
}
return head;
}
// To store the header info – Simple for now
// Only the filename
class Header {
String filename;
int filesize;
boolean isFile = true;
}
}