Skip to content

Instantly share code, notes, and snippets.

View howarddierking's full-sized avatar

Howard Dierking howarddierking

View GitHub Profile
@howarddierking
howarddierking / gist:2869457
Created June 4, 2012 16:39
Bundle registration for custom transform in VS 2012 RC
var lessBundle = new Bundle("~/My/Less").IncludeDirectory("~/My", "*.less");
lessBundle.Transforms.Add(new LessTransform());
lessBundle.Transforms.Add(new CssMinify());
bundles.Add(lessBundle);
@howarddierking
howarddierking / gist:2869451
Created June 4, 2012 16:38
Custom LESS bundle transform
public class LessTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
response.Content = dotless.Core.Less.Parse(response.Content);
response.ContentType = "text/css";
}
}
@howarddierking
howarddierking / gist:2869445
Created June 4, 2012 16:36
Bundle registration in VS 2012 RC
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
@howarddierking
howarddierking / gist:2869437
Created June 4, 2012 16:35
Bundle registration in VS 2012 Beta
bundle = new Bundle("~/Content/themes/base/css", csstransformer);
bundle.AddFile("~/Content/themes/base/jquery.ui.core.css", true);
bundle.AddFile("~/Content/themes/base/jquery.ui.resizable.css", true);
bundle.AddFile("~/Content/themes/base/jquery.ui.selectable.css", true);
bundle.AddFile("~/Content/themes/base/jquery.ui.accordion.css", true);
bundle.AddFile("~/Content/themes/base/jquery.ui.autocomplete.css", true);
bundle.AddFile("~/Content/themes/base/jquery.ui.button.css", true);
bundle.AddFile("~/Content/themes/base/jquery.ui.dialog.css", true);
bundle.AddFile("~/Content/themes/base/jquery.ui.slider.css", true);
bundle.AddFile("~/Content/themes/base/jquery.ui.tabs.css", true);
@howarddierking
howarddierking / chainedBundleTransform.cs
Created March 8, 2012 03:20
example of a chained bundle transform using less
protected void Application_Start()
{
//...
Bundle cssBundle = new Bundle("~/Content/css", new LessTransform().Then(new CssMinify()));
cssBundle.AddFile("~/Content/site.css", throwIfNotExist: false);
cssBundle.AddDirectory("~/Content/", "jquery.mobile*", searchSubdirectories: false, throwIfNotExist: false);
BundleTable.Bundles.Add(cssBundle);
//...
public HttpResponseMessage<IEnumerable<Bug>> Post(JsonObject formData) {
dynamic data = formData.AsDynamic();
var bug = new Bug
{
Name = data.name,
Priority = data.priority,
Rank = data.rank,
};
_bugRepository.Add(bug);
@howarddierking
howarddierking / WCFNet45AsyncService.cs
Created November 30, 2011 19:46
WCF 4.5 Async Service Operation
public async Task<double> CalculateShippingSubtotalAsync(int productID, string postalCode)
{
var productServiceProxy = new ProductServiceClient();
var shippingServiceProxy = new ShippingServiceClient();
var t = productServiceProxy.GetProductByIDAsync(productID);
var t2 = shippingServiceProxy.GetShippingCostForPostalCodeAsync(postalCode);
await Task.WhenAll(t, t2);
@howarddierking
howarddierking / InvalidAsyncServiceContract.cs
Created November 30, 2011 19:38
Invalid WCF async service contract
[ServiceContractAttribute(Namespace = "http://microsoft.samples")]
public interface ISampleService
{
[OperationContractAttribute]
string SampleMethod(string msg);
[OperationContractAttribute(AsyncPattern = true)]
IAsyncResult BeginSampleMethod(string msg, AsyncCallback callback,
object asyncState);
@howarddierking
howarddierking / RegistrationHelpers.cs
Created October 12, 2011 03:47
Web API helper extension methods for OAuth registration
public static void RegisterOAuth(this HttpConfiguration config, FacebookOAuthClient client) {
var existingFactory = config.RequestHandlers;
config.RequestHandlers = (c, e, od) => {
if (existingFactory != null)
existingFactory(c, e, od);
var authorizeAttribute = od.Attributes.OfType<AuthorizeAttribute>().FirstOrDefault();
if (authorizeAttribute == null) return;
if (od.Name == "GetCommentsOauth") {
@howarddierking
howarddierking / OAuthFacebookMessageHandler.cs
Created October 12, 2011 03:35
Web API Message Handler for processing Facebook OAuth2 auth code responses
public class OAuthFacebookMessageHandler : DelegatingHandler
{
static readonly Uri FacebookBaseGraphUri = new Uri("https://graph.facebook.com/me");
static readonly Uri FacebookAccessTokenBaseUri = new Uri("https://graph.facebook.com/oauth/access_token");
readonly string _facebookAppId;
readonly string _facebookAppSecret;
public OAuthFacebookMessageHandler(string appId, string secret) {
_facebookAppId = appId;
_facebookAppSecret = secret;