This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note: Install WebEssentials for VisualStudio 2012 | |
// Add the TypeScript properties to the debug & release compile groups | |
// For example: <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
<TypeScriptTarget>ES5</TypeScriptTarget> | |
<TypeScriptRemoveComments>false</TypeScriptRemoveComments> | |
<TypeScriptSourceMap>true</TypeScriptSourceMap> | |
<TypeScriptModuleKind>AMD</TypeScriptModuleKind> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WebRequestHandler handler = new WebRequestHandler() | |
{ | |
UseProxy = true, | |
}; | |
var client = new HttpClient(handler); | |
client.BaseAddress = new Uri("https://api.github.com/"); | |
// You should set the version so that GitHub knows what API you area calling | |
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sometimes the compiler will try to statically type-check when you don't want it to. | |
// TODO: I need to get a better example in here. | |
// This extension method to object makes the static type checker give up through the use of a generic method that does the casting. | |
public static T CastAs<T>(this object value) | |
{ | |
return (T)value; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private _getErrorMessage(jqXHR: JQueryXHR, textStatus, errorThrown): string { | |
var message = textStatus + ' ' + errorThrown; | |
var error = <any>$.parseJSON(jqXHR.responseText); | |
if (error) { | |
message = error.Message; | |
if (error.ExceptionMessage) { | |
message += error.ExceptionMessage; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void SetJsonSerializerDefaults() | |
{ | |
// I set the default JSON setting to provide camel-cased properties | |
JsonConvert.DefaultSettings = () => new JsonSerializerSettings() | |
{ | |
ReferenceLoopHandling = ReferenceLoopHandling.Ignore, | |
ContractResolver = new CamelCasePropertyNamesContractResolver() | |
}; | |
// I set the web API serializer for JSON to use JsonConverts default settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This attribute helps return exception text from web API methods when applied to a MVC Web API controller. | |
public class HandleWebApiErrorAttribute : ExceptionFilterAttribute | |
{ | |
public override void OnException(HttpActionExecutedContext context) | |
{ | |
var exception = context.Exception as Exception; | |
if (exception != null) | |
{ | |
var message = exception.Message; | |
message = message.Replace('\r', ' ').Replace('\n', ' '); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scaleFontToFit(element) { | |
if (element) { | |
// for an element | |
var $element = $(element); | |
if ($element.css("overflow") == "hidden") { | |
var elementHeight = $element.height(); | |
var fontSize = parseInt($element.css("font-size"), 10); | |
var $fullElement = $(element).clone().css('overflow', 'visible').height('auto'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static object ApplyDefaultData(object data, object defaultData) | |
{ | |
if (defaultData != null) | |
{ | |
var target = new ExpandoObject(); | |
// I apply the default values | |
string defaultJson = JsonConvert.SerializeObject(defaultData, _jsonSerializerSettings); | |
JsonConvert.PopulateObject(defaultJson, target, _jsonSerializerSettings); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void Application_BeginRequest() | |
{ | |
this.SetupCorsHeaders(); | |
//OPTIONS request comes before the POST to know the permissions. this forces to send the reply. | |
if (((IList)Request.Headers.AllKeys).Contains("Origin") && Request.HttpMethod == "OPTIONS") | |
{ | |
Response.Flush(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It may be worth making a copy of the element within <body> that is hidden | |
// or even producing a section of items to copy. | |
// This way you can remove any interactivity styles that make the copied content not | |
// look good when pasted into other applications. | |
var element = document.getElementById('ClipboardTemp'); | |
// This technique is simulating the user selecting these elements. | |
// Think of a ControlRange as a selection of controls and then executing the command like the user pressing 'Ctrl+C' | |
element.contentEditable = 'true'; | |
var controlRange; |
OlderNewer