Vincent Leung .NET Tech Clips

The latest tech clips from the .NET community

Simple Javascript to displaying the client’s current date and time

 

Simple set of functions to display the client’s date and time on your web pages.

CodeProject: Displaying the client’s current date and time. Free source code and programming help

July 11, 2008 Posted by | JavaScript | Leave a Comment

How to use the YouTube embedded Video Player

 

YouTube Chromeless Player API

 

Chromeless player SWF URL:

http://gdata.youtube.com/apiplayer?key=DEV_KEY

note: it is using gdata.youtube.com and videoId is no longer part of the url as it was used in the javascript player api.

 

Functions

The following functions are available in addition to the ones listed in the JavaScript API section below:

loadVideoById(videoId:String, startSeconds:Number):Void

cueVideoById(videoId:String, startSeconds:Number):Void

setSize(width:Number, height:Number):Void

Sample Code: http://code.google.com/apis/youtube/chromeless_player_reference.html#Examples

YouTube JavaScript Player API

 

Embedding the YouTube player using SWFObject

We recommend using SWFObject to embed any players that will be accessed using the JavaScript API. This will allow you to detect the end user’s Flash Player version (the JavaScript API requires Flash Player 8 or higher), and also will get rid of the ‘Click to activate this control’ box when using Internet Explorer to view the player. To enabled the API in the SWF, you must pass in the parameter enablejsapi=1.

image

   Additional SWF Url Parameters that allows you to set things like color, border, autoplay, ‘Genie’ menu, related videos etc…

Getting the Player Reference

e.g. function onYouTubePlayerReady(playerId) { ytplayer = document.getElementById(“myytplayer”); }

Issuing Calls

e.g. function play() { if (ytplayer) { ytplayer.playVideo(); } } <a href=”javascript:void(0);” onclick=”play();”>Play</a>

Subscribing to Events

e.g.

function onYouTubePlayerReady(playerId) { ytplayer = document.getElementById(“myytplayer”); ytplayer.addEventListener(“onStateChange”, “onytplayerStateChange”); }

function onytplayerStateChange(newState) { alert(“Player’s new state: ” + newState); }

Functions and Events exposed by the Javascript Player API: http://code.google.com/apis/youtube/js_api_reference.html#Operations

Sample Code: http://code.google.com/apis/youtube/js_api_reference.html#Examples

June 19, 2008 Posted by | JavaScript | 1 Comment

How to embed Flash Player content using SWFObject dynamic publishing

 

STEP 1: Create alternative content using standards compliant markup

STEP 2: Include the SWFObject JavaScript library in the head of your HTML page

STEP 3: Embed your SWF with JavaScript

image

STEP 4: Use JavaScript Objects to define your flashvars, params and object’s attributes

image


TIPS

Why use Dynamic publishing

Description

Create alternative content using standards compliant markup and embed Flash content with unobtrusive JavaScript.

Pros

Avoids ‘click-to-activate’ mechanisms in Internet Explorer 6+ and Opera 9+ and is easy to author (even without using this generator).

Cons

The embedding of Flash content relies on JavaScript, so if you have the Flash plug-in installed, but have JavaScript disabled or use a browser that doesn’t support JavaScript, you will not be able to see your Flash content, however you will see alternative content instead. Flash content will also not be shown on a device like Sony PSP, which has very poor JavaScript support, and automated tools like RSS readers are not able to pick up Flash content.

June 19, 2008 Posted by | JavaScript | 1 Comment

SQL# (SQLsharp) – Enabling more powerful SQL

 

