Skip to content

Instantly share code, notes, and snippets.

@yukitos
yukitos / HowToUseRazor.cs
Last active August 29, 2015 14:25
Trying to use System.Web.Razor without 3rd party libraries as possible.
// The following code references System.Web.Razor 2.0.0.0
// Note that our model should have a concrete type in the following code
// (i.e. anonymous typed model is not supported).
using Microsoft.CSharp;
using RazorEngine.Compilation;
using RazorEngine.Compilation.ReferenceResolver;
using RazorEngine.Templating;
using System;
using Microsoft.CSharp;
using RazorEngine.Compilation;
using RazorEngine.Compilation.ReferenceResolver;
using RazorEngine.Templating;
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
#if INTERACTIVE
#r "..\\packages\\FSharp.Compiler.Service.0.0.89\\lib\\net45\\FSharp.Compiler.Service.dll"
#endif
open System
open Microsoft.FSharp.Compiler.SourceCodeServices
let sourceTok = FSharpSourceTokenizer([], "C:\\test.fsx")
let lines = """
<?xml version="1.0" encoding="utf-16"?>
<BootstrapperApplicationData xmlns="http://schemas.microsoft.com/wix/2010/BootstrapperApplicationData">
  <WixBundleProperties DisplayName="BootstrapperSetup"
                       LogPathVariable="WixBundleLog"
                       Compressed="no" Id="{a8199337-8ee3-4e4e-a2ee-6f518501d8f3}"
                       UpgradeCode="{27A4F806-DB94-478A-B639-BE690C45E390}"
                       PerMachine="yes" />
  <WixMbaPrereqInformation PackageId="Netfx4Full"
                           LicenseUrl="NetfxLicense.rtf" />
  <WixPackageFeatureInfo Package="DummyInstallationPackageId"
using System;
static class Expr
{
public static T If<T>(Func<bool> guard, T thenValue, T elseValue)
{
return guard() ? thenValue : elseValue;
}
}
open System
open System.Net
open System.Text.RegularExpressions
let private matchedValue (matchResult:Match) (key:String) =
matchResult.Groups.[key].Value.Trim() |> WebUtility.HtmlDecode
let regex pattern options input =
let m = Regex.Match(input, pattern, options)
if m.Success then Some m else None
module SelfModule =
open System.Collections.Generic
type SelfObj(someOp: SelfObj -> unit) =
member self.op = someOp
member val Depth = 0 with get, set
let dict = new Dictionary<int, SelfObj>()
type SelfObj with
type IChristmasTrees2 =
| PlasticTree
| LiveTree
| HologramTree
let (|PlasticTreeType|_|) = function
| PlasticTree -> Some(PlasticTreeType)
| _ -> None
// Pearls of Functional Algorithm Design
// Ch1-1
let (--) us vs = us |>Seq.filter(fun i -> not (Seq.exists(fun j -> i=j) vs))
let minfree xs = Seq.head([0..Seq.length xs] -- xs)
[8; 23; 9; 0; 12; 11; 1; 10; 13; 7; 41; 4; 14; 21; 5; 17; 3; 19; 2; 6]
|> minfree
### Keybase proof
I hereby claim:
* I am yukitos on github.
* I am yukitos (https://keybase.io/yukitos) on keybase.
* I have a public key whose fingerprint is 2257 CD30 012D 6739 B948 271A 6BBD 7DCE 7766 C7DE
To claim this, I am signing this object: