Skip to content

Instantly share code, notes, and snippets.

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

Luiz Luiz-Monad

💭
computing
View GitHub Profile
// FORK from : https://github.com/fsharp/FSharp.Data
// --------------------------------------------------------------------------------------
// Helper operations for converting converting string values to other types
// --------------------------------------------------------------------------------------
open System
open System.Globalization
open System.Text.RegularExpressions
@Luiz-Monad
Luiz-Monad / azure_segment.fs
Created October 18, 2019 00:01
azure paging
let! table = container eset
let nextSegment callcc args ct = asyncSeq {
let execute (_, filter, records) =
let query = TableQuery ()
query.TakeCount <- Option.toNullable records
let q = query.Where(filter)
table.ExecuteQuerySegmentedAsync ( q, fromContinue ct )
match! catch execute args with
| Ok segmt ->
yield! segmt.Results |> Seq.map Ok |> AsyncSeq.ofSeq
ostringstream param;
param << "\x4c\x1b\x47\x4c\x31\x2c\x30\x2c";
param << string(3 - swidth.size(), '0') << swidth;
param << ",";
param << string(3 - sheight.size(), '0') << sheight;
param << ";";
string cmd = param.str();
write(f, cmd.c_str(), cmd.size());
@Luiz-Monad
Luiz-Monad / cpp_fp_thread.cpp
Created September 22, 2019 02:15
thread sleep C++
#include <chrono>
#include <thread>
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <algorithm>
#include <functional>
#include <random>
#include <chrono>
@Luiz-Monad
Luiz-Monad / user.fs
Created September 13, 2019 19:00
Delayed computation example
msg {
let! xn = ApiSubmit ( API.GetWorker )
match xn with
//match! User.Get with
| Ok data ->
yield StorageSave ( DataKey.User, data )
| Error (e: FableUtil.FetchUtil.Response) ->
yield ApplicationError <| string e.Status + " " + e.StatusText
@Luiz-Monad
Luiz-Monad / subPath.fsx
Created August 26, 2019 19:15 — forked from nojaf/subPath.fsx
Suave subPath
open System
open Suave
open Suave.Filters
let subPath path (ctx:HttpContext) =
async {
let localPath = ctx.request.url.LocalPath
let result =
match (localPath.StartsWith(path)) with
| false -> None
@Luiz-Monad
Luiz-Monad / genres.cs
Last active August 24, 2019 14:53
inject resources into assembly
using System;
using System.Linq;
using System.Resources;
public class MakeResource
{
public static void Run(string file, string[] resources)
{
var strt = resources;
// Define a resource file.
@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)
@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 / 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