Features:

  • String: Contains, Count, Cut, EndsWith, Equals, IndexOf, InitCap, Join, LastIndexOf, Newline, NthIndexOf, PadLeft, PadRight, Split, SplitIntoFields, StartsWith, Trim, WordWrap
  • RegEx: IsMatch, Matches, Match, MatchLength, MatchSimple, Replace, Split
  • Math: CompoundAmortizationSchedule, Constant (30 physics constants), Convert (22 measurement conversions), Cosh, Factorial, IsPrime, RandomRange, Sinh, Tanh
  • Date: BusinessDays, DaysInMonth, DaysLeftInYear, FirstDayOfMonth, FormatTimeSpan, FromUNIXTime, FullDateString, FullTimeString, IsBusinessDay, IsLeapYear, LastDayOfMonth, ToUNIXTime
  • InterNet (not available in free version): AddressToNumber, FtpDo, FtpGet, FtpPut, GetHostName, GetIPAddress, GetWebPages, IsValidIPAddress, NumberToAddress, Ping, PingTime
  • File (not available in free version): ChangeEncoding, Copy, CopyMultiple, CreateDirectory, Decrypt, Delete, DeleteDirectory, DeleteMultiple, Encrypt, GetDirectoryListing, GetDriveInfo, GetFile, GetFileBinary, GetRandomFileName, GetTempPath, GUnzip, GZip, Move, MoveMultiple, PathExists, SplitIntoFields, WriteFile, WriteFileBinary
  • Miscellaneous: CRC32, Deflate, GenerateDateTimeRange, GenerateDateTimes, GenerateFloatRange, GenerateFloats, GenerateIntRange, GenerateInts, GUnzip, GZip, Hash, Inflate, IsValidCC, IsValidSSN, ToWords
  • Database: DumpData (not available in free version)
  • Convert: BinaryToHexString, FromBase64, HexStringToBinary, ROT13, ToBase64
  • LookUps: GetCountryInfo, GetStateInfo
  • Internal: Version, Help, Setup, Uninstall, GrantPermissions, IsUpdateAvailable, Update (not available in free version), SetSecurity, WebSite
  • User-Defined Aggregates: GeometricAvg, Join, Median, Random, RootMeanSqr
  • User-Defined Types: FloatArray, HashTable, NVarcharArray

What can SQL# do?

  • SQL# gives you the easiest access to the power of the CLR!
    – a single assembly with over 100 functions, 5 User-Defined Aggregates, 3 User-Defined Types, and more being added!
  • SQL# installs easily and in moments!
    – download one small install sql script, execute it, and enjoy the power of the CLR!
  • SQL# is backed up and restored with the database along with all other objects and data!
    – no need to worry about separate DLLs as with COM Extended Stored Procedures
  • SQL# has built in documentation (list of function and procedure signatures)!
    – if you ever lose the documention, the worst off you are is one procedure call away from viewing the entire list of function signatures!
  • SQL# can easily be updated via the web in moments!
    – you can optionally install updates via the web with a single procedure call
  • SQL# saves countless hours learning CLR and .Net, not to mention the cost of Visual Studio 2005!
    – time is money and you have work to do so why stop and learn yet another language, especially when you might need to purchase additional software just to compile a basic function!
  • SQL# lets you focus on SQL programming without sacrificing the power of the CLR!
    – again, there is only so much time in the day so do you want to spend it NOT being productive?

Download

Download Free Version of SQL# (SQLsharp) here!

The manual and “What’s New” document cover both Free and Paid-For versions.
Manual in PDF format (766k)
What’s New in Version 2.5.20/2.5.21 (122k)

Date_BusinessDays ExcludeDaysMask Worksheet .
Download Spreadsheet (19k)

Via SQL# (SQLsharp) – Enabling more powerful SQL (Features)

March 22, 2008 Posted by | C#, Database | 4 Comments

Essential SQL Server Date, Time and DateTime Functions

Standard Date, Time & TimeSpan Functions

function DateOnly(@DateTime DateTime)
– Returns @DateTime at midnight; i.e., it removes the time portion of a DateTime value.
returns datetime

create function Date(@Year int, @Month int, @Day int)
– returns a datetime value for the specified year, month and day
– Thank you to Michael Valentine Jones for this formula (see comments).
returns datetime

