Tuesday 30 September 2014

SQL Server - Group DateTime by Minutes / x minutes

If you want to group by records based on Minutes use the below Group By:
GROUP BY
DATEPART(YEAR, SUB.[SubOnDate]),
DATEPART(MONTH, SUB.[SubOnDate]),
DATEPART(DAY, SUB.[SubOnDate]),
DATEPART(HOUR, SUB.[SubOnDate]),
DATEPART(MINUTE, SUB.[SubOnDate])

If you want to group by records by x minutes, it is as below. In the sample below its grouped by every 10 minutes. so records within each 10 minutes will be in the same group.
GROUP BY
DATEPART(YEAR, SUB.[SubOnDate]),
DATEPART(MONTH, SUB.[SubOnDate]),
DATEPART(DAY, SUB.[SubOnDate]),
DATEPART(HOUR, SUB.[SubOnDate]),
(DATEPART(MINUTE, SUB.[SubOnDate]) / 10)

Monday 22 September 2014

How to generate web service from wsdl file

This is a common scenario faced by developers who do web service based integrations. The partner if its an external company, might send over the wsdl file and ask to create a web service out of it so they can consume your webservice.

This is when the partner demands more control and they want to make sure all their partners host similar webservices so that the partner's code for the web service call is consistent.

Now to solve the matter, we do not have a GUI genie (wizard) for our help. We will have to do each step manually taking help of command line.

Here are the steps:
1) From the WSDL file create an Interface class using wsdl tool. For this, bring up the Visual Studio Command Prompt Window and run the below command.
wsdl.exe yourFile.wsdl /l:CS /serverInterface
Note: You can decide the language of the Interface Class generated. In parameter /l, use VB or CS for your Visual Basic or CSharp respectively. Finally the command will create a new .cs or .vb file.

2) Create a new .NET Web Service (.asmx).

3) Import the file created in the above step into your project.

