Skip to content

Instantly share code, notes, and snippets.

View kmlprtsng's full-sized avatar

Kamalpreet Singh Chauhan kmlprtsng

View GitHub Profile
@kmlprtsng
kmlprtsng / Flash_Fallback_Audio_HTML5
Created August 14, 2013 09:06
HTML5 audio player with flash fallback - Styling using AudioPlayer()
<!--http://www.hanselman.com/blog/FallbackHTML5AudioTagsForASimpleMP3PodcastAreHarderThanYoudThink.aspx-->
<script>
<audio id="audioplayer" preload="auto" controls style="width:100%;" >
<source src="your.mp3" type="audio/mp3">
Your browser doesn't support the HTML audio tag. You can still download the show, though!
</audio>
<p id="audioplayer_1"></p>
<script type="text/javascript">
var audioTag = document.createElement('audio');
@kmlprtsng
kmlprtsng / jQuery_ajax_call_web_method
Last active December 21, 2015 01:38
JQuery to make an Ajax call to ASP.NET webmethod
/*For more details see http://encosia.com/using-jquery-to-consume-aspnet-json-web-services */
/*c# Method must be static and be decorated with [WebMethod] Attribute*/
$.ajax({
type: "POST",
url: "Default.aspx/GetEvents",
data: "{month : 1, year : 1}",
//Or data: JSON.stringify({month:1}),
contentType: "application/json; charset=utf-8",
dataType: "json", //Return Type of data
@kmlprtsng
kmlprtsng / js_url_parser
Created August 14, 2013 09:10
Parsing URL into different bits
//Taken from: http://tutorialzine.com/2013/07/quick-tip-parse-urls/
$(function(){
// The URL we want to parse
var url = 'http://tutorialzine.com/2013/07/quick-tip-parse-urls/?key=value#comments';
// The magic: create a new anchor element, and set the URL as its href attribute.
// Notice that I am accessing the DOM element inside the jQuery object with [0]:
var a = $('<a>', { href:url } )[0];
@kmlprtsng
kmlprtsng / js_safe_submit
Created August 14, 2013 09:12
Safe Submit Button
//http://www.codeproject.com/Tips/581356/Safe-Submit-Button
<input type="submit" name="Submit" value="Submit"
önclick = "this.value='Please wait...'; this.disabled=true; this.form.submit();" />
@kmlprtsng
kmlprtsng / jquery_plugin_skeleton
Created August 14, 2013 09:14
Skeleton for jQuery plugin
// Utility
if (typeof Object.create !== 'function') {
Object.create = function(obj) {
function F() { };
F.prototype = obj;
return new F();
};
}
@kmlprtsng
kmlprtsng / sass_calc_em_size
Created August 14, 2013 09:15
Calculate em-size Sass
@function em($target, $context: $base-font-size) {
@return ($target / $context) * 1em;
}
// Usage:
font-size: em(18px);
// Go up to 18 px font size when in a 14 px context
font-size: em(18px, 14px);
@kmlprtsng
kmlprtsng / sql_server_taking_db_offline
Created August 14, 2013 09:16
SQL Server - Taking DB Offline to delete
use master;
Go
alter database [TestNew] set single_user with rollback immediate;
GO
alter database [TestNew] modify name = Test ;
@kmlprtsng
kmlprtsng / asp_net_injecting_js
Created August 14, 2013 14:23
Injecting Javascript from Code Behind - for multiple postbacks using update panels as well
//To Inject JS after async postback
ScriptManager.RegisterStartupScript(this, this.GetType(), "AlertMessage", "alert('Hello World');", true);
//To Inject JS for multiple postbacks use ?? not tested. Maybe this has to be injected only once.
ScriptManager.RegisterStartupScript(UpdatePanelName, typeof(string), "ShowPopup", "alert('Hello World');", true);
@kmlprtsng
kmlprtsng / mvc_export_excel_and_csv
Created August 14, 2013 14:41
Export to CSV and Excel in MVC
//http://adambielecki.blogspot.co.uk/2013/05/exporting-data-to-excel-and-csv-in.html
public void ExportClientsListToCSV()
{
StringWriter sw = new StringWriter();
sw.WriteLine("\"First Name\",\"Last Name\",\"Email\"");
Response.ClearContent();
@kmlprtsng
kmlprtsng / asp_get_base_url.cs
Created August 14, 2013 14:54
Get Base URL or a part of URL
//*************** Solution 1 **************/
// http://forums.asp.net/t/1466607.aspx/1
//http://forums.asp.net/t/1383898.aspx
//would return http://localhost:2013 or http://localhost:2013/ApplicationPath
return string.Format("{0}://{1}{2}",
HttpContext.Current.Request.Url.Scheme,
HttpContext.Current.Request.ServerVariables["HTTP_HOST"],