Skip to content

Instantly share code, notes, and snippets.

View Chubek's full-sized avatar

Chubak Bidpaa Chubek

View GitHub Profile
@Chubek
Chubek / README.md
Created July 15, 2024 12:22
The 'map' function is the same as Kleene star (regex *)!

The map function and Kleene Star (regex *) are the same! (homomorphic)

In functional languages, and most modern imperative languages which implement functional features, we often have a map function. In λ-> (simply-typed λ-calc) we could describe the type of this function as:

Γ ⊢ λfλmα.m(α) : (A -> B) -> [A] -> Unit

Let me explain what this notation means.

@Chubek
Chubek / README.md
Last active June 28, 2024 16:43
Schemeroni: Useful Scheme Macaronis

I will use this Gist to post useful Scheme macros.

These macros will be compliant with R7Rs and down.

All macros are partially tested (warning!). Don't use them in serious work before thorough test.

@Chubek
Chubek / Inter.h
Last active June 24, 2024 23:38
Imperative representation of Peyton Jones' "enriched" λ-Calc language
#ifndef INTER_H
#define INTER_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@Chubek
Chubek / Pacal-Syntax.ml
Created June 8, 2024 08:26
Pascal-Syntax.ml: ISO Pascal's syntax formalized in OCaml type system
(* Formalism for ISO-7185:1990 "Pascal" Syntax *)
(* These will be extended into an AST *)
(* ISO Pascal is different from Delphi *)
(* Please submit your comments to chubakbidpaa [at] riseup [dot] net *)
type pas_kw = And | Array | Begin | Case | Const
| Div | Do | Downto | Else | End
| File | For | Function | Goto
| If | In | Label | Mod | Nil
| Not | Of | Or | Packed | Procedure
@Chubek
Chubek / README.md
Last active May 30, 2024 16:01
TSV datasets of ROFF (Requests, Escapes, NRs, SRs, Characters)

This Gist contains a total of 5 tab-separated values files (TSV), and they list:

  • ROFF-Requests.tsv -> ROFF requests, this file is the only one where the structure is taken from the manual downloaded from TROFF's website authored by the late Joe Ossanna and the legendary BWK, refer to the listing in the manual to get a sense of what each column means (name;args;default;default arg values;flags;description).
  • ROFF-Escapes.tsv -> The escape sequences --- those accepting arguments and those variable have been marked;
  • ROFF-NRs.tsv -> The built-in numeric registers (which GROFF just calls registers);
  • ROFF-SRs.tsv -> The built-in string registers (which GROFF just calls strings);
  • ROFF-Chars.tsv -> The pre-defined character list;

Important thing to note is, these are the listings as defined by Ossanna and Kernighan. GNU additions have not been accounted for. Whatever Heirloom DocTools adds neither. This is pure ROFF!

@Chubek
Chubek / README.md
Created May 27, 2024 22:16
SML's "implode" and "explode" in OCaml

In Standard ML, we have two built-in functions called 'explode' and 'implode':

fun explode: string -> char list
fun implode: char list -> string

So, you get it, 'explode' makes a list of characters from a string and 'implode' does the inverse.

However, OCaml does not have these functions. Regardless; you may derive them like so:

@Chubek
Chubek / README.md
Last active May 4, 2024 17:22
Tokenizer for EBNF in Scheme

Tokenizer for EBNF in Scheme

tokenize-ebnf.scm defines in it a tokenizer (aka lexer, or scanner) for EBNF. This is compliant to ISO but several other meta-structures such as RegExp (/.../) are also consumed. Comments starting withg # are tokenized, consumed and appended to the token stream. Do with them as you wish!

This was an excercise at Scheme --- and so much more, an excercise at hand-rollling lexers in an stateless language with functional paradigm built in.

You can use this to, for example, translate EBNF to LaTEx, HTML, PostScript, ROFF --- or maybe define a parser for it, and convert it to Yacc, PEG, ANTLR, Flex, Re2C, etc.

What is EBNF?

@Chubek
Chubek / README.md
Created May 1, 2024 14:01
A tokenizer for EBNF in Scheme (need parser!)

tokenize-ebnf.scm is a tokenizer for EBNF in Scheme. Although it is [almost] useless without a parser --- and that is what I have issue arriving at!

I want this to be an educational experience, so I don't wish to resort to define-sytax macros. Otherwise it would have been much simpler. Scheme's macros are a cheatcode tbqh. In fact, CLisp's macros are cheatcode too. Read 'Let Over Lambda' by Doug Hoyte. If I use macros here, I have doomed myself to be a Scheme Simp (Scsimp?) forever. I just don't want that.

So what I want is your help in creating a parser for EBNF that keeps in mind the recursive, context-free nature of it. EBNF was not meant to be parser, it was never created as an applicable language. I have loooked around and there are not that many parsers for EBNF around. It's a meta-grammar meant to be leared at and hooted at. Not parsed.

And I don't really need to parse it. I wanna write an ebnf2ps program. So this is enough really.

The problem is the 'nested' or 'recursive' nature of EBNF. For

@Chubek
Chubek / README.md
Last active May 1, 2024 10:31
Hummingbot Gateway

1- wget setup_gateway.py:

wget -qO- https://gist.githubusercontent.com/Chubek/5137a0b75a76d5f9f38d1e768d56d591/raw/c4b8c8c25e6991f01367d9ed5a5fa2be7627d83d/setup_gateway.py > setup_gateway.py

2- Preprocess it with m4, using your credentials and pass it to python:

# For example
@Chubek
Chubek / controller.yml
Created April 27, 2024 12:45
Controller
########################################################
### Pure market making strategy config ###
########################################################
template_version: 24
strategy: pure_market_making
# Exchange and token parameters.
exchange: gate_io