Archive for February 11, 2012

t-sql trim function

Written by Alex on . Posted in Uncategorized

I was surprised when found than SQL server 2005 and even 2008 R2 does not have support for trim function. Trim function is so simple and wide use function so I believed all programming languages support it. But instead Sql server has ltrim and rtrim function

  • ltrim – returns string after removing leading blank characters
  • rtrim – return string after removing trailing blank characters.

But using these two functions you can create trim function and use it in your t-sql code

t-sql trim function

You can create trim function for your database using this source code

CREATE FUNCTION [dbo].[trim] (@stringValue as nvarchar(max))
RETURNS nvarchar(max)
AS
BEGIN
    RETURN ltrim(rtrim(@stringValue));
END

t-sql trim inline code

One more option is to use inline code if for some reason you don’t want to create function

ltrim(rtrim(LastName)) + ', '
+ ltrim(rtrim(FirstName)) as 'Customer Name',

Font scale, pixels vs percent

Written by Alex on . Posted in Uncategorized

I use my PC every day, and often by the end of the day my eyes are tired, so while surfing the internet, I use my browser setting to set large font. And I hate websites where I can’t change font size.

You can’t change font size because it size uses pixels. The better idea is use percent to setup font size.

Using percent you can change font size using your browser setting, just use your mouse wheel with Ctrl key pressed.

There is a good Yahoo UI library to perform font reset and than set default fonts size with percent.

You can add two small css files (reset-fonts.css and base-min.css) to your project and than declare your font size with percent, like this


<style type="text/css">
    .pixelFont
    {
        font-size:14px;
    }

    .percentFont
    {
        font-size:108%;
    }
</style>

<p class="pixelFont">
Hello this is text with font size 14 pixels.
You can't resize this type of font.</p>

<p class="percentFont">
You can resize this font,
because it's size use percent.
Actually it's 108%</p>

Both fonts has the same size 14px with your default browser settings, but try to resize font size on the page with browser, and you will see than pixelFont are not resized in contrast to percentFont.

Eval vs Bind for ASP.NET

Written by Alex on . Posted in Uncategorized

When you start working with ASP.NET sometimes it’s difficult to understand what is the difference between Eval and Bind for data binding controls in ASP.NET. If you just need to display data on the screen from DataSource it’s enough to use Eval. It’s something like read-only method from DataSource. But if you need to edit data inside of Grid you have to use Bind method. Because it provides two way binding you can read data from DataSource and you can write data back. Usually you have to use this methods if you need to quickly develop some WebPages and display and edit data from one table or simple view. If you try to edit some row in Data Grid and want to make some changes in code behind class in OnUdpdating event, data with Eval method will not be available instead of Bind method.

<asp:GridView ID="GridView1" runat="server" CssClass="dataGrid"
   DataSourceID="SqlDataSource1" AllowPaging="True" AutoGenerateColumns="false"
  OnRowDeleting="grid_onRowDeleting" OnRowUpdating="GridView1_OnRowUpdating"
    AutoGenerateEditButton="true" AutoGenerateDeleteButton="true"
  PageSize="20" GridLines="None" Width="99%">
   <AlternatingRowStyle CssClass="odd" />
   <Columns>

       <asp:TemplateField HeaderText="App Id">
           <ItemTemplate>
               <asp:Label ID="lbl" runat="server" Text='<%#Bind("APP_ID") %>'></asp:Label>
           </ItemTemplate>
       </asp:TemplateField>

      <asp:TemplateField HeaderText="App name">
           <ItemTemplate>
               <%#Eval("APPLICATION_NAME")%>
           </ItemTemplate>
       </asp:TemplateField>
   </Columns>
</asp:GridView>
protected void GridView1_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
   // if APP_ID in the grid bind with Eval method, it will be exception below
   // But if you use Bind instead of Eval it will be ok.
   rowToUpdate = e.NewValues["APP_ID"];
}

How to install Mac OS X Snow Leopard on VirtualBox under Windows 7 x64

Written by Alex on . Posted in Uncategorized

This guide explains how to install Mac OS X Snow Leopard on VirtualBox working under Windows 7 x64 Ultimate.

Configuration of my PC

  • laptop Asus G2S.
  • 4GB RAM
  • two core processor
  • VirtualBox 2.3.8
  • Mac OS X Snow Leopard 10.6 (boot image file)

my-pc

Steps to install Mac OS X Snow Leopard on VirtualBox

Dowload Mac OS X image

You need image of Mac OS. You can buy it or download from internet. The image usualy have extension .dng – it’s Mac analog for .iso extension on Windows.

Convert dng file to iso file

Unfortunately VirtualBox does not understand .dng file extension and you have to convert it to .iso. There is a great tool dng2img which you can use to convert dng to iso. It’s free and small.

convert-dng-to-iso

Create virtual machine at Virtualbox

To create new virtual machine in VirtualBox press New button and follow the steps in wizard. Below is the screenshots from my PC. Select at least 1.5 Gb RAM for Virual Machine.   

create-new-vmram-for-vmvm-created

Add boot image for Virtual Machine

After you have created Virtual Machine go to settings and under Storage add Mac OS X image file as a second boot device.

mac-os-boot-imagevm-settings

Modifing Mac OS X Virtual Machine setting

To install Mac OS X to VirtualBox you need to modify configuration file in text editor. Configuration files is just XML files. Close VirtualBox. Open in text editor file

c:\Users\\.VirtualBox\Machines\<virtual-machine>\<virtual-machine>.xml at my PC this path is c:\Users\Alexander\.VirtualBox\Machines\Mac OS X Snow Leopard\Mac OS X Snow Leopard.xml

Add the following lines to <extradata> section of xml file

<ExtraDataItem name="VBoxInternal2/EfiBootArgs" value=" "/>
<ExtraDataItem name="VBoxInternal2/SmcDeviceKey"
    value="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"/>

Close and save file. Now you can start VirtualBox and Run Virtual image of Mac OS X.

xml-settings-modification 

Installation of Mac OS X Snow Leopard on VirtualBox

Now you are ready to install Mac OS X Snow Leopard. After you run Virtual Machine installation should start. After than you need to create disc where you want to install Mac OS. Open Disk Utility under Utilities menu. Select the virtual disk and click Erase. Close it and you can now install OSX.

mac-os-x-start-installationmac-os-installation-step-1mac-os-x-disk-utilityerase-discmac-os-x-ready-to-installmac-os-x-installation-finished