Skip to content

Instantly share code, notes, and snippets.

Philip Cox neoGeneva

Block or report user

Report or block neoGeneva

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@neoGeneva
neoGeneva / gruntfile.js
Created Jul 24, 2015
SCSS compilation on save for VS2015 (for scss files under /Content/)
View gruntfile.js
/// <binding ProjectOpened='watch' />
module.exports = function (grunt) {
grunt.initConfig({
bower: {
install: {
options: {
targetDir: "lib",
layout: "byComponent",
cleanTargetDir: false
}
@neoGeneva
neoGeneva / gist:3660470
Created Sep 6, 2012
Proxy using ApiController
View gist:3660470
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using Http = System.Net.WebRequestMethods.Http;
namespace PhilsVersion
{
public class ProxyController : ApiController
{
@neoGeneva
neoGeneva / gist:3007125
Created Jun 27, 2012
Full-Text Search From EF4
View gist:3007125
public static class ObjectQueryExtensions
{
public static ObjectQuery<T> FullTextSearch<T, TProperty>(this ObjectQuery<T> query, Expression<Func<T, TProperty>> propertyExpression, string searchText)
{
var path = string.Join(".", propertyExpression.ToString().Split('.').Skip(1));
return query.Where(string.Format("CONTAINS(it.{0}, @search_text)", path), new ObjectParameter("search_text", searchText));
}
}
@neoGeneva
neoGeneva / gist:2722775
Created May 18, 2012
ASP.NET MVC3 EditorFor that looks for inheritance
View gist:2722775
public static MvcHtmlString EditorForInherited<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
{
if (htmlHelper.ViewContext.ViewData.Model == null)
return htmlHelper.EditorFor(expression);
var modelType = htmlHelper.ViewContext.ViewData.Model.GetType();
if (modelType == typeof(TModel))
return htmlHelper.EditorFor(expression);
@neoGeneva
neoGeneva / gist:1878868
Created Feb 21, 2012
An OrderBy extension method for IQueryable that takes string
View gist:1878868
public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string sortExpression)
{
if (source == null)
throw new ArgumentNullException("source", "source is null.");
if (string.IsNullOrEmpty(sortExpression))
throw new ArgumentException("sortExpression is null or empty.", "sortExpression");
var parts = sortExpression.Split(' ');
@neoGeneva
neoGeneva / gist:1309070
Created Oct 24, 2011
Simple Event Creator in JavaScript
View gist:1309070
var createEvent = function() {
var _handlers = [];
return function() {
if (arguments.length === 1 && typeof arguments[0] === 'function') {
_handlers.push(arguments[0]);
return;
}
for (var i = 0; i < _handlers.length; ++i) {
@neoGeneva
neoGeneva / gist:1234779
Created Sep 22, 2011
Detect Encoding in C#
View gist:1234779
public static Encoding GetFileEncoding(string path)
{
if (path == null)
throw new ArgumentNullException("path");
var encodings = Encoding.GetEncodings()
.Select(e => e.GetEncoding())
.Select(e => new { Encoding = e, Preamble = e.GetPreamble() })
.Where(e => e.Preamble.Any())
.ToArray();
@neoGeneva
neoGeneva / gist:1216184
Created Sep 14, 2011
C# like properties in JavaScript
View gist:1216184
var createProperty = function(getSet) {
var _value;
var autoImplement = {
get: function() { return _value; },
set: function(value) { _value = value; return _value; }
};
getSet = getSet || autoImplement;
var get = getSet.get || function() { throw new Error('No get method defined for this property.'); },
@neoGeneva
neoGeneva / gist:1200123
Created Sep 7, 2011
Async CTP and Entity Framework
View gist:1200123
// This code is provided "as-is" without warranty of any kind, either expressed or implied.
public static class AsyncExtensions
{
public static async Task<IEnumerable<T>> AsAsync<T>(this IQueryable<T> source)
where T : EntityObject
{
var query = (ObjectQuery<T>)source;
var cmd = new SqlCommand();
@neoGeneva
neoGeneva / RedBlackTree.fsx
Created Jun 30, 2011
Red-Black Tree in F#
View RedBlackTree.fsx
// Inspired by: http://jng.imagine27.com/articles/2011-06-28-141124_purely_functional_types_red_black_trees_in_qi.html
type TreeNode<'a> = { Key: int; Val: 'a }
type Color = Red | Black
type Tree<'a> = { Color: Color; LTree: Tree<'a> option; TreeNode: TreeNode<'a>; RTree: Tree<'a> option; }
let makeTreeBlack tree =
match tree with
You can’t perform that action at this time.