Skip to content

Instantly share code, notes, and snippets.

View Grinderofl's full-sized avatar

Nero Sule Grinderofl

View GitHub Profile
@Grinderofl
Grinderofl / jquery.autohash.js
Created November 16, 2011 06:22
jQuery: Autohash extension
(function ($) {
/**
* jQuery extension to parse hash (#) in url,
* fill in values of input boxes with the specific ID's,
* and automatically update the values on address bar by
* monitoring the change/keyup events.
*/
$.fn.autohash = function () {
// This extension is chainable
@Grinderofl
Grinderofl / AllowedValuesAttribute.cs
Created May 4, 2012 12:09
String property allowed values with dropdown box and MVC model validation
// Usage:
// [AttributeUsage("Option1", "Option2", "Option3")]
// public string MyTestAttribute { get; set; }
//
// In view:
// @Html.DropDownListFor(x => x.MyTestAttribute)
//
// Result:
// Dropdown list with 3 options.
@Grinderofl
Grinderofl / ExpressionType.cs
Created May 22, 2012 06:40
Custom filter builder from string
public enum ExpressionType
{
GreaterThan,
Equal,
LessThan
}
@Grinderofl
Grinderofl / SearchFieldMutator.cs
Created May 22, 2012 06:47
Search field mutator to allow easy filter function writing
public delegate IQueryable<T> QueryMutator<T>(IQueryable<T> item);
/// <summary>
/// Mutator class
/// </summary>
/// <typeparam name="TSearch">Predicate expression</typeparam>
/// <typeparam name="TQuery">Query expression if TSearch == true</typeparam>
public class SearchFieldMutator<TSearch, TQuery>
{
public Predicate<TSearch> Condition { get; set; }
@Grinderofl
Grinderofl / CacheExtensions.cs
Created June 1, 2012 09:01
Cache provider and extension for Entity Framework
using System;
using System.Collections.Generic;
using System.Linq;
namespace EFCache
{
public static class CacheExtensions
{
private static ICacheProvider _provider;
@Grinderofl
Grinderofl / MultipleReturnValues.cs
Last active December 18, 2015 21:19
A proposal for multiple return values
public class MyClass
{
public void MyMethod()
{
var x, y, z = MyReturnMethod();
Console.WriteLine("{0} {1} {2}", x, y, z);
// 10 Hello <now>
var var1 = MyReturnMethod();
Console.WriteLine(var1);
@Grinderofl
Grinderofl / StringParsingQueryable.cs
Created June 23, 2013 21:18
Idea for allowing expression parsing from string
class Program
{
static void Main(string[] args)
{
var items = new IEnumerable<Item>().... // setup items
var test = new ParsingTest(items);
var list = test.MyParsingTest("OrderBy(x => x.Name).Skip(2).Take(3)");
}
}
@Grinderofl
Grinderofl / AutomaticAssignment.cs
Created June 23, 2013 22:02
Proposal for automatic variable assignment from any object.
public class AutoAssign()
{
public Item GetItem()
{
return new Item() { Name = "Hello", Id = 10, DateTime = DateTime.Now };
}
public void Assign()
{
var id, name = GetItem().Assign();
Console.WriteLine("{0} {1}", id, name);
public partial class MainPage : PhoneApplicationPage
{
private readonly RotateTransform _rotateTransform;
private TranslateTransform _translateTransform;
// Constructor
public MainPage()
{
InitializeComponent();
@Grinderofl
Grinderofl / StopScrollToTopWhenLinkClicked.js
Last active December 30, 2015 23:39
Prevent youtube from scrolling to top when time link is clicked.
var links = document.getElementsByTagName('a');
for(var i = 0; i < links.length; i++) {
var thisLink = links[i];
if(thisLink.getAttribute('href') == '#') {
thisLink.onclick = (function(e){
var origClick = thisLink.onclick;
return function(e) {
var page_y;
window.onscroll = function(){
window.scrollTo(0, page_y);