0

New Domain Name

Posted by Sameer on May 14, 2012 in Uncategorized |

I have decided to buy a new domain name – agilechai.com. I think its a pretty cool name

0

Allow Visual Studio to use more memory in 32bit windows

Posted by Sameer on January 21, 2011 in Uncategorized |

Read this excellent guide on increasing the total memory Visual Studio can use, even in 32bit windows

0

No source avaiable (VS2010)

Posted by Sameer on January 10, 2011 in .NET articles |

Did you ever try pausing your code in VS2010? Did you get this very annoying screen that says “no source available” ?

The solution is simple, install this extension

0

Modifying open source code to overcome inbuilt limits

Posted by Sameer on January 6, 2011 in Linux |

This article applies to not just this particular piece of code but rather any open source tool you use. It may be possible for you to simply edit the source code and use it modified. Thats the beauty of open source!

I downloaded this tool SHNTool to use to try to split some lossless audio files that we are publishing on flawlessquran.com. The sad thing is, it has a file limit of 256 files, however I needed 286 files to be split at once.

Believe it or not, all I had to do is download the source for for SHNTool and then edit src/mode_split.c and change the definition of SPLIT_MAX_PIECES from
#define SPLIT_MAX_PIECES 256
to
#define SPLIT_MAX_PIECES 300

Then obviously I rebuilt it (using ./configure followed by make followed by make install)
and it worked!!

Splitting [002.flac] (198:33.36) –> [vbv/002248.flac] (1:20.18) : 100% OK
Splitting [002.flac] (198:33.36) –> [vbv/002249.flac] (1:03.49) : 100% OK
Splitting [002.flac] (198:33.36) –> [vbv/002250.flac] (2:20.72) : 100% OK
Splitting [002.flac] (198:33.36) –> [vbv/002251.flac] (0:31.64) : 100% OK
Splitting [002.flac] (198:33.36) –> [vbv/002252.flac] (0:53.67) : 100% OK
Splitting [002.flac] (198:33.36) –> [vbv/002253.flac] (0:20.66) : 100% OK
Splitting [002.flac] (198:33.36) –> [vbv/002254.flac] (1:42.21) : 100% OK
Splitting [002.flac] (198:33.36) –> [vbv/002255.flac] (0:28.39) : 100% OK

No more “shnsplit: error: too many split files would be created — maximum is 256″

I posted this incase someone else is running into the same problem the solution is quite easy!

and this worked!
It seems that the developers simply put an arbitrary limit of 256.

1

Jquery Rich Array Documentation

Posted by Sameer on April 30, 2010 in .NET articles |

If you want to use the JQuery Rich Array and you were hoping for some documentation, well its inside the .JS file but I am posting it here for reference purposes

/***************************************************************************
 *   Copyright (C) 2007 by Vladimir Kadalashvili                                        *
 *   Vladimir.Kadalashvili@gmail.com                                                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

/*
A simple jQuery plugin for varios manipulations with arrays
*/ 

jQuery.richArray = {

    /*
        Checks whether an array contains some value
	@param {Array} array - an array in which we search for a value
	@param {Mixed} value - the value we search for
	@return {boolean} true if the array contains the value, otherwise false
    */

    in: function(array, value) {
    },

    /*
        Produces the duplicate-free version of the array
	@param {Array} array
	@returns {array}  - an array without duplicates
    */
    unique: function(array) {

    },

    /*
        Finds the difference between two arrays.
	@param {Array} array1
	@param {Array} array2
	@return {Array} array of values which are present in the first array, but not in the second
    */

    diff: function(array1, array2) {

    },

    /*
        Finds the intersection of two arrays
	@param {Array} array1
	@param {Array} array2
	@return {Array} - the array of values wich are present in both arrays
    */

    intersect: function(array1, array2) {

    },

    /*
        Applies filter to the array, using callback function
	@param {Array} array - an array which we apply filter to
	@param {Function} fn - the filter function. If it returns the value that may be evaluated as TRUE, the value will be included to the returned array.
	@param {Object} scope - the scope of the callback function. Default is jQuery.richArray
	@returns {Array} - an array of values for which callback function returned true
    */

    filter: function(array, fn, scope) {

    },

    /*
        Applies callback function for each element in the input array, and returns array of values that this function returned
	@param {Array} array - an array which we should apply callback to
	@param {Function} fn - callback function
	@param scope - the scope of the callback function. Default is jQuery.richArray
    */
    map: function(array, fn, scope) {
    },

    /*
        Computes the sum of all array elements.
	@param {Array} array - an array we should compute the sum for
	@param {Mixed} init - the initial value of the sum. Default is 0.
	@returns {Mixed} the sum of all elements of the input array
    */

    sum: function(array, init) {
    },

    /*
        Calculates the production of all elements of the array
	@param array - an array we should compute production for
	@param init - the initial value. Default is 1.
	@returns {Mixed} - the production of all elements of the input array
    */

    product: function(array, init) {
    },

    /*
        Reduces the array. One-elemen arrays are turned into their unique element, others are retured untouched
	Examples:
	jQuery.richArray.reduce([3]) -> 3
	jQuery.richArray.reduce([3, 5]) -> [3, 5]
    */

    reduce: function(array) {
    },

    /*
        Creates new version of array without null/undefined values
	@param {Array} array - input array
	@returns {Array} - an array without null/undefined values
    */

    compact: function(array) {
    },

    /*
       Creates a new version of the array that doesn't contain the specified value
       @patam {Array} array - input array
       @param {Mixed} value - the value that shouldn't be included to the returned array
       @returns {Array} - a new version of the input array without specified value
    */

    without: function(array, value) {
    },

    /*
        If the passed argument is an array, returns it untouched, otherwise returns an empty array.
	For internal use.
    */

    getArray: function(array) {
    },

    /*
        if the passed argument is a function, returns it untouched, otherwise returns an empty function
   */

    getFunction: function(fn) {
        if (!(fn instanceof Function)) fn = new Function();
	return fn;
    }    

};

