Technological stupidity

by Svelmoe 4. February 2010 20:11

Time to rant a bit about a "new technological advantage" I saw the other day.

I just got my BluRay player hooked up to the internet, so I can marvel at the genius of all the technologies now available for me.
Sure it is fun to watch YouTube videos on the BluRay/TV without having to hook up a computer - but well, this isn't about that....

I popped in some disc I just bought and there was a notice for some kind of "chat" system.
Interested to see what benefits I could take advantage off now that my player was finally hooked up, I navigated over with my remote.

Well - in essence it was just a basic chat system, which would place a big chat box in the side of the screen and I could then invite my friends to "watch the movie" with me and "chat with them" while doing it ..... all from the comfort of each our own couch.
Now that is stupid enough to begin with - if I want to watch movies with friends, I - you know - visit them, and if we watch movies, I sure as heck would not want a chat box taking up the screen.

But that was not what struck me .... one method of chatting was using the remote and the keys like on phones, but the alternative was using a computer to type on, which of course also needs to be online.
But if you have a computer, hooked up to the internet, and you can use to chat on - why on earth would you then chat via a BluRay movie system?

Isn't that what you would use a - you know - chat software on your computer for? Wouldn't it be much better to just use your usual IM client and chat on the computer, if you have a computer anyway? Seriously - How irrelevant can one technology be.....

(And yes, I understand the irony in me complaining about such technology after hooking my BluRay player up to the net)

 

Google is … censoring?

by Svelmoe 8. January 2010 18:17

I noticed this blog: thenextweb.com: Google Blocking Negative Search Recommendations On Islam – Why? today (a bit late possible).
It tells about how Google possible is censoring search suggestions which could be controversial - in this case towards Islam.

Most everybody knows about Google in China so we know Google does … lets call it fiddle to be neutral ... with the search results in various situations.
However this begs the question - how do we actually know that Google is acting fairly and doesn’t censor or cheat with the search results in ways we cannot know?

Their revenue comes from advertisement and being able to provide a clear picture of what people search for to provide targeted advertisement.
So it would stand to argue that they can’t really afford to suffer doubt about their objectivity and whether or not they alter or effect or even censor search results.
However how would anybody know?

Is Google now so big that it doesn’t matter if they do questionable things? Can … would … people even stop using Google if it was confirmed that they are actively censoring? Is it even possible? Or are Google now so big that they can do what they want, when they want?

One can only speculate but my trust in Google is diminishing as they keep growing bigger and spand more and more features of the web, and with situations like this and China.
I still use their services, however …for now.

Do no evil.

 

Padding is invalid and cannot be removed

by Svelmoe 23. October 2009 15:42

I experienced the following rather unhelpful exception at work today.
Padding is invalid and cannot be removed

With a stacktrace something along the following:

System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast) +7596702
System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) +208
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +33
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo) +225
System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket) +246

After doing some searching and more or less complex debugging, and resetting the application pool and what not, I find the simple solution.

I had two projects running on my localhost which both used the default cookie name for forms authentication, which then apparently conflicted with each other. Do’h.
But well, problem solved.

VisitDenmark, fake youtube video.

by Svelmoe 13. September 2009 19:37

Some days ago a YouTube video appeared of a Danish women looking for the father of her child - which she supposedly met some evening and didn’t remember the name or nationality of.
The video can be seen here: http://www.youtube.com/watch?v=2xEiMpPKjFo
Now, many people thought it was real and it sort of vent “viral” which can be seen in the comments.

It has now been revealed that the video is a fake (oh the horrors - welcome to the Internet)  and is an advertisement from a Danish ad agency to promote “Denmark”, called “VisitDenmark“.
Well - that’s that to begin with, and I didn’t really care …. until I saw a representative for the agency in the news on a Danish TV station talking about he trick, which prompted my reaction.

The representative, sad there and kept repeating a memorized mantra that it was to promote awareness of the place called Denmark (duh)  and when asked if they had thought of the consequences and image they’d project of the Danish women, she repeated another memorized line of keywords - that they believed it promoted an image of “independent” women, taking “choices” in a “society” which allows them to take their own choice…….and other such keywords.
If I were a specialist in body language however, I’d also say she was lying about that - as she spoke those memorized keywords with erratic movements of upper body and head, and the attempts at emphasizing the keywords compared to the rest of the words, but I’m not a specialist - so..... It just looked like it wasn’t a reaction they had anticipated and needed to come up with excuses fast.

Funny though - my, and many others, impression of the messaged conveyed, was instead that they promoted Danish women as easy, willing to sleep with random tourists without knowing their names or nationality.
Visit Demark and try our easy women…. That’s the message they convey in my opinion.
The general reaction so far from people and politicians alike are also that it is distasteful attempt of promoting Denmark, and many remarks on both YouTube and elsewhere are the same interpretation as mine.

I guess we’ll see if this plan creates publicity and works or not…. Because I’m not a subscriber of the “any publicity is good publicity” theory - many people deliberate avoid products when displayed in stupid adverts or when companies lies to the public. This is no difference whether it is milk bought in the supermarket or awareness of a nation.