4) In your .asmx.cs file in Code-View, modify class as below to implement the interface generated in the above step:
public class MyWebService : System.Web.Services.WebService, IWsdlService
{
// Web methods and other calls goes here....
}
5) Implement the methods mentioned in the Interface class. Finally your webservice class will be something like this:
public class MyWebService : System.Web.Services.WebService, IWsdlService
{
[WebMethod]
public string MyWeMethod1()
{
// your business logic goes here...
return "MyWeMethod1 Result";
}
[WebMethod]
public string MyWeMethod2()
{
// your business logic goes here...
return "MyWeMethod2 Result";
}

Tuesday 16 September 2014

Javascript - How to check if a string contains another string

String function indexOf returns the position of the sub string in a string. If it doesn't find an occurance of the sub string, it will return -1.
var mainText = "microsoft";
var isSubstring = mainText.indexOf("soft") > -1
alert(isSubstring);
In the example, it checks for the substring "soft" within the main string "microsoft". As it find "soft" inside "microsoft", mainText.indexOf("soft") evaluates to 5 and isSubstring will be true;

Wednesday 10 September 2014

Data transfer speed between devices

Data transfer speed depends on many factors including the devices involved and the medium transferring data.

BUS
Bus is the actual wires that carry data. There are different types of bus (eg: Universal Serial Bus (USB), Ethernet) and they follow different protocols. Different controller chips (Integrated Circuits (IC)) take care of these protocols for data transfer. Now, each system will have its own controllers which vary in their capabilities and configurations. The working of these controllers affect the data transfer speeds. Some cheaper systems will rely on CPU for data transfer while more expensive ones will have dedicated controllers for data transfer. Systems using CPU cycles for data transfer slow down the system's performance as well as the data transfer speeds. Now a days, most systems have its own usb controller chips which will not steal CPU cycles and thus improving data transfer rate between devices. But system might have 3 usb ports and each one might have devices like mouse and external hard disks connected. All these devices and sometimes even your internal hard disk might share the same bus (wires) internally. In which case, each time you move the mouse, it interrupts the communication to your hard disks, making the data transfer rates to the disk slower.

Another factor related to buses is DMI (direct memory interface). It is an option which the controllers can use to make transfer rate appear better. Here controllers are allowed to use a portion of RAM as a buffer/cache data before actually writing to the disk. Typically this memory allocation is in the range of 16MB to 64MB. So if your data to be transferred is within this range, it showes to complete fast and if the dataoverflows this DMI memory, then it will fall back to the speed of the device. When a hard disk advertizes its transfer speed to be 480mb/s, the speed is available only for files within the size of the buffer. Once the buffer is full, the transfer rate falls down to the actual speed of the disk.

HARD DISK
I am specifically talking about the Mechanical HDD (Hard Disk Drive) and not the new SSD. Hard disk is the part of a computer that stays as a bottle neck for the performace of the rest of the components like Processor, RAM and the Bus. It is the only mechanical component in a computer and this explains for the low performance. HDD has Magnetic disks on which data is stored. It also has a disk arm/head which move around the disk platter to read/write data. This is a time consuming activity as the the disk arm / head has to physically move around. Obviously read operations are much faster than writes as writes also involve finding the place to insert/update data and changing the data on disk. Another factor is the fragmentation of data on the disk. The more fragmented a file is, the more the data is spread out on the disk and the longer it takes for the mechanical arm to move around and read or write data. Another factor affecting the transfer rate is the buffer memory of the disk. For example bus speed of ESATA is 3GB/sec. So while the disk buffer of say 64MB fills up at 3GB/sec, then it falls back to the disk speed of say 15bm/sec - 30mb/sec.

FILE SYSTEM
Different Operating Systems use different File Systems. Windows use NTFS/FAT32 and Linux use ext1/ext2/ext3/ext4. File System work on mapping the physical locations of file into human readable file names. It is more complicated than said because fragmentation is handled differently by different file systems and they efficiency to manage fragmentation varies with file systems. The more fragmented your disk is the more time it takes to fetch a complete file. Studies have shown that Linux ext3/4 deals more efficiently with defragmentation.
Also if your physical drive has multiple partitions and you move data from one partition to the other, it will be ridiculously slow. It is because the same disk arm has to move to a location to read data and move to the other location to write it. So moving files between partitions would be slower.

Saturday 6 September 2014

MAC OS- How to view Next and Previous photos from Finder

Image preview works a little different than from Windows Preview.
In WINDOWS you open an image from Windows Explorer and the Photo opens up in Windows Preview by default. You can view the next or previous images by clicking the left or right arrows.

In MAC OS, its a bit different, but gives you even a better experience sometimes.
Follow the below steps:
  1. From FINDER go to Photos folder, CMD+A (select all)
    • You can also select only some images according to your choice of viewing.
  2. Once selected, CMD+O (open)
  3. This will open the Photos in PREWIEW application
  4. View the next or previous photo with Right Arrow or Left Arrow. (Also Up / Down Arrow works. The trackpad slide works as well)
CMD+A (Select All)

CMD+O (Opens the selected Images in PREVIEW)

SQL SERVER 2008 - You must use the Role Management Tool to install or configure Microsoft .NET Framework 3.5.

While trying to install Visual Studio 2008 / SQL Server Management Studio or SQL Server Connectivity Tools on a Windows 2008 R2 machine you may get the following error.

You must use the Role Management Tool to install or configure Microsoft .NET Framework 3.5.

If you try to download .NET Framework 3.5 and install also it will give you error.

This is because Windows 2008 R2 already ships with the .NET 3.5.1 framework which needs to be enabled. You can enable the feature from Server Manager.

Steps:
1) Go To "Server Manager Console Window".
2) In the Console tree on the left, click Features.
3) In the Features pane click Add Features.
4) In the Add Features Wizard, select ".NET Framework 3.5.1 Features" and click Install.

Once you install the .NET Framework 3.5.1 Features from the Add Features Wizard in Server Manager, you can try installing VS 2008 / SSMS.

Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.


start-> Run--> c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -iru

To resolve this issue, run the following command line:
aspnet_regiis.exe /iru
The Aspnet_regiis.exe file can be found in one of the following locations:
%windir%\Microsoft.NET\Framework\v4.0.30319
%windir%\Microsoft.NET\Framework64\v4.0.30319 (on a 64-bit computer)