Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

"workbench.colorCustomizations": {
"foreground": "#9cdb70",
"focusBorder": "#42d400",
"selection.background": "#25a7332a",
"scrollbar.shadow": "#92db68",
"activityBar.foreground": "#ffffff",
"activityBar.background": "#264b21",
"activityBar.inactiveForeground": "#9fdb8466",
"activityBarBadge.foreground": "#ffffff",
@brandanmajeske
brandanmajeske / Dynamic SQL-like LINQ OrderBy Extention
Created December 15, 2017 17:49
Dynamic SQL-like LINQ OrderBy Extention (original author Adam Anderson)
public static class OrderByHelper
{
public static IEnumerable<T> OrderBy<T>(this IEnumerable<T> enumerable, string orderBy)
{
return enumerable.AsQueryable().OrderBy(orderBy).AsEnumerable();
}
public static IQueryable<T> OrderBy<T>(this IQueryable<T> collection, string orderBy)
{
foreach(OrderByInfo orderByInfo in ParseOrderBy(orderBy))
myApp.directive("autoGrow", function(){
return function(scope, element, attr){
var update = function(){
element.css("height", "auto");
element.css("height", element[0].scrollHeight + "px");
};
scope.$watch(attr.ngModel, function(){
update();
});
attr.$set("ngTrim", "false");
@brandanmajeske
brandanmajeske / URL rewrite to lower with JavaScript
Created March 18, 2015 19:54
URL rewrite to lower with JavaScript
<script type="text/javascript">
var URL=document.location;
//This makes the URL become a string, without it, an error would
//occur.
URL+="";
if(URL.toLowerCase() != URL){ //Check if the URL needs modified
//If so, then replace it.
document.location.replace(URL.toLowerCase());
@brandanmajeske
brandanmajeske / web.config
Last active January 5, 2021 08:49
IIS web.config rewrite rule for MVC/WebAPI with AngularJS in Html5 Mode
<!-- $locationProvider.html5Mode(true) in app.js and <base href="/"> in head tag -->
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
using System.Net;
using global::ServiceStack;
using global::ServiceStack.Logging;
using global::ServiceStack.ServiceHost;
public class AuthenticateFilter
{
private static readonly ILog Log = LogManager.GetLogger(typeof(AuthenticateFilter));
using global::ServiceStack;
using global::ServiceStack.Common.Web;
using global::ServiceStack.WebHost.Endpoints;
public class CorsFeature : IPlugin
{
public const string DefaultMethods = "GET, POST, PUT, DELETE, OPTIONS";
public const string DefaultHeaders = "Content-Type";
private static bool isInstalled = false;
/**
* Handles form errors from server.
*/
app.factory('formErrors', function () {
return {
/**
* Creates $error.errorKey (String) and sets validity
* for every failing model validation received from the server.
* E.g. 'form.message.$error.errorKey' can be accessed in the view.
@brandanmajeske
brandanmajeske / gist:e2fcb37af1e314629ce5
Created January 6, 2015 20:26
Gaussian/Banker's Rounding
/**
* Gaussian rounding (aka Banker's rounding) is a method of statistically
* unbiased rounding. It ensures against bias when rounding at x.5 by
* rounding x.5 towards the nearest even number. Regular rounding has a
* built-in upwards bias.
*/
function gaussianRound(x) {
var absolute = Math.abs(x);
var sign = x == 0 ? 0 : (x < 0 ? -1 : 1);
var floored = Math.floor(absolute);
@brandanmajeske
brandanmajeske / gist:3defa81c098fb17f5c02
Last active August 29, 2015 14:10
Angular / Bootstrap UI Datepicker filter to fix UTC/Local Datetime 'off by one' issue
app.filter('adjustDatepicker', [
'$filter', function($filter) {
var dateFilter = $filter('date');
return function(dateToFix) {
var localDate, localTime, localOffset, adjustedDate;
if (dateToFix === null)
return null;
localDate = new Date(dateToFix);
localTime = localDate.getTime();
localOffset = localDate.getTimezoneOffset() * 60000;