Wednesday, February 18, 2015

Javascript Resources

As a helper and a place resources associated with Javascript I have compiled a list of youtube videos which you should find useful.

Please try and take some time to watch these (in your own time :( ).


Basic Introduction to Best Practices:


Firstly Typescript:



O'Reilly



A useful introduction to deferred and promises:

Thursday, October 21, 2010

 private static T FindItem(IEnumerable list, Predicate findDelegate) where T: AbstractEntityItem
        {
            foreach (T item in list)
                if (findDelegate(item))
                    return item;
            return null;
        }

Thursday, October 07, 2010

Not .NET at All but VB6

Memory Leaks

This is very useful
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=28bd5941-c458-46f1-b24d-f60151d875a3&displaylang=en

I usually set up the debug diagnostics tool to start ~200Mb and every 15Mb thereafter after 4 or 5 dumps start the analysis.

And this which is a less sophisticated tool but helpful nevertheless:
http://mcfunley.com/277/using-leakdiag-to-debug-unmanaged-memory-leaks/comment-page-1

http://www.codeproject.com/KB/cpp/Tools.aspx

Wednesday, March 25, 2009

IE6 and GET /none HTTP/1.1

If you are using a script to get transparent pngs to work on IE6 there may be a flaw in your script.

Go here for a test and use fiddler to check for requests for none

:png problem for ie6

Here is the fix

</style>

<!--[if IE 6]>

<style>

img {

behavior: expression(

this.pngSet?

this.pngSet=true :

(this.nodeName == "IMG" ?

(this.src.toLowerCase().indexOf('.png')>-1 ?

(this.runtimeStyle.backgroundImage = "none", 
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" 
+ this.src + "', sizingMethod='image')",

this.src = "blank.gif") :

'') :         

(this.currentStyle.backgroundImage.toLowerCase().indexOf('.png')>-1) ?

(this.origBg = (this.origBg) ?

this.origBg :            

this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),

this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
 + this.origBg + 
"', sizingMethod='crop')",

this.runtimeStyle.backgroundImage = "none") :

''

), this.pngSet=true

);

}

</style>

<![endif]-->

Friday, July 04, 2008

What is the ASPNETDB for?

Registering the aspnet database

  1. Open a Visual Studio Command Prompt
  2. Type aspnet_regsql and press [Enter]
  3. Follow the steps in the wizard

Here's a simple guide to the aspnet_regsql command:
syntax: aspnet_regsql

:

  • Use -S to install to the aspnetdb on the server specified by
  • Use -sqlexportonly to generate a sql script
  • Add -E to log in to SQL using windows authentication, or -U -P to use a specific login and password.

:

  • * -A with one of the following: all, m, r, p, c, w
  • all: add all features
  • m: membership
  • r: roles
  • p: profiles
  • c: personalization (web parts)
  • w: web events
  • -ssadd -sstype and one of the following (for session-state persistence):
  • p: creates the ASPState database
  • c -d : creates ASPState tables in the specified

Thursday, February 07, 2008

Scripts, Extensions and XSLT

XSLT is about processing XML in which data is stored as text. It'd be really useful to be able to use regular expressions within the XSLT to process this text. We could reformat date strings, for example. XSLT 2 supports regular expressions natively, but unfortunately .NET 2.0 does not seem to support this. This caused me to investigate ways of incorporating scripting into XSLT with .NET. I've found 2:


1) The first way is to embed a script within the XSL document within msxsl:script tags.

You add the msxsl namespace reference to the stylesheet declaration (xmlns:msxsl="urn:schemas-microsoft-com:xslt") and provide a custom namespace prefix for your scripts (e.g. xmlns:MyScripts="urn:MyNamespace").

i.e. -


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:MyScripts="urn:MyNamespace">


Then you declare your script somewhere after this, setting the "implements-prefix" attribute to the custom namespace prefix you declared previously:

e.g.

<msxsl:script language="C#" implements-prefix="MyScripts">
<![CDATA[
public string UpperCase(string input){
// do something with input
return input.ToUpper();
}
]]>
</msxsl:script>


You can then use this script within your XSLT.

e.g.

<xsl:value-of select='MyScripts:UpperCase(@thing)'>


However, when load the xslt into the XsltCompiledTransform, you must pass in an XsltSettings object with the "EnableScript" property set to true, else it'll complain at runtime.


2) The second way involves making a class in your .NET language of choice (mine being C#) and defining the script function there.

e.g.


public class XsltScripts
{
public String UpperCase(String input)
{
return input.ToUpper();
}
}


You then declare a custom namespace and prefix for your scripts as before, and pass in an XsltArgument object that contains a reference to your C# object and the namespace when you call the transform.

e.g.

XsltArgumentList args = new XsltArgumentList();
args.AddExtensionObject("urn:MyNamespace", new XsltScripts());

xslt.Transform(..., _xsltArgs, ...);


You can then reference the code from the XSLT exactly the same way as we did with the previous embedded script method.

e.g.

<xsl:value-of select='MyScripts:UpperCase(@thing)'>


Of course, your code can do much more useful stuff, like using regular expressions on the input string.

Wednesday, January 30, 2008

Things that are silly in .NET

Collections:


List defines a "Find" method that takes a delegate - IList does not.
This could be defined by IEnumerable basically providing you with a arbitrarily filterable enumerable thingy.

List defines "AddRange" method - IList does not. This could be defined at the ICollection level, and allow you to add any enumerable to the collection.

These problems restrict the usefulness of the collections when they are declared by their interface and encourage the developer to return the concrete type and not the interface.
Bad for several reasons.

I've made a generic static finder method that provides the same functionality as List.Find, List.FindAll and so on, but has the added bonus of being able to search anything that is enumerable. Generic and typesafe.

Example of syntax:
IList<string> myList = new List<string>();
myList.Add("Hello?");
myList.Add("Goodbye!");
myList.Add("Error!");

ICollection<string> items = CollectionSearcher.FindAll(
myList, delegate(string s)
{ return s.EndsWith("!"); });
"items" would contain 2 strings - "Goodbye!" and "Error!".

Wouldn't this have been better in the base library?

XML Serialisation:


Does not support nullable types (Nullable) and provides only cumbersome support for the concept of null primitives by other means - for each property "e.g. 'PropX'", you must supply a second 'magic' boolean property that states if the property has been set (e.g. 'PropXSpecified'). This makes dumb BOs bigger and messier than they need to be and means that you have to check two properties to get a value. Rubbish. I know the Nullable support was added to .net 2.0 after serialisation was added, but it can't take much work to fix it. In fact, I've had to make my own ISerializable implementation that supports nullables so I don't have the property specified nonsense all over the place.

Does not support serialisation / deserialisation of properties that are declared as returning a collection interface (e.g. IList). Again, encourages the developer to return the concrete type and not the interface.

Has no way of supporting Abstract / Interface types. For example, you cannot serialise / deserialise something which is defined as extending / implementing a non-concrete type. Bad for flexibility - BOs must reference specifically about all concrete types they can hold.


Reflection:


Not at all obvious how you get the name of an Attribute from an AttributeInfo object that you have found by reflecting an assembly.

e.g.

IList<CustomAttributeData> attrs =
CustomAttributeData.GetCustomAttributes(
Assembly.ReflectionOnlyLoad(assemblyName.FullName));

foreach (CustomAttributeData data in attrs)
{
if (data.Constructor.DeclaringType.FullName == typeof(XXXAttribute).FullName)
{
// We've found an assembly with the attribute we're interested in
}
}

Wouldn't it make sense to be able to get the type directly from the CustomAttributeData?
(e.g. via a property 'Type data.AttributeType')