Skip to content

Instantly share code, notes, and snippets.

View bruno-cadorette's full-sized avatar

Bruno Cadorette bruno-cadorette

  • Sherbrooke
View GitHub Profile
@bruno-cadorette
bruno-cadorette / CheckBoxListFor.cs
Created May 24, 2013 02:07
MVC 3 checkbox list for
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Linq.Expressions;
public static class CheckBoxListForExtensions
{
public static MvcHtmlString CheckBoxListFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, SelectList selectList)
@bruno-cadorette
bruno-cadorette / 12 days of christmas
Last active December 29, 2015 20:19
Microsoft Anna sing: the 12 days of christmas!
open System.Speech.Synthesis
open System
type language = {
presents: string array
line: string
lastPrefix: string
suffix: int->string
}
let rec reverse str =
let a = Console.ReadLine()
if a <> "0" then
reverse a
printfn "%s" str
[<EntryPoint>]
let main argv =
reverse ""
@bruno-cadorette
bruno-cadorette / FizzBuzz
Last active August 29, 2015 14:21
fizzbuzz with infinite list, without modulo
fizzbuzz xs =
let
fizz = cycle ["","","fizz"]
buzz = cycle ["","","","","buzz"]
f x i = if null x then show i else x
in
zipWith3 (\fz bz i-> f (fz++bz) i) fizz buzz xs
main = do
putStr $ unlines $ fizzbuzz [1..100]
@bruno-cadorette
bruno-cadorette / IpAddress
Created June 19, 2015 04:43
Mask an ip address
import Control.Monad
import Data.Bits
import Data.List
import Data.List.Split
import Data.Word
createMask::Int -> [Word8]
createMask mask = take 4 $ gen mask ++ repeat 0
where
gen mask
@bruno-cadorette
bruno-cadorette / Auto clicker
Last active August 29, 2015 14:23
Press S to start and X to stop
#include "Windows.h"
#include <iostream>
#include <thread>
using namespace std;
void WaitForKey(int vKey)
{
while (!GetAsyncKeyState(vKey));
}
@bruno-cadorette
bruno-cadorette / RPSGame.hs
Last active August 29, 2015 14:23
Rock paper scissor
import Text.Read (readMaybe)
import System.Random (randomRIO)
data Move = Rock | Paper | Scissor deriving(Eq, Read, Show, Enum)
data Result = Victory | Defeat | Draw deriving(Show)
play Rock Scissor = Victory
play Paper Rock = Victory
play Scissor Paper = Victory
play a b
using System;
namespace CSharpFunctional
{
[Serializable]
public class NoPatternException : Exception
{
public NoPatternException() { }
public NoPatternException(string message) : base(message) { }
public NoPatternException(string message, Exception inner) : base(message, inner) { }
@bruno-cadorette
bruno-cadorette / HierachicalParser.hs
Created November 9, 2015 05:38
Read a rose tree separated by new lines and tabs and transform it to a Data.Tree
import Data.List
import Data.Tree
import Control.Arrow (first)
import Data.Function (on)
toHierarchical :: String -> [(Int, [String])]
toHierarchical = map simplify . groupBy ((==) `on` fst) . map (first length . span (== '\t')) . lines
where
simplify = first head . unzip
import Keyboard
import Mouse exposing (position)
import Time exposing (Time, fps)
import Debug exposing(..)
import Signal
import Graphics.Element exposing (show)
import Graphics.Collage
import Color exposing (red, black)
import Window exposing (dimensions)