Skip to content

Instantly share code, notes, and snippets.

@giuliohome
giuliohome / WebSharperLens2DB.fs
Created August 27, 2019 11:53
V for Lens with Async DB retrieval
// online snippet: https://try.websharper.com/snippet/user3383/0000Oy
// gitter ref: https://gitter.im/intellifactory/websharper?at=5d650521f2821072aa20f412
// intellifactory blog: https://www.intellifactory.com/blog/5508/clear-and-simple-reactive-code-with-websharper-ui-s-v
namespace Samples
open WebSharper
open WebSharper.JavaScript
open WebSharper.UI
open WebSharper.UI.Html
open WebSharper.UI.Client
// from IE datepicker to F#: you tried Globalization, ParseExact, etc... without luck
// and this does the trick ;-)
let filterDate (str:string) : string =
new string (str.ToCharArray()
|> Array.filter(fun c -> int c < 128))
// used for example in
let dateFrom = DateTime.Parse(filterDate dateFromStr)
@giuliohome
giuliohome / OpenDetails.fs
Last active July 30, 2019 09:50
Create a form to post a request with parameter for a new detail tab and render it into html, all typesafe, from f# to javascript
let (|==>) (param_name, param_id) (safe_url:EndPoint) =
let router = Router.Infer()
let url = router.Link(safe_url)
form [attr.target "_blank"; attr.action url; attr.id ("form" + param_id); attr.method "POST" ] [
a [ on.click (fun el ev ->
let frm = JS.Document.GetElementById ("form" + param_id) |> As<HTMLFormElement>
frm.Submit()
) ] [text param_id]
input [attr.``type`` "hidden"; attr.name param_name; attr.value param_id] []
]
@giuliohome
giuliohome / app_offline.htm
Created May 14, 2019 02:10 — forked from robert-claypool/app_offline.htm
A simple "app offline" template for ASP.NET
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Offline</title>
</head>
<body style="margin:3em;font-family:sans-serif">
<h2>Offline</h2>
<p>This site is offline for maintenance.</p>
<!--
//usage:
//TimeIt(() => Extract(sql_trades, "03_Trade_Valid_" + timestamp + ".csv"), "Trade Extract");
static bool Retry(int count, Action action, Action<int> startCallback, Func<Exception, int, bool> exceptionCallback)
{
if (count <= 0) { return false; } else
{
try
{
startCallback(count);
action();
open Renci.SshNet
open System.IO
open System.Configuration
open System
let config = ConfigurationManager.AppSettings
let timestamp = "sftp_log_" + DateTime.UtcNow.Date.ToString("yyyy_MM_dd") + ".txt"
let logPath = Path.Combine(config.["SharedFolder"],timestamp)
let sw = new StreamWriter(logPath,true)
import Database.HDBC
import Database.HDBC.ODBC
data Person = Person
{ id :: Int
, name :: [Char] }
deriving Show
convRow :: [SqlValue] -> Person
convRow [sqlId, sqlDesc] =

A quadratic space is a real vector space V with a quadratic form Q(x), e.g. V = R^n with Q as the squared length. The Clifford algebra Cl(V) of a quadratic space is the associative algebra that contains V and satisfies x^2 = Q(x) for all x in V. We're imposing by fiat that the square of a vector should be the quadratic form's value and seeing where it takes us. Treat x^2 = Q(x) as a symbolic rewriting rule that lets you replace x^2 or x x with Q(x) and vice versa whenever x is a vector. Beyond that Cl(V) satisfies the standard axioms of an algebra: it lets you multiply by scalars, it's associative and distributive, but not necessarily commutative.

Remarkably, this is all you need to derive everything about Clifford algebras.

Let me show you how easy it is to bootstrap the theory from nothing.

We know Cl(V) contains a copy of V. Since x^2 = Q(x) for all x, it must also contain a copy of some nonnegative reals.

@giuliohome
giuliohome / PageAjax2.aspx
Created November 2, 2018 18:55
Calling C# from JavaScript
protected async void Page_Load(object sender, EventArgs e)
{
test++;
if (!Page.IsPostBack)
{
if (Request.Form["method"] == "Test")
{
MyType[] obj = await Test(Request.Form["msg1"], Request.Form["msg2"]);
string json = new JavaScriptSerializer().Serialize(obj);
Response.Write(json);
@giuliohome
giuliohome / FP2TheMax.fs
Last active August 18, 2018 17:19
F# port of John A De Goes "FP to the max"
open System
type Eff<'Ctx, 'T> = 'Ctx -> 'T
type EffBuilder() =
member __.Return x : Eff<'Ctx,'T> =
fun _ -> x
member __.Bind(f : Eff<'Ctx, 'T>, g : 'T -> Eff<'Ctx, 'S>) : Eff<'Ctx, 'S> =
fun c -> g (f c) c
member __.Zero() : Eff<'Ctx, unit> =