Wednesday, February 27, 2013

Visual studio locking files on build

More and more I got a problem with visual studio blocking files on build, (Could not copy dll from debug to bin) mostly in web projects (MVC).
A solution was to clean the solution (getting the same error),
waiting a few seconds, cleaning again,
and then building.
Now I found a solution that seems to work,
right click the project,
properties,
Build steps,
and add to the pre build command line :
if exist "$(TargetPath).locked" del "$(TargetPath).locked" if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

(You need to copy the double quotes too).
It might be needed to add this to more than one project in your solution, just look at the error you get when building.

Wednesday, October 13, 2010

Some handy Javascript array methods

Working with javascript arrays today, I found some handy functions:

- Creating an array :
var ray = [];

- Joining two arrays :
var resultArray = ArrayOne.concat(ArrayTwo);

- Getting only unique items in an array :
(Jquery has a unique function, but it does not work on strings / numbers)
Array.prototype.unique = function() {
var result = new Array();
o: for (var i = 0, n = this.length; i < n; i++) {
for (var x = 0, y = result.length; x < y; x++) {
if (result[x] == this[i]) {
continue o;
}
}
result[result.length] = this[i];
}
return r;
}


- For each in JavaScript(using JQuery):
(although JavaScript has for (item in collection) functionality, it is not useful as it also iterates through the methods of the object.)
$.each(collection, function(index, value) { alert(index + ' : ' + value); });




- Bonus JavaScript : Splitting a string by multiple delimiters :
use a regular expression :
var result = myString.split(/[DELIMITERS]+/);
just replace DELIMITERS with the delimiters you want (one character delimiters)

Thursday, October 8, 2009

IE 6 not showing borders

We had a site that did not show the borders around a div in IE6,
After a while (and using google) I found out that I only needed to add
position: relative; on the element or its ancestors (only that element and descendants are fixed)

I found it Here.

Tuesday, October 6, 2009

Good old VB functions in c# Left, Mid, Right

Missing the good old string functions in c# I wanted to recreate them.
This is my solution where they are resurrected as extension methods.


public static class StringHelper
{
    public static string Right(this String source, int length)
    {
        if (source.Length == 0 || length <= 0)
        {
        return "";
        }

        return source.Substring(source.Length - length, length);
    }

    public static string Left(this String source, int length)
    {
        if (source.Length == 0 || length <= 0)
        {
        return "";
        }

        return source.Substring(0, length);
    }

    public static string Mid(this string source, int startIndex, int length)
    {
        if (source.Length == 0 || length <= 0 || startIndex < 0)
        {
        return "";
        }
        return source.Substring(startIndex, length);
    }

    public static string Mid(this string source, int startIndex)
    {
        if (source.Length == 0 || startIndex < 0)
        {
        return "";
        }
        return source.Substring(startIndex);
    }
}


To keep the code from giving errors I check for the length parameter,
if this is not what you want, you can throw an argumentexception for example ...

Thursday, July 2, 2009

Javascipt Replace, Replace All

Working in javascript today,
I found out that in javascript, the replace function only replaces the first occurrence, not all as in c#/VB.
You can test this by pasting the following in the addressbar of (most) browsers:

javascript:alert('test-test-test'.replace('-',''));

To replace all occurrences you need to use regular expression (place the word you want to find between / /g :

javascript:alert('test-test-test'.replace(/-/g,''));


or you can create a javascript function eg:

function replaceAll(text, findText, replaceText)
{
return text.replace( new RegExp(findText,"g"), replaceText);
}

Friday, March 6, 2009

Portable Browsers

Are you a webdeveloper,
or do you need to run some sites in a specific version of Internet Explorer (or Firefox or ... )

Or do you just want to try a new browser version without installing it?

Earlier I put up an article about IETester which allows you to run Internet Explorer 6 (and others) on Vista.
Now I found a new (and better) way to run different browsers without the need for installation :


http://www.xenocode.com/browsers/

Currently they have the following browsers :
- Internet Explorer 8, 7, 6
- Firefox 3, 2
- Google Chrome
- Opera
- Safari

From the site :
Xenocode WebApps do not require any software to be installed and allow multiple application versions to run side-by-side on any version of Windows.


So they should run on any version of windows (not yet tested, only on vista).

Have fun!
It works fine here, and I have

Wednesday, February 25, 2009

Menu Selection Gets Stuck on Screen

At work,

when I chose an item in a right click menu it stuck on screen,
It dissappeared when I locked and then unlocked the pc,
but reappeared the next time I selected an item. This does not work in windows 7 (and maybe 8), the quick workaround there is Start > Run :
tskill dwm

Right clicking the desktop and closing the menu also helped, but this were only workarounds.

I finally solved it :
Go into Windows Performance Options and de-select the option for "Fade out menu items after clicking."

In Vista, you can find it by right clicking My Computer > Properties > Advanced system settings (link on the left) > Advanced (tab) > Performance settings (button) > Visual effects (tab).

To cure it one in windows 7 you can set the corresponding monitor from 32 bit to 16 bit and back again, to remove one item. If it keeps happening, use the above solution.