This file contains 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 matchFirst(arr, predicateFn) { | |
var index = -1; | |
arr.some(function(x, i) { | |
var isMatch = predicateFn(x, i); | |
if (isMatch) { | |
index = i; | |
return true; | |
} | |
}); |
This file contains 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
# Check if PowerShell Profile-file exists | |
Test-Path $profile | |
# if "false" create Profile-file | |
New-Item -path $profile -type file –force | |
# Start editing file at | |
# C:\Users\[USERNAME]\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 |
This file contains 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
public static void MapMvcAttributeRoutes( | |
this RouteCollection routeCollection, | |
Assembly controllerAssembly, | |
IInlineConstraintResolver constraintResolver = null) | |
{ | |
var controllerTypes = (from type in controllerAssembly.GetExportedTypes() | |
where | |
type != null && type.IsPublic | |
&& type.Name.EndsWith("Controller", StringComparison.OrdinalIgnoreCase) | |
&& !type.IsAbstract && typeof(IController).IsAssignableFrom(type) |
This file contains 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
// http://stackoverflow.com/q/10659097/2429 | |
$('input[type=text]').on('change input propertychange paste', function() {}); |
This file contains 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
public static ExpandoObject ToDynamic(this object obj) | |
{ | |
var expandoObject = new ExpandoObject(); | |
if (obj == null) | |
{ | |
return expandoObject; | |
} | |
var dictionaryValues = new RouteValueDictionary(obj); | |
if (!dictionaryValues.Any()) |
This file contains 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
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | |
public class SuppressXFrameOptionsHeaderAttribute : ActionFilterAttribute | |
{ | |
public override void OnResultExecuted(ResultExecutedContext filterContext) | |
{ | |
filterContext.HttpContext.Response.Headers.Set("X-Frame-Options", "ALLOWALL"); | |
} | |
} |
This file contains 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
// According to: | |
// http://www.ietf.org/rfc/rfc3986.txt | |
public static char[] ValidRfc3986Chars = new[] { | |
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', | |
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', | |
'0','1','2','3','4','5','6','7','8','9', | |
'-','.','_','~',':','/','?','#','[',']','@','!','$','&','\'','(',')','*','+',',',';','=', | |
}; |
This file contains 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
public static string ToAbsolute(this UrlHelper urlHelper, string appRelativeUrl, | |
string relativeHostName = null, bool? useSecureConnection = null) { | |
var httpContext = urlHelper.RequestContext.HttpContext; | |
if(string.IsNullOrWhiteSpace(relativeHostName) && httpContext.Request == null) { | |
throw new ArgumentException("The provided host-name cannot be null or empty if there is no current HttpContext.", "relativeHostName"); | |
} | |
relativeHostName = (relativeHostName ?? string.Empty).Trim(new[] { '/' }); | |
if(!Uri.IsWellFormedUriString(relativeHostName, UriKind.Relative)) { |
This file contains 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
// Needs reference to 'http://maps.google.com/maps/api/js?sensor=false'. Optional: '&language=en'. | |
// mapElement should contain a 'data-locations'-attribute with JSON-formatted objects | |
// with properties 'lat', 'long', 'title' and optional 'description' | |
var initMap = function (mapElement) { | |
var dataLocations = $(mapElement).attr('data-locations'); // Find DOM-attribute containing locations | |
var markerPositions = ($.parseJSON(dataLocations) || { locations: [] }).locations || []; | |
var latlng = new google.maps.LatLng(59.33279, 18.06449); |
This file contains 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
// Load jQuery | |
(function () { | |
var jq = document.createElement('script'); jq.type = 'text/javascript'; jq.async = true; | |
jq.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(jq, s); | |
})(); |
OlderNewer