Skip to content

Instantly share code, notes, and snippets.

View kmlprtsng's full-sized avatar

Kamalpreet Singh Chauhan kmlprtsng

View GitHub Profile
@kmlprtsng
kmlprtsng / json_guide.js
Created November 27, 2013 14:14
JSON Guide
//JSON is supported in IE8+. Otherwise use Json2 or something library
//to convert from json string
JSON.parse(jsonString); //or
jQuery.parseJSON( jsonString );
//JSON to string
JSON.stringify({ attestationId: attestationId, haveReadDoc: haveReadDoc, willComply: willComply }),
//Would delete all the files in a directory.
protected void DeleteFiles()
{
FileInfo[] files = new DirectoryInfo(Server.MapPath(WebConfig.ProfilePhotoPath)).GetFiles(WebConfig.ProfilePhotoPrefix + "*" + User.ID + ".*");
foreach (FileInfo file in files)
{
try
{
file.Delete();
}
@kmlprtsng
kmlprtsng / asp_ctrl_ddl.html
Created October 18, 2013 09:52
Dropdown with All / Select option apended
<asp:DropDownList runat="server" ID="SomeDropDown" AutoPostBack="true"
DataTextField="FirstName" DataValueField="Id" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="-1" />
</asp:DropDownList>
@kmlprtsng
kmlprtsng / js_cancelClick.js
Created October 14, 2013 08:55
Cancel Hyperlink click
//<a href="#" onClick="return false;"> //Most accepted Solution
//<a href="javascript:void(0)"> ... </a> //Problem: breaks when linking images in IE
//return this from the method.
return false;
//or using jquery
e.stopPropagation(); //stop the event from bubbling
e.preventDefault(); // stop the default functionality
@kmlprtsng
kmlprtsng / sql_reset_seed_value.sql
Created October 8, 2013 21:03
Add id manually in column with Identity and reset seed value
--http://www.sqlteam.com/article/how-to-insert-values-into-an-identity-column-in-sql-server
SET IDENTITY_INSERT IdentityTable ON
INSERT IdentityTable(TheIdentity, TheValue) VALUES (3, 'First Row')
SET IDENTITY_INSERT IdentityTable OFF
--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.
--This SEED should get updated itself if any Id higher than the seed is used
@kmlprtsng
kmlprtsng / scorm_api_map.txt
Created September 25, 2013 09:27
SCORM 1.2 LMS methods mapped to SCORM 2004 API
Changes to API Methods
SCORM1.2 SCORM2004
LMSInitialize(“”) Initialize(“”)
LMSFinish(“”) Terminate(“”)
LMSGetValue(parameter) GetValue(parameter)
LMSSetValue(parameter_1,parameter_2) SetValue(parameter_1,parameter_2)
LMSCommit(“”) Commit(“”)
LMSGetLastError() GetLastError()
LMSGetErrorString(parameter) GetErrorString(parameter)
LMSGetDiagnostic(parameter) GetDiagnostic(parameter)
@kmlprtsng
kmlprtsng / sql_column_case_sensitive.sql
Created September 10, 2013 10:29
Make Column Case Sensitive
-- For SQL Server 2005 and above
ALTER TABLE Foo ALTER COLUMN Bar ntext COLLATE Latin1_General_CS_AS
@kmlprtsng
kmlprtsng / linq_keyword_search.cs
Created September 6, 2013 15:26
Keyword search
if (Keywords.Trim().Length > 0)
{
string[] keywordFilterArr = Keywords.Split(' ');
query = keywordFilterArr.Where(str => str.Trim().Length > 0)
.Aggregate(query, (current, str) => current.Where(u => u.FirstName.Contains(str) || u.LastName.Contains(str)));
}
@kmlprtsng
kmlprtsng / asp_checkboxlist_all_selected_items.cs
Created September 6, 2013 11:08
Checkboxlist - get all selected items
chkBoxList.Items.Cast<ListItem>()
.Where(i => i.Selected)
.Select(i => int.Parse(i.Value));
@kmlprtsng
kmlprtsng / asp_register_control_page.html
Created September 3, 2013 17:03
Register namespaces and controls for web pages
<%@ Register TagPrefix="scott" TagName="footer" Src="Controls/Footer.ascx" %>