Display VIMEO video thumbnail

On the homepage of http://www.divelicious.com we display images of youtube and vimeo. To get the images of vimeo you can try this. You only need a bit of javascript (and jquery).

<script type="text/javascript">
        $(document).ready(function () {
            $('.vimeothumb').each(function (i, obj) {
                vimeoVideoID = $(this).data('val');
                    'http://www.vimeo.com/api/v2/video/' + vimeoVideoID + '.json?callback=?',
                    { format: "json" },
                    function (data) {
                        var imgId = '#' + data[0].id;
                        $(imgId).attr('src', data[0].thumbnail_small);
                        $(imgId).attr('title', data[0].title);
                        // title
                        // description
                        // thumbnail_large ()
                        // thumbnail_medium (200x150)
                        // thumbnail_small (100x75)

And in your HTML you require an img element which carries the vimeothumb with the data-val set to the image which needs to be displayed.

<img id="{vimeoid}" class="img-rounded vimeothumb  videothumb" alt="" data-val="{{vimeoid}" />

Parameter is not valid error in MemoryStream

Encountered the following exception which was caused by converting a byte[] which originated from a BMP to an Image.


public static Image ToImage(this byte[] value)


            Image returnImage;

            using (MemoryStream ms = new MemoryStream(value))


                returnImage = Image.FromStream(ms);



            return returnImage;



System.ArgumentException was unhandled by user code


  Message=Parameter is not valid.



       at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)

       at System.Drawing.Image.FromStream(Stream stream)


I will try to solve this in the near future. It works though with all other image formats.

MVC4 Conditional attribute(s)

MVC4 beta has conditional attributes built in...


<div @{if(myClass !=null){<text>class="@myClass"</text>}}>Content</div>

<div class="@myClass">Content</div>


If @myClass is null, it just won't use the attribute at all...

Finding text in procedures

      WHERE [text] LIKE '%foobar%'
      AND OBJECTPROPERTY(id, 'IsProcedure') = 1

TSQL - Pivot uniqueidentifier

with cntval
, id = MIN(CAST(id AS BINARY(16)))
FROM [table]
where (code = 1 or code =2 )
cast ( max(case con.code when 1 then id end) as uniqueidentifier)
, cast ( max(case con.code when 2 then id end) as uniqueidentifier)
cntval con

TSQL - Find a column in the database

If you need to find where a certain column is used in the database you can use the following sql code.

select *
where column_name = 'CustomerStatus'

Descriptor Pattern Part II

I described the descriptor patteren earlier, this time I want to elaborate a bit showing the advantage of extending it and using it in combination with an MVC application. I created two classes ApplicationAction and Account Action where AccountAction extends ApplicationAction.

Here is the implementation of the ApplicationAction

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Divelicious.Website.Code.Descriptor
public class ApplicationAction
private string _description = String.Empty;

private static readonly IDictionary dict = new Dictionary<string, ApplicationAction>();

protected ApplicationAction(string description)
_description = description;
dict.Add(description, this);

public override string ToString()
return _description;

public static ApplicationAction Parse(string description)
if (dict.Contains(description))
return dict[description] as ApplicationAction;
throw new NotImplementedException("This description is currently not supported.");

public static bool TryParse(string description, out ApplicationAction gender)
gender = Parse(description);
return true;
catch (NotImplementedException)
gender = null;
return false;

public static IEnumerable GetMembers()
return dict.Values.Cast().ToList();

Here is the AccountAction

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Divelicious.Website.Code.Descriptor
public class AccountAction : ApplicationAction
private AccountAction(string description)
: base(description)


// Account
public static readonly AccountAction Login = new AccountAction("Login");
public static readonly AccountAction LogOff = new AccountAction("LogOff");
public static readonly AccountAction Register = new AccountAction("Register");
public static readonly AccountAction Disassociate = new AccountAction("Disassociate");
public static readonly AccountAction Manage = new AccountAction("Manage");
public static readonly AccountAction ExternalLogin = new AccountAction("ExternalLogin");
public static readonly AccountAction ExternalLoginCallback = new AccountAction("ExternalLoginCallback");
public static readonly AccountAction ExternalLoginConfirmation = new AccountAction("ExternalLoginConfirmation");
public static readonly AccountAction ExternalLoginFailure = new AccountAction("ExternalLoginFailure");
public static readonly AccountAction ExternalLoginsList = new AccountAction("ExternalLoginsList");
public static readonly AccountAction RemoveExternalLogins = new AccountAction("RemoveExternalLogins");


And when you want to use it. 

<a href="@Url.Action(@AccountAction.Login.ToString(), "Account", new { Area="" })">Login</a>

TSQL - Update using an inner join

Sometimes you want to update a table and require a join with another table. The achieve this use the following construction.

SET t1.CalculatedColumn = t2.[Calculated Column]
FROM dbo.Table1 AS t1
INNER JOIN dbo.Table2 AS t2 ON t1.CommonField = t2.[Common Field]
WHERE t1.BatchNo = '110';

Add a column to an existing table

 if not exists (select 1 from INFORMATION_SCHEMA.columns
 where table_schema = 'dat'
   and table_name = 'table_name'
   and column_name = 'your_column')   
     alter table dat.table_name
     add your_column varchar(255)

Error message when you try to save a table in SQL Server: "Saving changes is not permitted"

To change the Prevent saving changes that require the table re-creation option, follow these steps:

  1. Open SQL Server Management Studio (SSMS).
  2. On the Tools menu, click Options.
  3. In the navigation pane of the Options window, click Designers.
  4. Select or clear the Prevent saving changes that require the table re-creation check box, and then click OK.




Sponsored by


<<  May 2016  >>

View posts in large calendar