Simple Jquery Tooltip

by wizbay 27. January 2011 17:13

Simple and easy to use jquery tooltip plugin from http://dev.mariusilie.net/content/simple-tooltip-jquery-plugin

How to use

$("#some-element").simpletooltip()
or
$("a.some-class").simpletooltip()

Caution

The text displayed in tooltip is the same as the TITLE attribute of the element.

Download

Click here to download the simpletooltip jquery plugin.

Additional Info

  • Tested with IE 6+, Firefox 3, Safari 4 and Opera 9
  • jQuery 1.3.2 (it should work with previous releases of jQuery, but I didn't test it) 

Changelog

v1.1

  • tooltip flips to the left/top of the cursor if it goes out of the screen. Now it is always displayed on the visible area

v1.0

  • display a tooltip on mouseover

Tags: , , ,

Jquery

IP / Port scan program with range

by wizbay 4. October 2010 20:03

Scan ip addresses with specified range and check for opened ports

ipscan.exe (108.50 kb)

Tags: , , , ,

General

Embed Video/Audio/Flash/PDF/sIFR/Html using JQuery Media plugin

by wizbay 11. September 2010 18:52

I found a good jquery plugin to embed media files.

Sample Usage - Video / Flash

Script:

$('a.media').media();

Markup:

<script type="text/javascript" src="jquery.metadata.js"></script> 
<script type="text/javascript" src="http://github.com/malsup/media/raw/master/jquery.media.js?v0.92"></script> 
 
... 
 
<a class="media {width:480, height:280}" href="http://malsup.github.com/video/simpsons.mov">MOV File (video)</a> 
<a class="media {width:250, height:250}" href="flash/curtain.flv">FLV File</a> 
<a class="media {width:250, height:250}" href="mediaplayer.swf?file=flash/curtain.flv">SWF with FLV (mediaplayer.swf?file=curtain.flv)</a> 
<a class="media {width:250, height:200}" href="flash/snail.swf">SWF File</a> 
<a class="media {width:450, height:380, type:'swf'}" href="http://youtube.com/v/TyvN59L4hJU">Youtube Video (SWF)</a> 
<a class="media {width:480, height:425}" href="http://malsup.github.com/video/ski.wmv">WMV File</a> 
<a class="media {width:300, height:300}" href="http://malsup.github.com/video/clear.avi">AVI File</a> 
<a class="media {width:250, height:150}" href="http://malsup.github.com/video/pulsar.mpg">MPG File</a> 
<a class="media {width:250, height:180}" href="http://malsup.github.com/video/tube.3g2">3G2 File (cell phone video)</a> 
<a class="media {width:400, height:250}" href="http://malsup.github.com/video/realvideo.ram">RAM File</a> 
<a class="media {width:650, height:500, caption: false}" href="flash/line.swf" id="lr">Line Rider!</a> 
Sample Usage - Audio
Script:
$('a.media').media( { width: 300, height: 20 } );

Markup:

<script type="text/javascript" src="jquery.metadata.js"></script> 
<script type="text/javascript" src="http://github.com/malsup/media/raw/master/jquery.media.js?v0.92"></script> 
 
... 
 
<a class="media"              href="audio/sample.au">AU File</a> 
<a class="media"              href="audio/sample.aac">AAC File</a> 
<a class="media"              href="audio/sample.aif">AIF File</a> 
<a class="media"              href="audio/sample.gsm">GSM File</a> 
<a class="media"              href="audio/velvet.mid">MIDI File</a> 
<a class="media"              href="audio/sample.mp3">MP3 File</a> 
<a class="media {height:80}"  href="audio/sample.rm">RM File</a> 
<a class="media"              href="audio/sample.wav">WAV</a> 
<a class="media {height:45}"  href="audio/sample.wma">WMA File</a>
 

Sample Usage - PDF / HTML

Script:

$('a.media').media({width:500, height:400});

Markup:

<script type="text/javascript" src="http://github.com/malsup/media/raw/master/jquery.media.js?v0.92"></script> 
<script type="text/javascript" src="jquery.metadata.js"></script> 
 
... 
 
<a class="media" href="guice.pdf">PDF File</a> 
<a class="media {type: 'html'}" href="../">HTML File</a> 

Visit http://jquery.malsup.com/media/#overview for more detail.

Download plugin script: jquery.media.js (15.08 kb)

Tags: , , , , , , ,

Jquery

ICO, CUR (Windows Icon / Cursor) file format plugin for Photoshop

by wizbay 10. September 2010 13:35

Download plugin for photoshop to create ico (windows icon) / cur (cursor) image.

 

Windows (standard ICO/favicon)

ICOFormat-1.6f9-win.zip (25.11 kb)

 

Windows (incl. Vista format icons)

ICOFormat-1.93b1-win.zip (145.93 kb)

 

Windows 64-bit (CS4, CS5 only)

ICOFormat-1.93b1-win64.zip (139.84 kb)

To install

  1. Move the plugin into the "File Formats" folder inside your Photoshop Plugins folder:
    • On Windows, ICOFormat.8bi
    • On OS X/Classic, icoformat (CS2/Mac version is ICOFormat_cs2.plugin)
    • On 68K MacOS, icoformat(68K)
  2. Quit and relaunch Photoshop, if it's already running.

To use the plugin

  • Use Photoshop's Open command (File menu) to open .ICO files (which will now appear in the file browser)
  • Use Photoshop's Save command to create .ICO files. 

 

Tags: , , , , , , ,

Photoshop

Custom Inherited DropDownList class in ASP.Net using SQL Stored Procedure

by wizbay 10. September 2010 13:28

 

Created a custom dropdownlist that is inherited from System.Web.UI.WebControls.DropDownList.

The class accepts an additional property (CCSdesc) to get data from lookup table in sql database. And the class calls a stored procedure to get lookup data (value and text).

Once you set up this class, you can just use <cc:DropDownList runat="server" ID="ddl_country" CCSdesc="country"></cc:DropDownList> without additional codes.


-----------------------Web.Config---------------------------------------
-- Register the class for whole application
    <pages>
      <controls>
        <add assembly="CustomControl" tagPrefix ="cc" namespace ="CustomControl"/>
      </controls>
    </pages>
-- Or you can just register the class in each aspx page
<%@ Register Assembly="CustomControl" Namespace="CustomControl" TagPrefix="cc" %>

-----------------------Default.aspx-------------------------------------
-- This is how you use a new dropdownlist
<cc:DropDownList runat="server" ID="ddl_country" CCSdesc="country"></cc:DropDownList>

-----------------------SQL Server table---------------------------------
CREATE TABLE [dbo].[Lookup](
 [LookupCategory] [varchar](20) NULL,
 [LookupCode] [varchar](50) NULL,
 [LookupShortDesc] [varchar](200) NULL,
 [LookupLongDesc] [varchar](500) NULL,
 [LookupSort] [varchar](10) NULL,
 [LookupSortDirection] [varchar](10) NULL,
 [LookupIcon] [varchar](50) NULL
) ON [PRIMARY]

--Sample Data--
LookupCategory LookupCode LookupShortDesc LookupLongDesc LookupSort LookupSortDirection LookupIcon
country                 VU Vanuatu                   NULL          1                ASC       NULL
country                 VE Venezuela                   NULL          2                ASC       NULL
country                 VN Vietnam                   NULL          3                ASC       NULL

------------------------Stored Procedure--------------------------------------
CREATE PROCEDURE [dbo].[sp_Dropdownlist]
 @LookupCategory varchar(50),
 @sort varchar(20) = null,
 @order varchar(10) = null
AS

BEGIN
 Declare @orderby varchar(50)
 IF (@order = 'desc')
 begin
 Select *
 From [lookup]
 where LookupCategory = @LookupCategory
 order by Case @sort When 'code' then LookupCode 
 When 'sort' then LookupSort 
 Else  LookupShortDesc end desc 
 end
 else
 begin
 Select *
 From [lookup]
 where LookupCategory = @LookupCategory
 order by Case @sort When 'code' then LookupCode 
 When 'sort' then LookupSort 
 Else LookupShortDesc end asc 
 end
END
-----------------------DropDownList.vb ----------------------
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient


Public Class DropDownList
    Inherits System.Web.UI.WebControls.DropDownList

    Dim _CCSdesc As String = String.Empty
    Public Property CCSdesc() As String
        Get
            Return _CCSdesc.ToLower
        End Get
        Set(ByVal Value As String)
            _CCSdesc = Value.ToLower
        End Set
    End Property

    Dim _CCSort As String = String.Empty
    Public Property CCSort() As String
        Get
            Return _CCSort.ToLower
        End Get
        Set(ByVal Value As String)
            _CCSort = Value.ToLower
        End Set
    End Property

    Dim _CCOrder As String = String.Empty
    Public Property CCOrder() As String
        Get
            Return _CCOrder.ToLower
        End Get
        Set(ByVal Value As String)
            _CCOrder = Value.ToLower
        End Set
    End Property

    Dim _CCShowDefault As Boolean = False
    Public Property CCShowDefault() As Boolean
        Get
            Return _CCShowDefault
        End Get
        Set(ByVal Value As Boolean)
            _CCShowDefault = Value
        End Set
    End Property

    Dim _CCShowDefaultText As String = "Please Select..."
    Public Property CCShowDefaultText() As String
        Get
            Return _CCShowDefaultText
        End Get
        Set(ByVal Value As String)
            _CCShowDefaultText = Value
        End Set
    End Property

    Dim _CCSelectedValue As String = String.Empty
    Public Property CCSelectedValue() As String
        Get
            Return _CCSelectedValue
        End Get
        Set(ByVal Value As String)
            _CCSelectedValue = Value
        End Set
    End Property

    Dim maxParams As Int16 = 3
    Dim paramIndex As Int16 = 0

    Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
        MyBase.OnPreRender(e)
        GetItems()
    End Sub

    Private Sub GetItems()
        If CCSort = String.Empty Then maxParams -= 1
        If CCOrder = String.Empty Then maxParams -= 1

        Dim param(maxParams - 1) As SqlParameter
        Dim sql As String = String.Empty

        sql = "sp_Dropdownlist"
        param(paramIndex) = New SqlParameter("@LookupCategory", CCSdesc)
        param(paramIndex).SqlDbType = SqlDbType.VarChar

        If CCSort <> String.Empty Then
            paramIndex += 1
            param(paramIndex) = New SqlParameter("@sort", CCSort)
            param(paramIndex).SqlDbType = SqlDbType.VarChar
        End If
        If CCOrder <> String.Empty Then
            paramIndex += 1
            param(paramIndex) = New SqlParameter("@order", CCOrder)
            param(paramIndex).SqlDbType = SqlDbType.VarChar
        End If

        Using db As New Database
            DataSource = db.ExecuteReader(sql, param)
            DataTextField = "LookupShortDesc"
            DataValueField = "LookupCode"
            DataBind()
        End Using

        If CCSelectedValue <> String.Empty AndAlso Not Me.Items.FindByValue(CCSelectedValue) Is Nothing Then
            SelectedValue = CCSelectedValue
        End If
    End Sub

    Private Sub DropDownList_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DataBound
        If CCShowDefault Then
            Me.Items.Insert(0, New ListItem(CCShowDefaultText, 0))
        End If
    End Sub
End Class

 

Tags: , , , , , , , ,

ASP.Net | SQL Server | VB.Net

How to use Captcha with ASP.NET

by wizbay 10. September 2010 13:14

I was trying to find a solution to block spammers adding data to our database using VB.Net.

Here's a good captcha image implementation. Easy and simple.

 

Default.aspx

<img src="JpegImage.aspx" alt="CAPTCHA IMAGE" title="Captcha Image" style="border:1px solid #c1c1c1; width:135px; height:26px;" />
<asp:TextBox runat="server" ID="txt_captcha" MaxLength="50" Width="125" CssClass="textbox" style="margin-top:15px;"></asp:TextBox>

<asp:CustomValidator ID="valCaptcha" runat="server" ControlToValidate="txt_captcha" ValidationGroup="signupVal" 
Display="Dynamic" OnServerValidate="valCaptcha_ServerValidate" CssClass="validator" ></asp:CustomValidator>

 

Default.aspx.vb

Protected Sub valCaptcha_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
        If txt_captcha.Text.Trim <> Me.Session("CaptchaImageText").ToString() Then
            args.IsValid = False
            valCaptcha.ErrorMessage = "The security code does not match. Try again."
        Else
            args.IsValid = True
        End If
End Sub

JpegImage.aspx // this doesn't really do anything. just for code behind.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="JpegImage.aspx.vb" Inherits="JpegImage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Captcha Image</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>
 

JpegImage.aspx.vb //You can resize image and font name here

Partial Class JpegImage
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Create a CAPTCHA image using the text stored in the Session object.
        If IsNothing(Me.Session("CaptchaImageText")) Then
            Me.Session("CaptchaImageText") = GetRandomNumber(3)
        End If

        Dim ci As CaptchaImage = New CaptchaImage(Me.Session("CaptchaImageText").ToString(), 135, 26, "Tahoma")

        ' Change the response headers to output a JPEG image.
        Me.Response.Clear()
        Me.Response.ContentType = "image/jpeg"

        ' Write the image to the response stream in JPEG format.
        ci.Image.Save(Me.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)

        ' Dispose of the CAPTCHA image object.
        ci.Dispose()
    End Sub
End Class

Function GetRandomNumber(ByVal length As Int16) As String
        Dim randomM As Random = New Random()

        Dim s As String = ""
        For i As Integer = 0 To length
            s = [String].Concat(s, randomM.[Next](10).ToString())
        Next
        Return s
End Function 

AppCode/CapchaImage.vb

Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Drawing.Text

''' <summary>
''' Summary description for CaptchaImage
''' </summary>
Public Class CaptchaImage
    '
    ' TODO: Add constructor logic here
    '
    Public Sub New()
    End Sub

    ' Public properties (all read-only).
    Public ReadOnly Property Text() As String
        Get
            Return Me.m_text
        End Get
    End Property
    Public ReadOnly Property Image() As Bitmap
        Get
            Return Me.m_image
        End Get
    End Property
    Public ReadOnly Property Width() As Integer
        Get
            Return Me.m_width
        End Get
    End Property
    Public ReadOnly Property Height() As Integer
        Get
            Return Me.m_height
        End Get
    End Property

    ' Internal properties.
    Private m_text As String
    Private m_width As Integer
    Private m_height As Integer
    Private familyName As String
    Private m_image As Bitmap

    ' For generating random numbers.
    Private random As New Random()

    ' ====================================================================
    ' Initializes a new instance of the CaptchaImage class using the
    ' specified text, width and height.
    ' ====================================================================
    Public Sub New(ByVal s As String, ByVal width As Integer, ByVal height As Integer)
        Me.m_text = s
        Me.SetDimensions(width, height)
        Me.GenerateImage()
    End Sub

    ' ====================================================================
    ' Initializes a new instance of the CaptchaImage class using the
    ' specified text, width, height and font family.
    ' ====================================================================
    Public Sub New(ByVal s As String, ByVal width As Integer, ByVal height As Integer, ByVal familyName As String)
        Me.m_text = s
        Me.SetDimensions(width, height)
        Me.SetFamilyName(familyName)
        Me.GenerateImage()
    End Sub
    Protected Overrides Sub Finalize()
        Try

            ' ====================================================================
            ' This member overrides Object.Finalize.
            ' ====================================================================
            Dispose(False)
        Finally
            MyBase.Finalize()
        End Try
    End Sub

    ' ====================================================================
    ' Releases all resources used by this object.
    ' ====================================================================
    Public Sub Dispose()
        GC.SuppressFinalize(Me)
        Me.Dispose(True)
    End Sub

    ' ====================================================================
    ' Custom Dispose method to clean up unmanaged resources.
    ' ====================================================================
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            Me.m_image.Dispose()
            ' Dispose of the bitmap.
        End If
    End Sub

    ' ====================================================================
    ' Sets the image width and height.
    ' ====================================================================
    Private Sub SetDimensions(ByVal width As Integer, ByVal height As Integer)
        ' Check the width and height.
        If width <= 0 Then
            Throw New ArgumentOutOfRangeException("width", width, "Argument out of range, must be greater than zero.")
        End If
        If height <= 0 Then
            Throw New ArgumentOutOfRangeException("height", height, "Argument out of range, must be greater than zero.")
        End If
        Me.m_width = width
        Me.m_height = height
    End Sub

    ' ====================================================================
    ' Sets the font used for the image text.
    ' ====================================================================
    Private Sub SetFamilyName(ByVal familyName As String)
        ' If the named font is not installed, default to a system font.
        Try
            Dim font As New Font(Me.familyName, 12.0F)
            Me.familyName = familyName
            font.Dispose()
        Catch ex As Exception
            Me.familyName = System.Drawing.FontFamily.GenericSerif.Name
        End Try
    End Sub

    ' ====================================================================
    ' Creates the bitmap image.
    ' ====================================================================
    Private Sub GenerateImage()
        ' Create a new 32-bit bitmap image.
        Dim bitmap As New Bitmap(Me.m_width, Me.m_height, PixelFormat.Format32bppArgb)

        ' Create a graphics object for drawing.
        Dim g As Graphics = Graphics.FromImage(bitmap)
        g.SmoothingMode = SmoothingMode.AntiAlias
        Dim rect As New Rectangle(0, 0, Me.m_width, Me.m_height)

        ' Fill in the background.
        Dim hatchBrush As New HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White)
        g.FillRectangle(hatchBrush, rect)

        ' Set up the text font.
        Dim size As SizeF
        Dim fontSize As Single = rect.Height + 1
        Dim font As Font
        ' Adjust the font size until the text fits within the image.
        Do
            fontSize -= 1
            font = New Font(Me.familyName, fontSize, FontStyle.Bold)
            size = g.MeasureString(Me.m_text, font)
        Loop While size.Width > rect.Width

        ' Set up the text format.
        Dim format As New StringFormat()
        format.Alignment = StringAlignment.Center
        format.LineAlignment = StringAlignment.Center

        ' Create a path using the text and warp it randomly.
        Dim path As New GraphicsPath()
        path.AddString(Me.m_text, font.FontFamily, CInt(font.Style), font.Size, rect, format)
        Dim v As Single = 4.0F
        Dim points As PointF() = {New PointF(Me.random.[Next](rect.Width) / v, Me.random.[Next](rect.Height) / v), New PointF(rect.Width - Me.random.[Next](rect.Width) / v, Me.random.[Next](rect.Height) / v), New PointF(Me.random.[Next](rect.Width) / v, rect.Height - Me.random.[Next](rect.Height) / v), New PointF(rect.Width - Me.random.[Next](rect.Width) / v, rect.Height - Me.random.[Next](rect.Height) / v)}
        Dim matrix As New Matrix()
        matrix.Translate(0.0F, 0.0F)
        path.Warp(points, rect, matrix, WarpMode.Perspective, 0.0F)

        ' Draw the text.
        hatchBrush = New HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray)
        g.FillPath(hatchBrush, path)

        ' Add some random noise.
        Dim m As Integer = Math.Max(rect.Width, rect.Height)
        For i As Integer = 0 To CInt((rect.Width * rect.Height / 30.0F)) - 1
            Dim x As Integer = Me.random.[Next](rect.Width)
            Dim y As Integer = Me.random.[Next](rect.Height)
            Dim w As Integer = Me.random.[Next](m / 50)
            Dim h As Integer = Me.random.[Next](m / 50)
            g.FillEllipse(hatchBrush, x, y, w, h)
        Next

        ' Clean up.
        font.Dispose()
        hatchBrush.Dispose()
        g.Dispose()

        ' Set the image.
        Me.m_image = bitmap
    End Sub
End Class

Tags: , , , , , , ,

ASP.Net | VB.Net

Generate a random alpha-numeric code with any length in VB.Net

by wizbay 10. September 2010 02:53

Simple function to Generate a random alpha-numeric code with any length in VB.Net

 

'Generate a random alpha-numeric code with any length.
    Shared Function GetRandomCode(ByVal length As Int16) As String
        Dim num_characters As Integer
        Dim i As Integer
        Dim txt As String = String.Empty
        Dim ch As Integer

        num_characters = length
        Randomize()

        For i = 1 To num_characters
            ch = Int((26 + 26 + 10) * Rnd())
            If ch < 26 Then
                txt = txt & Chr(ch + Asc("A"))
            ElseIf ch < 2 * 26 Then
                ch = ch - 26
                txt = txt & Chr(ch + Asc("a"))
            Else
                ch = ch - 26 - 26
                txt = txt & Chr(ch + Asc("0"))
            End If
        Next i

        Return txt
    End Function

Tags: , , , , , , ,

VB.Net

Function To Split By String Rather Just A Charactor In VB.Net

by wizbay 10. September 2010 02:51

Built-in "split" function in visual studio only allows a single charactor as delimeter.

Use this method to use string as a delimeter rather than a single charactor.

 

 'Split string with a string delimeter rather than just a charactor.
    Shared Function SplitByString(ByVal splitString As String, ByVal delimeter As String)
        Dim offset As Int16
        Dim index As Int16
        Dim offsets(splitString.Length) As Integer
        While index < splitString.Length
            Dim indexOf As Int16
            indexOf = splitString.IndexOf(delimeter, index)
            If indexOf <> -1 Then
                offsets(offset) = indexOf
                offset += 1
                index = (indexOf + delimeter.Length)
            Else
                index = splitString.Length
            End If
        End While
        Dim final(offset) As String
        If offset = 0 Then
            final(0) = splitString
        Else
            offset += -2
            final(0) = splitString.Substring(0, offsets(0))
            Dim i As Int16
            For i = 0 To offset
                final(i + 1) = splitString.Substring(offsets(i) + delimeter.Length, offsets(i + 1) - offsets(i) - delimeter.Length)
            Next
            final(offset + 2) = splitString.Substring(offsets(offset + 1) + delimeter.Length)
        End If
        Return final
    End Function

Tags: , , , ,

Function To Remove HTML Tags From String In .Net

by wizbay 10. September 2010 02:49

Following function remove all html tags using regular expressions and just return text string.

 

 'Remove HTML tags from string.
    Shared Function RemoveHTML(ByVal str As String) As String
        Return Regex.Replace(str, "<(.|\n)*?>", String.Empty)
    End Function

Tags: , , , , , , ,

ASP.Net | VB.Net

Function to parse querystring into nameValueCollection in VB.Net

by wizbay 10. September 2010 02:46

Use following function to parse querystring into nameValueCollection and easily retrieve its values using parameter names.

 

 

'Get URL with querystring and parse it into NameValueCollection with keys and names.
    Shared Function ParseQueryString(ByVal url As String)
        Dim queryStringBegin As Integer = url.IndexOf("?")
        Dim queryString As String = url.Substring(queryStringBegin + 1)
        Dim nvc As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection
        Dim sections() As String = queryString.Split("&")
        For Each section As String In sections
            Dim pair() As String = section.Split("=")
            nvc.Add(pair(0).ToString, pair(1).ToString)
        Next
        Return nvc
    End Function

Tags: , , , , ,

ASP.Net | VB.Net