Skip to content

Instantly share code, notes, and snippets.

View Luiz-Monad's full-sized avatar
💭
computing

Luiz Luiz-Monad

💭
computing
View GitHub Profile
let meleeAttacks
(abilities:Abilities)
(proficiency:Weapon.Proficiency)
(level:int)
(weapon:Weapon) =
let ability =
match weapon.Finesse with
| true -> [ STR; DEX ]
@Luiz-Monad
Luiz-Monad / fib.cpp
Created April 22, 2019 03:48
peano fib template
struct Z {
enum { ToInt = 0 };
};
template<typename T>
struct S {
enum { ToInt = sizeof(T) };
T t;
char c;
@Luiz-Monad
Luiz-Monad / whenSome.fs
Last active May 30, 2019 14:21
monads.fs
// val whenSome: ('b -> 'c) -> 'b option list -> 'c list
let whenSome f = List.collect ( Option.map ( f >> List.singleton ) >> Option.defaultValue [] )
@Luiz-Monad
Luiz-Monad / JsonConvert.fs
Last active June 20, 2019 17:21
POJO DU Json Hack [not working]
#r obj\Debug\netcoreapp2.2\Server.dll
#r ..\.nuget\packages\fable.core\3.0.0\lib\netstandard2.0\Fable.Core.dll
#r ..\.nuget\packages\fsharp.core\4.6.2\lib\netstandard1.6\FSharp.Core.dll
#r ..\packages\Newtonsoft.Json\lib\netstandard2.0\Newtonsoft.Json.dll
#r ..\packages\System.Reflection.TypeExtensions\lib\netstandard2.0\System.Reflection.TypeExtensions.dll
#r System.Numerics.dll
let dump o = o.Dump() |> ignore
let dumpS (s: String) o = o.Dump(s) |> ignore
@Luiz-Monad
Luiz-Monad / traverse.fs
Created July 9, 2019 21:38
YOLO traverse - you only lift once
//fsharp
type Result<'Ok, 'Error> =
| Ok of 'Ok
| Error of 'Error
//yolo
module Result =
let bind f v =
@Luiz-Monad
Luiz-Monad / AsyncResult.fs
Created July 10, 2019 01:06
AsyncResult playground
/// Stacks the Async Result monad.
module AsyncResult =
let ok v = v |> Ok |> Async.result
let error v = v |> Error |> Async.result
let map f =
f |> Result.map |> Async.map
/// <summary>
/// Microsoft provided class. It allows dynamic string based querying.
/// Very handy when, at compile time, you don't know the type of queries that will be generated.
/// </summary>
public static class DynamicQueryable
{
#region IQueryable Extensions
@Luiz-Monad
Luiz-Monad / xml.fs
Created July 25, 2019 20:22
xml patch
let patchRequest (r: RequestEventArgs) =
let filter (s: string) = s.Replace ( "\"", "" )
let doc = using (new MemoryStream ()) <| fun ms ->
let xw = System.Xml.XmlWriter.Create ms
r.RequestInformation.WriteXml xw
xw.Flush ()
ms.Position <- 0L
@Luiz-Monad
Luiz-Monad / ts2fs.ps1
Last active August 11, 2019 02:30
convert typescrito to fsharp
# ls -Recurse -Include *.d.ts | % { " declare module $((($_.Name) -split "[.]")[0]) { " ;gc $_; "}" } | Set-ClipBoard
node .\ts2fable\build\ts2fable.js material-ui-pickers\lib\build\index.d.ts src\material_ui_pickers.fs -e material-ui-pickers react react-dom material-ui
@Luiz-Monad
Luiz-Monad / genres.ps1
Last active August 18, 2019 02:14
inject resources into an assembly
$strings = @( "file1.bin", "file2.bin", "file3.bin" )
# Compile the code
function escape() { process { "@`"$_`"" } }
$source = @"
using System.Resources;
public class MakeResource
{
public static void Main(string[] args)