Skip to content

Instantly share code, notes, and snippets.

View LukeWinikates's full-sized avatar

Luke Winikates LukeWinikates

View GitHub Profile
@LukeWinikates
LukeWinikates / ControllerHelper.cs
Created July 23, 2011 01:54
A possibly naive way to write less code when you want a Controller POST action to play nicely with both vanilla and Ajax form submits.
public static class ControllerHelper {
// working with forms on MVC 3, I found a handful of instances where I wanted to support ajax form submits using the jQuery form plugin
// but still wanted to keep the option of graceful degradation if javascript wasn't supported.
// there might be a better approach to this, like having seperate Ajax and vanilla Post methods,
// moving the logic that currently resides in the controller elsewhere. That would increase complexity a lot all at once.
// Perhaps this kind of thing is the right path in the short term.
public static ActionResult PartialIfAjax_ViewOtherwise(this Controller controller, string viewName, object model) {
if (controller.Request.IsAjaxRequest()) {
return controller.PartialView(viewName, model);
@LukeWinikates
LukeWinikates / FakeDbSet.cs
Created October 24, 2011 16:31
An implementation of IDbSet to help with mocking Entity Framework DbContexts.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EntityExtensions {
public class FakeDbSet<T> : System.Data.Entity.IDbSet<T> where T : class {
private readonly List<T> list = new List<T>();
public FakeDbSet() {
@LukeWinikates
LukeWinikates / EqualityExtender.cs
Created June 2, 2012 00:56
Sometimes, IEnumerable<T>.Any() is the opposite of what you want...
public static class EqualityExtender
{
/// <summary>
/// Sometimes you want to say this.Name = "Bob" or "Fran". Linq lets you do:
/// new[]{"Fran", "Bob"}.Any(n=> n == this.Name);
///
/// but isn't it nicer to do:
///
/// this.Name.EqualsAnyOf(new[]{"Bob", "Fran"});
/// </summary>
@LukeWinikates
LukeWinikates / posts.json
Created December 31, 2012 02:26
Example of liquid template for generating JSON -- not pretty, but effective
---
---
[
{% for post in site.posts %}
{ "title": "{{ post.title }}", "url": "{{ post.url}}" },
{% endfor %}
null
]
@LukeWinikates
LukeWinikates / from-dropdowns
Created December 31, 2012 17:59
Quotation from bootstrap dropdowns.less
// Links within the dropdown menu
li > a {
display: block;
// ...etc
}
@LukeWinikates
LukeWinikates / go.grcconf
Created February 17, 2013 21:47
grc config file for go text / gocheck output, to make failing tests pop out more
regexp=FAIL:?
colours=red
count=more
-
regexp=PASS:?
colours=green
count=more
-
regexp=/[\w/\.]+:\d+
colours=blue
exciting content
@LukeWinikates
LukeWinikates / .gitignore
Created July 20, 2013 23:55
sunspot demo
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.
@LukeWinikates
LukeWinikates / .gitignore
Created July 20, 2013 23:57
sunspot demo
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.

Keybase proof

I hereby claim:

  • I am lukewinikates on github.
  • I am lwinikates (https://keybase.io/lwinikates) on keybase.
  • I have a public key whose fingerprint is AC5F 7444 8560 9905 7128 38E9 AE14 2850 289E 14F4

To claim this, I am signing this object: