Skip to content

Instantly share code, notes, and snippets.

View vgaltes's full-sized avatar

Vicenç García Altés vgaltes

View GitHub Profile
@vgaltes
vgaltes / Index.cshtml
Created December 6, 2015 21:46
Button with parameter
<table>
<colgroup>
<col style="width: 50%;">
<col style="width: 20%;">
</colgroup>
<tbody>
@for (var i = 0; i < Model.IngredientSearchResults.Count; i++)
{
var ingredient = Model.IngredientSearchResults[i];
<tr>
@vgaltes
vgaltes / Index.cshtml
Created December 6, 2015 21:34
Clear button
<button type="submit" class="button" name="SpecifyIngredients" value="ClearIngredients">Clear</button>
@vgaltes
vgaltes / HomeController.cs
Created December 6, 2015 21:33
Applying MultipleFormActionsButton attribute
[HttpPost]
[MultipleFormActionsButton(SubmitButtonActionName = "SpecifyIngredients")]
public ActionResult ClearIngredients()
{
...
}
@vgaltes
vgaltes / MultipleFormActionsButtonAttribute.cs
Last active December 6, 2015 21:27
MultipleFormActionsButtonAttribute
[AttributeUsage(AttributeTargets.Method)]
public class MultipleFormActionsButtonAttribute : ActionNameSelectorAttribute
{
public string SubmitButtonActionName { get; set; }
public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
{
var value = controllerContext.Controller.ValueProvider.GetValue(SubmitButtonActionName);
if (value == null)
@vgaltes
vgaltes / gist:342499b8c7f36f5eb4c7
Created July 3, 2015 14:59
Social network (temporal solution)
module SocialNetworkKata
let mutable timelines = Map.empty
let mutable followers = Map.empty
let post userName message =
let userTimeline = if (Map.containsKey userName timelines )
then Map.find userName timelines
else []
@vgaltes
vgaltes / gist:8c1c7b58c07df88bfd3a
Created May 10, 2015 14:45
FSharp Pattern Mathing -> Using parameterized active pattern
let fizzBuzz =
function
| DivisibleBy 3 & DivisibleBy 5 -> "FizzBuzz"
| DivisibleBy 3 -> "Fizz"
| DivisibleBy 5 -> "Buzz"
| n -> n.ToString()
@vgaltes
vgaltes / gist:e453ddd088beac84791f
Created May 10, 2015 14:43
FSharp Pattern Matching - parametrized active pattern
let (|DivisibleBy|_|) d n = if n % d = 0 then Some DivisibleBy else None
@vgaltes
vgaltes / gist:ba40cc99e15118b81301
Created May 10, 2015 14:36
FSharp Pattern Matching - using partial active pattern matching
let fizzBuzz =
function
| Fizz & Buzz -> "FizzBuzz"
| Fizz -> "Fizz"
| Buzz -> "Buzz"
| n -> n.ToString()
@vgaltes
vgaltes / gist:06f0e841f0a82d9d7d8c
Created May 10, 2015 14:33
FSharp Pattern Matching - Partial active patterns
let (|Fizz|_|) n = if n % 3 = 0 then Some Fizz else None
let (|Buzz|_|) n = if n % 5 = 0 then Some Buzz else None
@vgaltes
vgaltes / gist:1bd24d3819c9e6022514
Created May 10, 2015 14:21
FSharp Pattern Matching - Printing results
seq {1..100}
|> Seq.map fizzBuzz
|> Seq.iter (printfn "%s")