Homepage: Jquery Rich Array Plugin

3

Serialize and Deserialize to JSON from ASP.NET

Posted by Sameer on April 23, 2010 in .NET articles |

Its very easy to serialize an object to .NET
Simply create some object, normally a custom class with some attributes.
Normally you have a list of these and you want to serialize to JSON to use it from client side code.

If you do the following

var s = new System.Web.Script.Serialization.JavaScriptSerializer();
string resultJs = s.Serialize(result);

you will end up with a JSON array that you were looking for:

[
  { "Desc" : "Corn 100 ",
    "ItemNo" : "123456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.21
  } ,
  { "Desc" : "Ice 100 ",
    "ItemNo" : "323456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.50
  } ,
  { "Desc" : "Meat 100 ",
    "ItemNo" : "423456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.11
  } 

]

However if you try to deserialize this back into an object by running

var json = new System.Web.Script.Serialization.JavaScriptSerializer();
var result = json.Deserialize<ShoppingCartItem[]>(jsonItemArray);
    

You will get a NULL type Exception.

The solution is to create a simple resolver as follows

    using System;
    using System.Web;
    using System.Web.Compilation;
    using System.Web.Script.Serialization;

    namespace XYZ.Util
    {
        /// <summary>
        /// as __type is missing ,we need to add this
        /// </summary>
        public class ManualResolver : SimpleTypeResolver
        {
            public ManualResolver() { }
            public override Type ResolveType(string id)
            {
                return System.Web.Compilation.BuildManager.GetType(id, false);
            }
        }
    }
    

2) Use it to serialize

    var s = new System.Web.Script.Serialization.JavaScriptSerializer(new XYZ.Util.ManualResolver());
    string resultJs = s.Serialize(result);
    lblJs.Text = string.Format("<script>var resultObj = {0};</script>", resultJs);
    

You will get something like the following this time (note new __type included this time)

[
  {
    "__type":"XYZ.Data.Entities.ShoppingCartItem, XYZ.Data, Version=1.7.1.0, Culture=neutral, PublicKeyToken=null",
    "Desc" : "Corn 100 ",
    "ItemNo" : "123456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.21
  } ,
  {
    "__type":"XYZ.Data.Entities.ShoppingCartItem, XYZ.Data, Version=1.7.1.0, Culture=neutral, PublicKeyToken=null",
    "Desc" : "Ice 100 ",
    "ItemNo" : "323456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.50
  } ,
  {
    "__type":"XYZ.Data.Entities.ShoppingCartItem, XYZ.Data, Version=1.7.1.0, Culture=neutral, PublicKeyToken=null",
    "Desc" : "Meat 100 ",
    "ItemNo" : "423456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.11
  } 

]

3) Use it to deserialize

    System.Web.Script.Serialization.JavaScriptSerializer(new XYZ.Util.ManualResolver());
    var result = json.Deserialize<ShoppingCartItem[]>(jsonItemArray);
    

References: Comment by Manuel Abadia on ASP.NET AJAX Extensions Internals – Web Service Proxy Generation

0

How to completely disable ViewState and ControlState

Posted by Sameer on April 21, 2010 in Uncategorized |

Here is a code snippet that will COMPLETELY disable ViewState and ControlState.

