Skip to content

Instantly share code, notes, and snippets.

@OndeVai
OndeVai / BindModelUnknownKey.cs
Created January 27, 2012 00:09
Asp.net MVC - bind to a Model even without knowing key in value provider
public class SelectedColumIDsModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
//bind up the object using the base method
var queryRequest = (QueryRequest) base.BindModel(controllerContext, bindingContext);
if(queryRequest!=null)
{
//get the attempted value from the value provider, in this case a comma-delimited string
Expression<Func<QueryRequest, int[]>> expression = x => queryRequest.SelectColumnIDs;
@OndeVai
OndeVai / jquery-validation-ko-bindinghander.js
Created March 12, 2012 22:15
jquery validation plugin with knockout js custom binding handler
ko.bindingHandlers.jqValidation = {
update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var accessor = valueAccessor();
if (accessor.enforce) {
$(element).find(':submit').removeClass('cancel');
$(element).validate({
submitHandler: function () {
if ($.isFunction(accessor.submitHandler))
@OndeVai
OndeVai / GoogleGeoCodingJson.cs
Created March 14, 2012 20:53
Calling Google Geo Coding Service with Json.Net Server Side
public interface IGeoLocationService
{
Location GetLocation(string street, string city, string state, string zip);
Location GetLocation(string address);
}
public class GoogleGeoLocationService : IGeoLocationService
{
public Location GetLocation(string street, string city, string state, string zip)
{
@OndeVai
OndeVai / EFCodeFirstSkeleton.cs
Created March 16, 2012 16:24
EF Code First Skeleton
public class Parent
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual ICollection<Child> MyChildren { get; set; }
}
public class Child
{
@OndeVai
OndeVai / sammy-routing-skeleton.js
Created March 20, 2012 20:00
Sammy Routing Skeleton
//all should be wrapped in jquery func
var my = my || {};
//routes setup
my.routes = (function () {
var hashBang = '#!/', //here could check if browser supports pushstate and avoid the hashbang
createRoute = function (route) {
@OndeVai
OndeVai / mappingLight
Created April 16, 2012 16:27
KnockoutJS Make Json Data Observable (lighter mapping plugin)
//todo make this a plugin for ko
function makeAllPropsObservable(jsonData) {
////console.log(jsonData.DivisionSummaries);
for (x in jsonData) {
////console.log(x + ' ' + jsonData[x]);
if (!$.isFunction(jsonData[x])) {
if (!$.isArray(jsonData[x])) {
if (!$.isPlainObject(jsonData[x]))
@OndeVai
OndeVai / vsiisdebuggermacro.vb
Created June 14, 2012 00:53
attaches debugger for VS
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Public Module Module1
private Image ScaleImage(Image image, int maxWidth, int maxHeight)
{
var ratioX = (double)maxWidth / image.Width;
var ratioY = (double)maxHeight / image.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(image.Width * ratio);
var newHeight = (int)(image.Height * ratio);
var newImage = new Bitmap(newWidth, newHeight);
public class MatchesController : ApiController
{
private static IMatchRepository _repository;
public MatchesController(IMatchRepository repository)
{
_repository = repository;
}
@OndeVai
OndeVai / gist:7494296
Created November 16, 2013 00:45
IIS Pickup Directory
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\temp\maildrop\"/>
</smtp>
</mailSettings>
</system.net>