Skip to content

Instantly share code, notes, and snippets.

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

Luiz Luiz-Monad

💭
computing
View GitHub Profile
@Luiz-Monad
Luiz-Monad / profunctor.cs
Last active December 5, 2016 23:53
A Profunctor is just a bifunctor that is contravariant in the first argument and covariant in the second. What's the problem?
//https://ocharles.org.uk/blog/guest-posts/2013-12-22-24-days-of-hackage-profunctors.html
//http://blog.sigfpe.com/2011/07/profunctors-in-haskell.html
//https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors
public interface Variant { }
public interface CoVariant { }
public interface Profunctor<P>
{
P p { get; }
@Luiz-Monad
Luiz-Monad / high_ef.fs
Last active January 31, 2018 01:32
HighOrder EntityFramework
//how to implement CRUD with F# and entityframework and TypeClasses
//transform this into an highorder type
type Customer with static member queryId = <@ fun ( λ : Customer ) -> λ.Id @>
//just a helper
type entity<'T> = ('T -> int)
//our highorder context
@Luiz-Monad
Luiz-Monad / sort_by_pk.cs
Last active December 7, 2016 19:47
EF PK sort
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Data.Entity.Core;
using System.Data.Entity.Core.Mapping;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Core.Objects.DataClasses;
using System.Data.Entity.Infrastructure;
using System.Data.Linq;
@Luiz-Monad
Luiz-Monad / vlc_screen.ps1
Created January 29, 2017 22:34
VLC transcode bullshit formats
function x($i) { $i.Replace("`r", '').Replace("`n", '').Replace(" ",'').Replace("'", '"') }
$f = join-path (get-location) 'screen'
$l = join-path (get-location) 'log.txt'
pushd 'C:\Program Files\VideoLAN\VLC'
./vlc.exe `
-I dummy `
(x "screen://") `
(x @"
--sout=#transcode{
@Luiz-Monad
Luiz-Monad / gif_animated.cc
Last active January 29, 2017 23:17
extract gif
#include "cv.h"
#include "highgui.h"
#include <iostream>
#include <string>
using namespace std;
void help(const string& exec_name) {
cout << exec_name << " src tgt w h" << endl;
@Luiz-Monad
Luiz-Monad / ParallelExtensions.cs
Created February 14, 2017 16:10
Parallel Task Constraining
public static class ParallelExtensions
{
/// <summary>
/// Enumerates through each item in a list in parallel
/// </summary>
public static void ForEachParallel<T>(this IEnumerable<T> list, Func<T, int, AsyncCallback, IAsyncResult> beginAction, Action<T, int, object, IAsyncResult> endAction, int parallelization = 0)
{
if (list == null) {
return;
@Luiz-Monad
Luiz-Monad / CS
Last active May 9, 2020 12:03
CS
https://teachyourselfcs.com/
http://steshaw.org/plt/
https://github.com/open-source-society/computer-science
PLT: advanced
textbooks
http://cs.brown.edu/~sk/Publications/Books/ProgLangs/
http://www.cis.upenn.edu/~bcpierce/tapl/main.html
http://highered.mheducation.com/sites/0070131511/index.html
@Luiz-Monad
Luiz-Monad / memoize.fs
Created July 6, 2017 05:13
Fsharp memoize
let rec y f x = f (y f) x
let memoize (d:System.Collections.Generic.Dictionary<_,_>) f n =
if d.ContainsKey n then d.[n]
else d.Add(n, f n);d.[n]
let rec factorialucps factorial' n cont =
if n = 0I then cont(1I) else factorial' (n-1I) (fun k -> cont (n*k))
let factorialdpcps =
@Luiz-Monad
Luiz-Monad / overloaded_overload.fs
Last active January 31, 2018 01:32
Overloading and TypeClasses
//////////////////////////////////////////////////////////////////////////////////////////
// first try, trying to generalize over overloading, nope, cant generalize over
// two overloads
let inline backend<'M, 'C, 'VM when 'C : (new : unit -> 'C)
and 'C : (member Get : unit -> 'M seq)
and 'C : (member Get : int Nullable -> 'M seq)
and 'C : (member Get :'M Selector -> 'M seq)> () =
let getGet0 ( controller : ^C ) () =
@Luiz-Monad
Luiz-Monad / helpers.cpp
Last active August 18, 2017 14:08
C++ helpers
class Random
{
private:
function<int(void)> rnd;
public:
Random() {
auto rnde = default_random_engine();
auto rndd = uniform_int_distribution<int>(
numeric_limits<char>::min(),