programming

Bash : Compound condition using && (AND) and || (OR) operators

To have compound conditions in bash using && or ||:-
if [ $VAR1 -eq 1 ] && [ "$VAR2" == "true" ]
then
    # do something
fi
 
if [ "$VAR1" == "String 1" ] || [ "$VAR2" == "String 2" ]
then
    # do something
fi

Reference: http://www.museum.state.il.us/ismdepts/library/linuxguides/abs-guide/ops.html#ANDOR

Bash : Compare Strings With Spaces

To compare two strings that contain spaces in bash, enclose them with a double quote (e.g.  "$VAR" ). Example below:-

if [ "$VAR" == "this is a string with spaces" ]
then
    # do something
fi

Reference: http://hacktux.com/bash/string

Configure multiple log4j instances in different contexts

The problem:
We needed to use different log4j.properties file for each context.

We have one library (directory.jar) which resides in tomcat's shared lib that uses log4j. We also have three contexts (core, admin & user contexts) that will be using log4j for logging too.

Initially, we put the log4j library in tomcat's shared lib, and specify log4j.properties for each context's web.xml. But we found out that only one context is able to initialize the log4j properly. The other two contexts doesn't seem to be able to use log4j properly.

ASP.NET Client-side Validation & Confirmation Popup

The other day I was working on a project for our client. They wanted some client-side validation to be done on the page to avoid postbacks, since postbacks could take REALLY long on a slow connection. They also wanted a javascript confirmation popup before processing the form.

In the page, I had a few RequiredFieldValidators, as well as some RegularExpressionValidators. Initially, I modified the submit button to include the confirmation message, and check whether the page is valid or not. Below is a snippet of the ASP.NET button that I had in my page.

 

Request Filtering module is configured to deny a request that exceeds request content length

It's been a while since I last wrote on this blog. Been busy with work + real life. Anyway, here's what I encountered a couple of days ago.

We were working on a module that would allow users to upload files to the server (the file is stored in SQL Server as VARBINARY). The maximum allowed file size to be uploaded was made configurable through web.config file. We set those to be 50mb. When we tried to upload a 36mb file, IIS7 gave us this error:

Syndicate content