Skip to content

Instantly share code, notes, and snippets.

View juanbono's full-sized avatar
:shipit:

Juan Bono juanbono

:shipit:
View GitHub Profile
@ncthbrt
ncthbrt / Authorization.re
Last active January 12, 2018 08:58
Authorization.re
type permission =
| Permission(string, string);
module PermissionComparision = {
type t = permission;
let compare = (Permission(name1, _), Permission(name2, _)) => String.compare(name1, name2);
};
module PermissionSet = Set.Make(PermissionComparision);
@jaredly
jaredly / BasicServer.re
Created January 2, 2018 05:24
Simple Static File Server in Reason/OCaml
let recv = (client, maxlen) => {
let bytes = Bytes.create(maxlen);
let len = Unix.recv(client, bytes, 0, maxlen, []);
Bytes.sub_string(bytes, 0, len)
};
let parse_top = top => {
let parts = Str.split(Str.regexp("[ \t]+"), top);
switch (parts) {
@snoyberg
snoyberg / html-cleanup.hs
Created December 26, 2017 18:03
Small example of xml-conduit for cleaning up some HTML: remove unneeded <span>s and convert <br>s to \n
#!/usr/bin/env stack
-- stack --resolver lts-10.0 script
{-# LANGUAGE OverloadedStrings #-}
import Text.XML
import qualified Data.Map.Strict as Map
main :: IO ()
main = do
Document x (Element n a nodes) y <- Text.XML.readFile def "foo.html"
Text.XML.writeFile def "foo2.html" $ Document x (Element n a $ concatMap goN nodes) y
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Foldable (for_)
import Data.Traversable (for)
import Control.Monad.IO.Class
-- build-depends: base, haskeline, optparse-applicative
-- -- for example parser
@lilactown
lilactown / promises.re
Last active August 20, 2022 07:56
Notes on using JavaScript Promises in ReasonML/BuckleScript
/**
* Making promises
*/
let okPromise = Js.Promise.make((~resolve, ~reject as _) => [@bs] resolve("ok"));
/* Simpler promise creation for static values */
Js.Promise.resolve("easy");
Js.Promise.reject(Invalid_argument("too easy"));
import Control.Monad.IO.Class
import Control.Monad.Codensity
import System.IO
managedActions :: Codensity IO ()
managedActions = do
input <- Codensity $ withFile "in.txt" ReadMode
output <- Codensity $ withFile "out.txt" WriteMode
contents <- liftIO $ hGetContents input
@thoughtpolice
thoughtpolice / RegAlloc1.hs
Last active July 26, 2022 13:49
Simple register allocation, see "Essentials of Compilation" for more https://jeapostrophe.github.io/courses/2017/spring/406/notes/book.pdf
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
module RegAlloc1
( -- * Types
Var
@chshersh
chshersh / ghci.conf
Last active December 5, 2023 00:19
Config for GHCi with pretty output
-- To run:
-- cabal repl -b pretty-simple
--
-- Colorizing and pretty-printing ghci output
-- requires: pretty-simple
:set -interactive-print=Text.Pretty.Simple.pPrint
-- green bold lambdas and multiline mode
:set prompt "\ESC[1;32mλ: \ESC[m"
:set prompt-cont "\ESC[1;32mλ| \ESC[m"