Please note, if you want to disable viewstate, you can set “EnableViewState” to false for the page, however you will still see “VIEWSTATE” in the page. The reason for that is because the hidden ViewState HTML field also contains “Control State”, which is used by server controls (either built in controls or custom 3rd party controls) and is not disable-able (for core functionality that their control depends on).

However you can still disable this, with disastrous consequences on postback.

USE THIS only if you have NO POSTBACKS whatsoever and you are living in a happy client side world of javascript and web service calls.

Put this following code inside your ASP.NET page

private class DummyPageStatePersister  :P ageStatePersister
{
    public DummyPageStatePersister(Page p) : base(p) { }
    public override void Load() { }
    public override void Save() { }
}

private DummyPageStatePersister _PageStatePersister;
protected override PageStatePersister PageStatePersister
{
    get
    {
        if (_PageStatePersister == null)
            _PageStatePersister = new DummyPageStatePersister(this);
        return _PageStatePersister;
    }
}

Please note this will has disastrous consequences if you attempt to do a postback because you have essentially killed the control state.

7

Flesk Viewstate Optimizer Documentation

Posted by Sameer on March 1, 2010 in .NET articles |

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:

  1. 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:

    &lt;%@ Page  Language=&quot;C#&quot; Inherits=&quot;Flesk.Accelerator.Page&quot; %&gt;
    
  2. 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:

  • save to file (saves ViewState into a file, server side)
  • Session (saves ViewState into a Session variable, server side)

  • Default (default ViewState saving method, sends hidden fields to client side)

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)

Edit Aug 12, 2010

Web.Config Requirements

To use this, here is what you put in Web.Config between <configuration> and </configuration>

  &lt;Flesk.NET&gt;
    &lt;!--
		The StorageMethod parameter sets the ViewState's storage type.
		Possible values are :

			- File (saves ViewState into a file, server side)
				- StoragePath must specify a write enabled server path ( ~ means site root path)
					If StoragePath is a web path (i.e.: \\MachineName\Dir), when used in webfarms,
					please add the following line under &lt;system.web&gt;
					&lt;identity impersonate=&quot;true&quot; userName=&quot;domain\username&quot; password=&quot;userpass&quot;/&gt;

			- Default (default ViewState saving method, sending hidden fields to client side)

			- Session (saves ViewState into a Session variable, server side)

			- SqlServer (saves the ViewState into a database table)
				- ConnectionString specifies the database connection.
				- TableName specifies the table in the database where the records will be stored.

		New Option :
			Compressed=&quot;true&quot; or Compressed=&quot;false&quot;
			this will compress the ViewState if StorageMethod is Default or File.
			so the ViewState's value will be significantly smaller than the original value.
			Compression method is not suported by StorageMethod=&quot;Session&quot;

		--&gt;
    &lt;ViewStateOptimizer
			PersistenceHandler=&quot;Flesk.Accelerator.SessionViewstatePersister, Flesk.Accelerator&quot;
			StorageMethod=&quot;SqlServer&quot;
			StoragePath=&quot;~/Files/Logs&quot;
			ConnectionString=&quot;Server=...;Database=...;Uid=...;Pwd=...
			TableName=&quot;app_ViewState&quot;
			Compressed=&quot;false&quot;
			RequestBehavior=&quot;EachLoad&quot;
			ViewStateCleanupInterval=&quot;01:00:00&quot;
			/&gt;
  &lt;/Flesk.NET&gt;

Between <configSections> and </configSections> put the following:

    &lt;sectionGroup name=&quot;Flesk.NET&quot;&gt;
      &lt;section name=&quot;ViewStateOptimizer&quot; type=&quot;Flesk.Accelerator.Viewstate.ConfigHandler, Flesk.ViewState&quot; /&gt;
    &lt;/sectionGroup&gt;

Between <httpModules> and </httpModules> you can put

			&lt;!--
			This HttpModule provides automatic cleanup of viewstate files
			on the start of each session, thus requiring
			the SessionStateModule to be installed as well.
		  --&gt;
			&lt;add name=&quot;ViewstateCleanupModule&quot; type=&quot;Flesk.Accelerator.Viewstate.CleanupModule, Flesk.ViewState&quot;/&gt;
		&lt;/httpModules&gt;

0

Recursively extract files

Posted by Sameer on February 11, 2010 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

best way to search inside php files for text yoursearchtexthere

find . -name '*.php' -exec grep --with-filename --line-number 'yoursearchtexthere' {} \;

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 &quot;$dir&quot; &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

0

Improve SQL Server Plan Execution Speed With Foreign Keys and constraints

Posted by Sameer on January 11, 2010 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.

Copyright © 2007-2012 SharpDeveloper now AgileChai All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.0.2, from BuyNowShop.com.