I can’t wait to see the consequences for VisitDenmark - because I’m sure we’ll see some and this case isn’t over yet.

Enabling moderated comments due to spam

by Svelmoe 26. July 2009 18:06

Some time ago Google announced more insight in how the nofollow attribute worked, and since then I’ve received an explosion in comment spam.

So now I’ve taken the liberty of enabling moderating of comments, to stem up against this inrease in spams - too bad people have to ruin it for others.
Funnily enough some of these spamming idiots have the gall to put “nospam” in as e-mail address ….. so I guess spam is an issue for them as well. 

With any luck, moderated comments will just be temporary, but well – it never hurt anybody to wait a little while with putting a comment on-line.

Tags:

Blogging

Long running Close() on SQLDataReader / Slow Close()

by Svelmoe 30. June 2009 13:51

Today I was faced with a problem where the close method on a SQLDataReader took ages – well 10 seconds or so – to complete.

Then I read the following snippet from the documentation:
The Close method fills in the values for output parameters, return values and RecordsAffected, increasing the time that it takes to close a SqlDataReader that was used to process a large or complex query. When the return values and the number of records affected by a query are not significant, the time that it takes to close the SqlDataReader can be reduced by calling the Cancel method of the associated SqlCommand object before calling the Close method.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.close.aspx

So I tried calling cancel on the command prior to closing the reader and presto – the SQLDataReader closed very fast.

Once again, reading the documentation solved my problem and from this day on, I'll try to cancel the command prior to every close, just to see if it saves some time :)

Using scripts in XSLT

by Svelmoe 2. June 2009 18:36

I mentioned in my last blog post that you can use scripts in XSLT, so I just wanted to show shortly how you can use scripts to show the power it can yield.
Firstly – add a namespace to your XSLT file:

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

