Showing posts with label Codes. Show all posts
Showing posts with label Codes. Show all posts

Tuesday, March 05, 2024

How to check if string exists in JQuery

In jQuery, you can use the indexOf method to check if a string contains another string. Here's an example:

var mainString = "Hello, world";
var subString = "world";

if (mainString.indexOf(subString) !== -1) {
    // subString is found in mainString
    console.log("Substring found");
} else {
    // subString is not found in mainString
    console.log("Substring not found");
}
  

In this example, the indexOf method returns the index of the first occurrence of the subString within the mainString. If the subString is not found, indexOf returns -1. You can use this to check if a string contains another string in jQuery.

Monday, January 09, 2017

Top 20 Developer Tools of 2016

Here are the list of top 20 Developer utilities that are must to have for Developer.

  1. GitKraken: The downright luxurious Git GUI client for Windows, Mac, and Linux.
  2. Atom: A hackable text editor for the 21st Century.
  3. VS Code: A free, lightweight tool for editing and debugging web apps.
  4. Git: A free and open source distributed version control system.
  5. GitHub: A web-based Git repository hosting service.
  6. Visual Studio: Developer tools and services for any platform with any language.
  7. Sublime Text: A sophisticated text editor for code, markup, and prose.
  8. Chrome DevTools: A set of web authoring and debugging tools built into Google Chrome.
  9. Docker :An open platform for developers and system administrators to build, ship, and run distributed applications.
  10. GitLab: Git repository management, code reviews, issue tracking, activity feeds, and wikis.
  11. IntelliJ IDEA: A Java IDE.
  12. PhpStorm : A commercial, cross-platform IDE for PHP.
  13. Postman: A powerful GUI platform to make your API development faster & easier.
  14. ReSharper : A Visual Studio extension for .NET developers.
  15. Slack: Real-time messaging, archiving, and search for modern teams.
  16. PyCharm: An IDE used specifically for Python.
  17. Android Studio: The official IDE for Android platform development.
  18. Notepad++: A free source code editor which supports several programming languages running under the MS Windows environment.
  19. Xcode : an IDE for macOS/and iOS development.
  20. Stack Overflow: The largest online community for programmers to learn, share their knowledge, and advance their careers.

Tuesday, November 17, 2015

TextBox set to ReadOnly using javascript

Here is a quick solution that works across the all browsers. Add below code in input textbox.

onKeyPress = "javascript: return false;" onPaste = "javascript: return false;" .

That way, even the textbox is enabled, the user will not be able to modify the data

Friday, July 20, 2012

C#: How to Get Machine name of the webserver

Here is how you can do using C#,

Response.Write("machinename " +System.Environment.MachineName +"<BR>" )


This gives you name computer where your webserver is located.


If you need with the domain name here is how you can achieve using the following code snippet:


You need to import following namespace to use this,


using System.Net; 


public static string GetServerMachineName()
{
string domainName = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
string hostName = Dns.GetHostName();
string sysdn = "";
if (!hostName.Contains(domainName))
sysdn = hostName + "." + domainName;
else
sysdn = hostName;

return sysdn;
}

Happy Coding Smile

Thursday, February 02, 2012

How to: change DB owner name using T-SQL

Here is how you can do it using SQL Statement.

Method 1:

Using this method first we’ll get all the db objects and update with new db owner name.

DECLARE tabcurs CURSOR
FOR
SELECT 'olddbowner.' + [name]
FROM sysobjects
WHERE xtype = 'u'

OPEN tabcurs
DECLARE @tname NVARCHAR(517)
FETCH NEXT FROM tabcurs INTO @tname

WHILE @@fetch_status = 0
BEGIN

EXEC sp_changeobjectowner @tname, 'dbo'

FETCH NEXT FROM tabcurs INTO @tname
END
CLOSE tabcurs
DEALLOCATE tabcurs



Method 2:


This approach is simple and straight forward. Using this we will build the statements and you can copy them from the result window and execute


declare @OldOwner varchar(100) declare @NewOwner varchar(100) 
set @OldOwner = '353446_eda_db'
set @NewOwner = 'dbo'