create function Time(@Hour int, @Minute int, @Second int)
– Returns a datetime value for the specified time at the “base” date (1/1/1900)
– Many thanks to MVJ for providing this formula (see comments).
returns datetime

create function TimeOnly(@DateTime DateTime)
– returns only the time portion of a DateTime, at the “base” date (1/1/1900)
returns datetime

create function DateTime(@Year int, @Month int, @Day int, @Hour int, @Minute int, @Second int)
– returns a dateTime value for the date and time specified.
returns datetime

create function TimeSpan(@Days int, @Hours int, @Minutes int, @Seconds int)
– returns a datetime the specified # of days/hours/minutes/seconds from the “base” date of 1/1/1900 (a “TimeSpan”)
returns datetime

create function TimeSpanUnits(@Unit char(1), @TimeSpan datetime)
– returns the # of units specified in the TimeSpan.
– The Unit parameter can be: “d” = days, “h” = hours, “m” = minutes, “s” = seconds
returns int

For More Details: Essential SQL Server Date, Time and DateTime Functions

see also:

March 22, 2008 Posted by | C#, Database | Leave a Comment

Do not learn Ruby

 

Ruby will get under your skin. You will miss its features and quirks when you’re not using it. You might even find other languages insufferable, once you get comfortable with Ruby.

Do not learn Ruby

February 22, 2008 Posted by | Ruby | Leave a Comment

IronPython Studio – Home

image 

Introduction

IronPython Studio is a free full IDE (Integrated Development Environment) for the Python programming language. It is based on the existing IronPython example that is included in the VS SDK.
IronPython Studio is based on the Visual Studio 2008 Shell runtime (royalty free) and can be installed without requiring any version of Visual Studio.

IronPython Studio – Home

February 6, 2008 Posted by | Python, Visual Studio | Leave a Comment

Silverlight & HTML DOM interaction Screencast

By Tim Heuer

image 

Using Javascript to manipulate HTML & Silverlight elements.

Download Screencast

November 8, 2007 Posted by | JavaScript, Silverlight | Leave a Comment

Extract frames from video files – The Code Project – Multimedia

 

Introduction

This class contains methods to use the IMediaDet interface, that can be found in Microsoft DirectShow.
The Media Detector object, among other things, can be used to extract still pictures from several file formats including .avi, .wmv and some .mpeg files. This class exposes the GetFrameFromVideo, GetVideoSize and SaveFrameFromVideo methods that can be used from any .net application. The class also takes care of translating HRESULTs returned from the functions to meaningful .net exceptions.

Using the code

Just add a reference to JockerSoft.Media.dll in your project (or include the source code). Remember also to distribute Interop.DexterLib.dll  All the methods are static, so to use them just do something like

try
{
    this.pictureBox1.Image = FrameGrabber.GetFrameFromVideo(strVideoFile, 0.2d);
}
catch (InvalidVideoFileException ex)
{
    MessageBox.Show(ex.Message, "Extraction failed");
}
catch (StackOverflowException)
{
    MessageBox.Show("The target image size is too big", "Extraction failed");
}

or

try
{
    FrameGrabber.SaveFrameFromVideo(strVideoFile, 0.2d, strBitmapFile);
}
catch (InvalidVideoFileException ex)
{
    MessageBox.Show(ex.Message, "Extraction failed");
}

Via Extract frames from video files – The Code Project – Multimedia

September 27, 2007 Posted by | C#, Tools | 3 Comments

Read/Write App.Config

In .NET 2.0+ and with the help of Visual Studio Generated Settings.settings, you can do the following:

image

Load your settings programmatically:

Settings set = Settings.Default;

Read from your settings:

string str = set.testSetting;

Write to your settings:

set.testSetting = “xyz”;
set.Save();

Very Easy

September 5, 2007 Posted by | C#, Visual Studio | Leave a Comment

Follow

Get every new post delivered to your Inbox.