Then you can use the scripts in various situations.
For example, I had to parse some "Yes" and "No" into Boolean strings "true" and "false" (for business logic reasons) so I made a script for that in the bottom of my XSLT file (I made the scripts in C# syntax):

<msxsl:script language="C#" implements-prefix="scripts">
    <![CDATA[
        //return true or false as string instead of "yes" and "no"
    public string getBooleanString(string s0)
    {
      if ((String.Equals(s0, "yes", StringComparison.OrdinalIgnoreCase))
      { return "true"; }
      if (String.Equals(s0, "no", StringComparison.OrdinalIgnoreCase))
      { return "false"; }
      return s0;
    }
    ]]>
</msxsl:script>

Now, I could use this script in my XSLT matching like this:

<xsl:value-of select ="scripts:getBooleanString(./VALUE)"/>

This makes a call to the C# script “getBooleanString” with the value, the script will test it for “Yes” and “No” and return “true” or “false” respectively, or the string itself it it wasn’t one of the two.
Some of the other things I used this for was to compare strings case with case insensitive, and to hold temporary values to avoid having to run through my XSLT file multiple time in the transformation process.  I also had to convert some number formats to use period as decimal point instead (due to language specific settings), so I made a script which changes between period and comma.

It is a powerful tool to have in the XSLT toolbox.

XSLT in .NET

by Svelmoe 1. June 2009 13:39

I have been working quite a bit with doing XSLT on some large XML files lately.
During this I worked with the XslCompiledTransform class in .NET, which make transformations really easy and it works very fast.

An advantage of this class is also that it enables you to utilize scripts within your XSLT file, which enables you to make for example C# functions, for various tasks. I’ll write more about that in a later blog entry to keep this one simple and to the point.

The syntax (in vb.net) for doing a transformation using XslCompiledTransform is as simple as the following:

    'Create settings which eanble scripting in the XSLT file
    
Dim xmlSettings As New 
XsltSettings
    xmlSettings.EnableScript 
= True
    
'create a XML reader for the XLST file
    
Dim xsltFile As XmlReader XmlReader.Create("XSLT FILE"
)
    
'create a Transform object
    
Dim xslTransform As New 
XslCompiledTransform
    
'Load XSLT file with Settings into transform object
    
xslTransform.Load(xsltFilexmlSettingsNothing
)
    
'Do the transformation.
    
xslTransform.Transform("INPUT XML FILE""OUTPUT XML FILE")
  

The main disadvantage I’ve found for using this transformation is the huge memory usage it uses.
In my own situation, the process used about 3.5 times as much memory as my source XML file, meaning that a source file about 450MB my .NET process was killed on a 32 bit computer with an out of memory exception.

The actual memory usage will of course vary depending on how complex your transformation is, so the 3.5 number is not meant to be nothing more than an indicator that it is memory intensive.
It is however very fast, and I managed to transform very large files in a manner of seconds, thus if you can live with the memory consumption it is quite effective.

String comparison performance, and regular expression, in vb.net

by Svelmoe 26. May 2009 16:50

Having to do some optimizing of processes over the last period of time, I decided to do some quick benchmark of the various string comparisons, to see how they performened against each other.
The ones I was interested in was the String.Equal and String.Compare, so I decided to make some quick testing.

I made a WinForm and used the following code to test with:

      For i As Integer = 0 To 100000
            If String.Equals("item", "ITEM", StringComparison.InvariantCultureIgnoreCase) Then
                Debug.WriteLine("yes")
            End If
        Next
        For i As Integer = 0 To 100000
            If String.Equals("item", "ITEM", StringComparison.CurrentCultureIgnoreCase) Then
                Debug.WriteLine("yes")
            End If
        Next
        For i As Integer = 0 To 100000
            If String.Equals("item", "ITEM", StringComparison.OrdinalIgnoreCase) Then
                Debug.WriteLine("yes")
            End If
        Next
        For i As Integer = 0 To 100000
            If String.Compare("item", "ITEM", True) = 0 Then
                Debug.WriteLine("yes")
            End If
        Next
        For i As Integer = 0 To 100000
            If String.CompareOrdinal("item", "item") = 0 Then
                Debug.WriteLine("yes")
            End If
        Next
        Dim regex As New System.Text.RegularExpressions.Regex("item", System.Text.RegularExpressions.RegexOptions.Compiled Or System.Text.RegularExpressions.RegexOptions.IgnoreCase)
        For i As Integer = 0 To 100000
            If regex.IsMatch("item") Then
                Debug.WriteLine("yes")
            End If
        Next


The specifics of the code aren’t that interesting, it was mostly to create some comparable numbers, so I use just one string “item” to compare to “ITEM” (except for CompareOrdinal, which is mostly there as a benchmark).

Anyways I was quite surprised at the numbers when I ran the code through RedGate’s ANTS performance profiler.



For the String.Equals with the various options, the following numbers were meassured:
StringComparison.InvariantCultureIgnoreCase gave 51.490ms (the actual number is irrelevant, it is the relative difference I’m interested in)

StringComparison.CurrentCultureIgnoreCase gave 65.747ms which is close enough to the above that I’ll say those two are quite similar.

StringComparison.OrdinalIgnoreCase however only took 12.378 for the same amount of iterations and true checks. This surprised me a bit.

String.Compare took 66.004ms, which is similar to the CurrentCultureIgnoreCase.

CompareOrdinal only took 8.056ms, but of course is case sensitive, so it doesn’t quite match up to this situation (unless you spend less time running a ToUpper on your compare clauses).

RegEx.IsMatch took a staggering 375.127ms with compiled and ignore clause, but then again – you shouldn’t use regular expression for something as trivial as this anyway. Regular expression is a very powerful tool in its own right, this was just to compare.

The big surprise is that there is such a big difference between using StringComparison.OrdinalIgnoreCase in your String.Equals compared to the other options. I’ll refer to the msdn documentation for the specifics of the different types (http://msdn.microsoft.com/en-us/library/system.stringcomparison.aspx) , but shallowly said - the Ordinal as the name says ignores culture specific matching.

So if that is acceptable in a given situation, using String.Equals with OrdinalIgnoreCase is by far the best option when comparing strings.

Again note the numbers aren’t numerically important, the relative difference existed as I ran the code several times, with OrdinalIgnoreCase winning out significantly each time.
In a production function I had made, I was able to shave several percent off my execution time, simply by switching from String.Compare to String.Equals with OrdinalIgnoreCase option used.
That was an easy way of gaining performance in my book.

VB.NET and the WITH statement

by Svelmoe 20. April 2009 20:23

I love using the WITH statement in VB.NET/ASP.NET because it eases up on the typing and helps “group together” functionality.
However, I found a fun little something when using the WITH statement, which I wanted to share.

It seems that you can assign a new object reference within a WITH statement to the specific object, however you can’t assign values to said new reference. Strange indeed, but I’m sure there’s some underlying reason.
Here some code to illustrate.

Suppose I have a class:

Private Class Test
        Private m_Text As String

        Public Property TextValue() As String
            Get
                Return m_Text
            End Get
            Set(ByVal value As String)
                m_Text = value
            End Set
        End Property
End Class

Then I have some code which uses this class in a WITH statement:

Dim obj As New Test()
obj.TextValue = "Test"
  For i As Integer = 0 To 10
   With obj
     If Not String.IsNullOrEmpty(.TextValue) Then
          System.Diagnostics.Debug.WriteLine("VALUE: " & .TextValue)
    Else
         System.Diagnostics.Debug.WriteLine("VALUE NOTHING")
    End If
    obj = New Test()
    .TextValue = "test" & i
   End With
Next

When run this provides the output:
VALUE: Test
VALUE NOTHING

And "nothing" for every subsequent run.
So it is possible to assign a new reference to the “obj” object reference, but the assignment of the new TextValue is ignored.

Not that usefull, but fun enough in my book :) (yes, I’m a geek

Powered by BlogEngine.NET 1.4.5.0
Theme by Extensive SEO

About Svelmoe

My real name is Allan Svelmøe Hansen.

I live in Denmark, where I work as a developer for hedal:kruse:brohus using SQL Server and the .NET framework since 2004. Svelmoe.dk is a place for my every day thoughts and reactions and the occasional technical blog entry.

I also blog about SQL and MS SQL Server but have moved those posts to www.sqlstuff.dk so in case you are looking for more about that, please visit that website.