March 1st, 2010 by Sameer | No Comments | Filed in Uncategorized
I came across this excellent looking tool Flesk ViewState Optimizer but was not able to find any details or documentation on it. Apparently the tool used to be commercial but now its free! I was able to dig up some history on it
Flesk.ViewStateOptimizer is a unique technology that overrides sending ViewState object to your client’s browser! This means that your client’s browser will no longer receive those large hidden field values, which thus reducing downloading time. Instead, Flesk.ViewStateOptimizer saves the page’s Viewstate hidden field to a file, on the server side, speeding up processing time, downloading time and data.
Combining Flesk.ViewStateOptimizer and Flesk.Accelerator,
you can benefit from reducing downloading data and downloading time up to 30 times faster! No other components
do the same or give the same results!
Flesk.Accelerator and Flesk.ViewStateOptimizer are now released with versions
targeted for the .NET Framework v2.0
How it works?
Flesk.ViewStateOptimizer has several viewstate optimization possibilities that can be set through the web.config file.
From viewstate data compression to saving viewstate on server farms, anything can be possible. This means that Flesk.ViewStateOptimizer can persist values using server side Sessions or files saved on shared locaton accessible by a server farm, or by using common viewstate hidden field value on client side, with the ability to compress data.
There are 2 ways to setup Flesk.ViewStateOptimizer on your web application or .Net project:
- In all your codebehind, instead of inheriting your class with
System.Web.UI.Page, change the inheritance to Flesk.Accelerator.Page.
If you use script block codebehind, use the following lines:
<%@ Page Language="C#" Inherits="Flesk.Accelerator.Page" %>
-
Flesk.ViewStateOptimizer is designed to meet the requirements of customers that are unable to change
the base class of their pages.
As such, Flesk.ViewStateOptimizer provides static methods that allows calling the viewstate procedures
from within any page class.
If you have access to the source of your base class, just add the following lines to the code:
protected override void SavePageStateToPersistenceMedium(object viewStateBag)
{
Flesk.Accelerator.Page.SavePageStateToPersistenceMedium(this, viewStateBag);
}
protected override object LoadPageStateFromPersistenceMedium()
{
return Flesk.Accelerator.Page.LoadPageStateFromPersistenceMedium(this);
}
If you are using precompiled code you’ll have to edit your aspx files. If at all possible, add the following
snippet to your aspx file:
protected override PageStatePersister PageStatePersister
{
get
{
return Flesk.Accelerator.Page.GetPageStatePersister(this);
}
}
Flesk.ViewStateOptimizer can use different storage methods:
Other parameters are:
- depending on the storage method setting, Flesk.ViewStateOptimizer can be set to compress viewstate value,
so that it can be significantly smaller than the original value
- the request behaviour of viewstate can be set to be generated on the first request to a page and then
reused in the following postbacks, or to be generated on each request to a page.
A common scenario where viewstate set to be generated on each request can be usefull is in Content Management
frameworks:
page loads up some controls on postback based on some state stored in hidden input values, handles events
and as a result of those actions purges the control collection and loads new controls.
Standard Flesk.ViewStateOptimizer configuration persists the Viewstate using the same GUID as the original
page.
If the user then hit’s refresh (F5) in the browser, the data is posted again, the framework loads up it’s
controls based on the original state but the viewstate value now matches the new controls. This also happens
with any change to the viewstate between postbacks, when users back up or use refresh in their browsers.
The solution was to make Flesk.ViewStateOptimizer generate GUID’s each and every time the viewstate is persisted.
Only then is the viewstate truly unique for each page.
Features
V1.0
- Reduces downloading time of your website or web application, by not sending back the page’s Viewstate
hidden field.
- This component is setup individually. It is not shared by all the webserver’s websites, but only by
your website or webapplication. This means that you can install it in your hosting account without changing
any webserver’s configuration.
- Runs on .NET Framework v1.1 and v2.0. No configuration required. Only a few lines on your web.config
file is all you need to change.
- Greatly reduces bandwidth traffic from your webserver, reduces Posted data from your client’s browser,
and speeds up your web application!
Supported by WebFarms
V1.2
- Compresses the ViewState value. This means that ViewState is sent and returned to/from client’s browser
or saved into local file, on server, compressed, thus reducing ViewState’s value length and increasing
speed even more!
- This release of the Viewstate Optimizer is designed to meet the requirements of
customers that are unable to change the base class of their pages.
- The Flesk.Accelerator.Page class now provides two static methods that allow calling the viewstate
procedures from within any page class.
- ViewState files can now be persisted on shared location accessible by all servers in a server farm.
From Archive.Org
Not sure what happened to the company but glad they decided to give their product for free now! (GPL license)
February 11th, 2010 by Sameer | No Comments | Filed in Hosting
i want to recursively unzip into proper folder
so i have
/home/abdullah/quran1/files.zip
/home/abdullah/quran2/files.zip
…
/home/abdullah/quranfolder/files.zip
i simply want to unzip all of them at once, here is the shell script to do it in linux:
find -maxdepth 1 -mindepth 1 -type d | while read line; do unzip $line/*.zip -d $line ; done
This way is problematic if any of the folders have spaces in them
this way is better
for dir in */
do
( cd "$dir" &amp;amp;&amp;amp; unzip *.zip )
done
Ref: http://unix.derkeiler.com/Newsgroups/comp.unix.misc/2005-03/0006.html
Here is an application of method 1 above, delete all files with 2008 in the name
find -name *2008* | while read line; do rm -f $line ; done
January 11th, 2010 by Sameer | No Comments | Filed in SQL
Its been a while since I have posted, and I thought this was too amazing to NOT share
Apparently, using Check Constraints and adding Foreign Keys not only improves the quality of your database through ensuring referential integrity and data integrity in general, apparently it also helps the Query Analyzer design better plans!
Take a look at this post:
- 13 Things you should know about statistics and the query optimizer, jump to Point 9.
- Also, incase you are wondering what he means by “trusted constraint” and “non trusted constraints”, it would be ‘non trusted’ if you allowed existing non-complying data in the table to stay in there. More here on trusted constraints.
August 7th, 2009 by Sameer | No Comments | Filed in Uncategorized
August 7th, 2009 by Sameer | 4 Comments | Filed in Uncategorized
If you read Creating SqlParameters Best Practices you will find the fun you have if you have null values:
SqlParameter[] sqlParams = new SqlParameter[] {
new SqlParameter("@Required", required),
questionCode == null ? new SqlParameter("@Code", DBNull.Value) : new SqlParameter("@Code", questionCode)
};
Here is a nice helper function to deal with nulls without having to manually check every time.
/// <summary>
/// Return a SqlParameter with DBNull value or value
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static SqlParameter NullWrapper(string key, object value)
{
if (value == null)
return new SqlParameter(key, DBNull.Value);
else
return new SqlParameter(key, value);
}
Then you can use it as follows
SqlParameter[] sqlParams = new SqlParameter[] {
new SqlParameter("@UserID", userId),
new SqlParameter("@itemNo", itemNo),
General.NullWrapper("@expiryDate", expiryDate) //no need to check if null any more
};
July 1st, 2009 by Sameer | No Comments | Filed in Hosting
Have you ever tried to do a recursive linux search for a text string inside a particular file? For example
grep -r "mail" *.php
and then it fails because the current folder doesn’t have any php files in it?
Here is how you can achieve a search inside all .htaccess files for the text php_flag
find -iname .htaccess | while read line; do grep --with-filename "php_flag.*" $line; done
This below line will search all .PHP files for a common hack script
find -iname *.php | while read line; do grep --with-filename "eval (base64_decode('aWYoIWlzc2V0KCR" $line; done
If that gives you too much output, here is a search that will only display the filenames
find . -name "*.php" | while read line; do grep --files-with-matches --with-filename "base64_decode('aWYoIWlzc2V0KCR" $line; done
Tags: grep, linux
June 13th, 2009 by Sameer | No Comments | Filed in Hosting
Here is a cool way to delete files according to some complex rules without knowing complicated bash commands.
First, create a file as follows that contains your deletion rules.
+ public_html/
+ public_html/*
- access-logs
- etc/
- logs/
- mail/
- .cpanel/
- .cpaddons/
- .spamassassin/
- .ssh/
- public_ftp/
- cpmove.psql/
- tmp/
- cpeasyapache/
- MySQL-install/
Then, run rsync with the source and destination folder being the same
rsync -avz --include-from:rulesFile.txt . . --delete-excluded
You can add –dry-run if you want to see what will be deleted:
rsync -avz --include-from:rulesFile.txt . . --delete-excluded --dry-run
Tags: linux
May 27th, 2009 by Sameer | No Comments | Filed in Uncategorized
Here is a list of new features in ASP.NET 4.0.
Very interesting. Auto start feature, new ways to choose where data is cached, built in option for compression session (via gzip), and more!
April 9th, 2009 by Sameer | No Comments | Filed in .NET articles
LINQ to Entities seems really great. It can save you a lot of time in writing unnecessary db connection code, improve the performance many fold, only connect to the db when required (lazy loading), and easy concurrency handling for you.
However there is a missing feature which I found out the hard way. If you try to do a ‘Create Function Import’ and it returns a scalar, the code will not be automatically generated, due to ‘lack of time’ from the MS Team:
MSDN Forums – See the post by Noam.
So basically, you are handicapped! Either write the code yourself or just do it the old fashioned way
April 2nd, 2009 by Sameer | No Comments | Filed in Uncategorized
Wow, sweet. Use .NET 3.5 features in .NET 2.0.
A quick overview how to do it.
1. Edit your .CSPROJ file and manually add another reference to System.Core
Add a True
This will make the compiler copy it to the BIN folder.
Thats it. You can now use .NET 3.5 features