Skip to content

Instantly share code, notes, and snippets.

@OndeVai
OndeVai / gist:8722781
Created January 31, 2014 00:02
MVC - current routr
private static bool IsCurrentAction(this HtmlHelper htmlHelper, string action, string controller)
{
var viewContext = htmlHelper.ViewContext;
var routeValues = viewContext.RouteData.Values;
var currentController = routeValues["controller"];
var currentAction = routeValues["action"];
return (currentController != null && String.Equals(currentController.ToString(), controller, StringComparison.CurrentCultureIgnoreCase)) &&
(currentAction != null && String.Equals(currentAction.ToString(), action, StringComparison.CurrentCultureIgnoreCase));
}
@OndeVai
OndeVai / gist:8044905
Created December 19, 2013 19:38
view jquery validation errors
$(function() {
$('form').on('submit', function() {
var validator = $("form").validate();
var errors = validator.errors(); //get the error elements, the actual labels
var errorsE = validator.invalidElements(); //the invalid elements themselves
console.log(validator.valid());
console.log(errors);
console.log(errorsE);
});
});
@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>
public class MatchesController : ApiController
{
private static IMatchRepository _repository;
public MatchesController(IMatchRepository repository)
{
_repository = repository;
}
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);
@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
@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 / 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 / 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 / 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)
{