Skip to content

Instantly share code, notes, and snippets.

@umair-me
umair-me / next_identity.sql
Last active December 26, 2015 20:59
Get next identity key id
USE DATABASENAME
GO
SELECT IDENT_CURRENT('TABLENAME') + IDENT_INCR('TABLENAME')
@umair-me
umair-me / new_gist_file
Created October 24, 2013 15:56
convert timespan to readable string format
public static string ToReadableString(this TimeSpan span)
{
string formatted = string.Format("{0}{1}{2}{3}",
span.Duration().Days > 0 ? string.Format("{0:0} day{1}, ", span.Days, span.Days == 1 ? String.Empty : "s") : string.Empty,
span.Duration().Hours > 0 ? string.Format("{0:0} hour{1}, ", span.Hours, span.Hours == 1 ? String.Empty : "s") : string.Empty,
span.Duration().Minutes > 0 ? string.Format("{0:0} minute{1}, ", span.Minutes, span.Minutes == 1 ? String.Empty : "s") : string.Empty,
span.Duration().Seconds > 0 ? string.Format("{0:0} second{1}", span.Seconds, span.Seconds == 1 ? String.Empty : "s") : string.Empty);
if (formatted.EndsWith(", ")) formatted = formatted.Substring(0, formatted.Length - 2);
@umair-me
umair-me / new_gist_file
Created October 24, 2013 14:55
time timespan in words - return relative time between two given dates
public string TimespanInWords(DateTime oDtTo, DateTime oDtFrom)
{
TimeSpan oTs = oDtTo >= oDtFrom ? oDtTo - oDtFrom : oDtFrom - oDtTo;
if (oTs.TotalSeconds < 30)
return "less than a minute";
if (oTs.TotalSeconds < 90)
return "1 minute";
if (oTs.TotalSeconds < 44 * 60 + 30)
return (int)oTs.TotalMinutes + " minutes";
if (oTs < new TimeSpan(0, 89, 30))
@umair-me
umair-me / new_gist_file
Created October 23, 2013 22:16
Migrate or Clone tfvc tfs to git using git-tfs
http://gitstack.com/how-to-migrate-from-tfs-to-git/
http://stackoverflow.com/questions/19548659/migrate-from-tfs-to-git-on-visualstudio-com/19550144
git-tfs clone --username=mumair85 --password=xxxx https://mumair85.visualstudio.com/DefaultCollection $/uGen
After that clone the new repository or Push an existing repository
From Visual Studio
You can Push a repository after connecting with Team Explorer and adding the Git repo to your list of Local Git Repositories.
AjaxJsonPostCall = function (fullUrl, dataObj, callbackFunction) {
$.ajax({
type: 'post',
url: fullUrl,
data: JSON.stringify(dataObj),
dataType: 'json',
cache: false,
success: function (data) { callbackFunction(GetJson(data)); },
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("error :" + XMLHttpRequest.responseText);
@umair-me
umair-me / gist:6933583
Created October 11, 2013 12:05
List of datetime strings
From: http://www.csharp-examples.net/string-format-datetime/
String Format for DateTime [C#]
This example shows how to format DateTime using String.Format method. All formatting can be done also using DateTime.ToString method.
Custom DateTime Formatting
There are following custom format specifiers y (year), M (month), d (day), h (hour 12), H (hour 24), m (minute), s (second), f (second fraction), F (second fraction, trailing zeroes are trimmed), t (P.M or A.M) and z (time zone).
@umair-me
umair-me / ReplaceStringSQL.sql
Created October 1, 2013 15:17
Replace string in SQL database via sql query
UPDATE TableName
SET DBTextField = REPLACE(CAST(DBTextField AS varchar(MAX)), 'SearchText', 'ReplaceText')
FROM TableName
WHERE CHARINDEX('SearchText', CAST(DBTextField as varchar(MAX))) > 0
Example:
UPDATE [database].[dbo].[table]
SET [column_name] = REPLACE(CAST([column_name] AS varchar(MAX)), 'OLD_WORD', 'NEW_WORD')
FROM [database].[dbo].[table]
@umair-me
umair-me / new_gist_file
Created October 1, 2013 13:15
recaptcha not working in asp.net
protected void Button1_Click(object sender, EventArgs e)
{
Page.Validate(); <--- you need this
if (Page.IsValid)
{
lblResult.Text = "All Good";
}
else
{
lblResult.Text = "The words you entered are incorrect";
@umair-me
umair-me / gist:6699851
Created September 25, 2013 13:47
Random MVC Stuff
http://www.codeproject.com/Articles/657264/Couple-of-not-so-different-approaches-to-paging-in
http://www.codeproject.com/Articles/533932/Custom-ASP-NET-MVC-ActionResults
@umair-me
umair-me / new_gist_file
Created September 25, 2013 13:47
Reset Identity Column value SQL Server
DBCC CHECKIDENT (tableName, RESEED, 10)
Note that the next value will be whatever you reseed with + 1, so in this case I set it to 10 so that the next value will be 11.