SELECT 'sp_changeobjectowner ''[' + s.name + '].[' + p.name + ']'', ''' + @NewOwner + '''
GO'

FROm sys.Procedures p INNER JOIN
sys.Schemas s on p.schema_id = s.schema_id WHERE s.Name = @OldOwner
union
select 'sp_changeobjectowner ''[' + table_schema + '].[' + table_name + ']'', ''' + @NewOwner + '''
GO'

from information_schema.tables where Table_schema = @OldOwner


Hope this helps.

Wednesday, November 02, 2011

Regex validate Email address C#

This is how we can validating email address through C# using Regular Expression. Here is the sample code,

using System.Text.RegularExpressions;



public bool vaildateEmail(string useremail)
{
bool istrue = false;
Regex reNum = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
CaptureCollection cc = reNum.Match(useremail).Captures;
if (cc.Count == 1)
{
istrue = true;
}
return istrue;
}

How to get current page Filename using C#

There are different ways to get current page filename using c#. Here are 3 methods you can use for your advantage.

Method 1
string currentPageFileName = new FileInfo(this.Request.Url.LocalPath).Name;

Method 2

string sPath = HttpContext.Current.Request.Url.AbsolutePath;
string[] strarry = sPath.Split('/');
int lengh = strarry.Length;
string sReturnPage = strarry[lengh - 1];

Method 3

string absPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo finfo = new System.IO.FileInfo(absPath);
string fileName = finfo.Name;

 

Out of these I like Method 1 and 3 as its straight forward. Use a per your advantage. Good luck.

Saturday, September 10, 2011

Convert DateTime values to W3C DateTime format in C#

ConvertDateToW3CTime() function takes a C# DateTime value and converts it to a W3C formatted date/time value.
The function works by first converting the date/time parameter to a UTC (Coordinated Universal Time) value and formatting it. It then appends the UTC offset time to the previously formatted string.

The T placed between the date and time simply indicates that the numbers following it are Time values. The UTC offset can be one 3 states, zero e.g. there is not difference in time between the UTC value and the local value. A zero value is identified by simply appending the letter Z to the end of the formatted datetime value. If the offset time is greater than 0 then it is preceded with a + sign, e.g. 2 hours and 30 minutes over the UTC time would be written as +02:30. If the offset is less than the UTC value then it is preceded with a sign e.g. -01:00.

/// <summary>
/// Converts a datetime value to w3c format
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static string ConvertDateToW3CTime(DateTime date)
{
//Get the utc offset from the date value
var utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(date);
string w3CTime = date.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss");
//append the offset e.g. z=0, add 1 hour is +01:00
w3CTime += utcOffset == TimeSpan.Zero ? "Z" :
String.Format("{0}{1:00}:{2:00}", (utcOffset > TimeSpan.Zero ? "+" : "-")
, utcOffset.Hours, utcOffset.Minutes);

return w3CTime;
}



Here is an example, how to use it


ConvertDateToW3CTime(DateTime.Now);
//Output 2011-10-17T19:10:48+01:00

Friday, February 18, 2011

Microsoft Code Samples for Developers

This code sample library will help all developers to find useful code in various dot net areas. Microsoft goal is to centralized all codes in one place. This library having below things:

  • Microsoft All-in-One Code Framework: Free, centralized code sample library
    • Code Samples
    • Services
  • Microsoft SDKs: provide documentation, code samples, tools etc..
  • MSDN Code Gallery:  download and share sample applications, code snippets and other resources.

You can download it from here

Sunday, December 05, 2010

Javascript Tip: Close Pop-up - Refresh Parent

Sometimes we need to force parent refresh on closing pop-up window which was opened from this parent window. There are many ways to make it work, however the most elegant way will be using location.href

function Refresh() 
{
    window.opener.location.href = window.opener.location.href;
    window.close();
}

Smile

Saturday, October 16, 2010

Date Formatting in C#

Date formatting in C# using string object

Specifier Description Output
d Short Date 20/10/1983
D Long Date 20 October 1983
t Short Time 21:20
T Long Time 21:20:59
f Full date and time 20 October 1983 21:20
F Full date and time (long) 20 October 1983 21:20:59
g Default date and time 20/10/1983 21:20
G Default date and time (long) 20/10/1983 21:20:59
M Day / Month 20 October
r RFC1123 date Thu, 20 Apr 1983 21:20:59 GMT
s Sortable date/time 1983-10-20T21:20:59
u Universal time, local timezone 1983-10-20 21:20:59Z
Y Month / Year October 1983
dd Day 20
ddd Short Day Name Thu
dddd Full Day Name Thursday
hh 2 digit hour 09
HH 2 digit hour (24 hour) 21
mm 2 digit minute 20
MM Month 10
MMM Short Month name Apr
MMMM Month name October
ss seconds 59
tt AM/PM PM
yy 2 digit year 07
yyyy 4 digit year 1983
: seperator, e.g. {0:hh:mm:ss} 09:20:59
/ seperator, e.g. {0:dd/MM/yyyy} 20/10/1983

Example using the specifier with data object

DateTime now = DateTime.Now;
Console.WriteLine(now.ToString("d"));

Monday, October 04, 2010

JavaScript: Display Clock

Displaying a clock is very similar to making a countdown timer. All we have to do is to create a new date and get it's hours, minutes, and seconds.

Here is a example:

<!-- This span is where the clock will appear -->
<div id='clockDiv'></div>
<script type="text/javascript">
function clock() {
   var now = new Date();
   var outStr = now.getHours()+':'+now.getMinutes()+':'+now.getSeconds();
   document.getElementById('clockDiv').innerHTML=outStr;
   setTimeout('clock()',1000);
}
clock();
</script>

Hope this helps :-)

JavaScript: Count down Timer

This is how creating Count down timer using JavaScript with Julian dates. This code below creates two Julian dates, now and newYear. By subtracting now from newYear we get an integer which represents the difference between the two dates.

Suppose you want to know your birthday in days, hours and minutes etc. This is how you can achieve using JavaScript.

<!-- This span is where the countdown timer will appear -->
<div id='countdown'></div>
<script type="text/javascript">
// Here's our countdown function.
function happyBirthDay() {
var now = new Date();
var newYear = new Date('October 20, '+(now.getFullYear()+1));
var diff=newYear-now;
var milliseconds=Math.floor(diff % 1000);   
    diff=diff/1000;            
var seconds=Math.floor(diff % 60);
    diff=diff/60;
var minutes=Math.floor(diff % 60);
    diff=diff/60;
var hours=Math.floor(diff % 24);
    diff=diff/24;
var days=Math.floor(diff);
// We'll build a display string instead of doing document.writeln
   var outStr = days + ' days, ' + hours+ ' hours, ' + minutes;
       outStr+= ' minutes, ' + seconds + ' seconds until your birthday!'; 
   // Insert our display string into the countdown span.
   document.getElementById('countdown').innerHTML=outStr;
   // call this function again in exactly 1 second.   
   setTimeout("happyBirthDay()",1000);
}
// call the countdown function (will start the timer)
happyBirthDay();   
</script>

Hope this helps!

Saturday, October 02, 2010

HTML Codes - Characters and symbols

I have found collection of information about HTML codes, ASCII Codes, URL Encoding, URL Decoding which is helpful.

Check this URL for more information.