31 Days of Refactoring
Refactoring is an integral part of continually improving your code while it moves forward through time. Without refactoring you accrue technical debt, forget what portions of code do and create code that is resistant to any form of testing. It is an easy concept to get started with and opens the door to much better practices such as unit testing, shared code ownership and more reliable, bug-free code in general.
Day 1 : Encapsulate Collection
Day 2 : Move Method
Day 3 : Pull Up Method
Day 4 : Push Down Method
Day 5 : Pull Up Field
Day 6 : Push Down Field
Day 7 : Rename (method, class, parameter)
Day 8 : Replace Inheritance with Delegation
Day 9 : Extract Interface
Day 10 : Extract Method
Day 11 : Switch to Strategy
Day 12 : Break Dependencies
Day 13 : Extract Method Object
Day 14 : Break Responsibilities
Day 15 : Remove Duplication
Day 16 : Encapsulate Conditional
Day 17 : Extract Superclass
Day 18 : Replace exception with conditional
Day 19 : Extract Factory Class
Day 20 : Extract Subclass
Day 21 : Collapse Hierarchy
Day 22 : Break Method
Day 23 : Introduce Parameter Object
Day 24 : Remove Arrowhead Antipattern
Day 25 : Introduce Design By Contract Checks
Day 26 : Remove Double Negative
Day 27 : Remove God Classes
Day 28 : Rename boolean methods
Day 29 : Remove Middle Man
Day 30 : Return ASAP
You can find all of the sample code available for download here: http://github.com/schambers/days-of-refactoring/tree/master
Via 31 Days of Refactoring – Sean Chambers – Los Techies : Blogs about software and anything tech!
Functional Programming for Everyday .NET Development
In this article we will examine in particular how the new support for functional programming techniques in .NET 3.5 can help you do the following:
- Make your code more declarative.
- Reduce errors in code.
- Write fewer lines of code for many common tasks.
The Language Integrated Query (LINQ) feature in all of its many incarnations is an obvious and powerful use of functional programming in .NET, but that’s just the tip of the iceberg.
For more visit Functional Programming for Everyday .NET Development
What is the difference between a.Equals(b) and a == b?
Value Types:
For value types, “==” and Equals() works same way : Compare two objects by VALUE
Example:
int i = 5;
int k= 5;
i == k > True
i.Equals(k) > True
Reference Types:
For reference types, both works differently :
“==” compares REFERENCE – returns true if and only if both references point to the SAME object.
Equals method compares object by VALUE.
Example:
StringBuilder sb1 = new StringBuilder(”Mahesh”);
StringBuilder sb2 = new StringBuilder(”Mahesh”);
sb1 == sb2 > False
sb1.Equals(sb2) > True
However
String s1 = “zzz”;
String s2 = “zzz”;
In above case the results will be,
s1 == s2 > True
s1.Equals(s2) > True
Why? Does that mean String a Value Type?
No, String IS a Reference Type. Although string is a reference type, the equality operators (== and !=) are defined to compare the values of string objects, not references. This makes testing for string equality more intuitive. For example:
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)
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 datetimecreate 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 datetimecreate 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 datetimecreate function TimeOnly(@DateTime DateTime)
– returns only the time portion of a DateTime, at the “base” date (1/1/1900)
returns datetimecreate 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 datetimecreate 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 datetimecreate 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 intFor More Details: Essential SQL Server Date, Time and DateTime Functions
see also:
- SQL# CLR
- Working with Time Spans and Durations in SQL Server
- Group by Month (and other time periods)
- Working with Date and/or Time values in SQL Server: Don’t Format, Don’t Convert — just use DATETIME
- Data Types — The Easiest Part of Database Design
- How to format a Date or DateTime in SQL Server
- Breaking apart the DateTime datatype — Separating Dates from Times in your Tables
- Date Only and Time Only data types in SQL Server 2005 (without the CLR)
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 theGetFrameFromVideo,GetVideoSizeandSaveFrameFromVideomethods 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
LINQ, C# Rolls
What’s New in C#
- Dinesh Kulkarni is the C# PM in charge of LINQ to SQL. He has recently revved up his blog: http://blogs.msdn.com/dinesh.kulkarni/. Here are a few of his recent posts:
- Sreekar Choudhary is an SDE on the C# Team. This is his second post.
- Browsing Eric Lippert’s blog for the first time is a bit like finding a first class book on C#. Fortunately for us, he has many wonderful new posts to browse:
- Matt Warren is one of the top developers on the C# Team
- Jomo Fisher is C# developer on the LINQ to SQL team. Any technical posts he produce are mandatory reading in my book. He has three new posts for us:
- Luca Bolognese is C# Lead PM
- Luke Hoban is the PM on the Compiler Team
- Wes Dyer
- I have a few new posts:
- How to be random with LINQ to Objects
- LINQ to the Semantic Web Additional information here and also on Hooked on LINQ.
- LINQ to Expressions
- LINQ to Bits
- Work at Microsoft: http://blogs.msdn.com/jobsblog/archive/2007/06/12/my-new-gig-as-a-sourcer.aspx
Community Web Sites and Downloads
- Hooked on LINQ
- Popfly
- Dan Fernandez on Beginning C#
Source from : Charlie Calvert’s Community Blog
