Skip to content

Instantly share code, notes, and snippets.

@vrotaru
vrotaru / Base58.java
Created February 6, 2012 18:30
Base58 encoding an decoding
package core;
public class Base58 {
private static final char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
.toCharArray();
private static final int BASE_58 = ALPHABET.length;
private static final int BASE_256 = 256;
private static final int[] INDEXES = new int[128];
let split s n =
let arr = Array.make n 0 in
let rec loop j i =
if i < String.length s && j < n then
let c = s.[i] in
if c == ' ' then
loop (j + 1) (i + 1)
else
let () = arr.(j) <-
arr.(j) * 10 + (int_of_char c - int_of_char '0')
type _ ty =
| TBool : bool ty
| TInt : int ty
type _ value =
| Bool : bool -> bool value
| Int : int -> int value
type _ expr =
| Value : 'a value -> 'a expr
type _ ty =
| TBool : bool ty
| TInt : int ty
type _ value =
| Bool : bool -> bool value
| Int : int -> int value
type _ expr =
| Value : 'a value -> 'a expr
@vrotaru
vrotaru / README.md
Last active February 24, 2020 10:25

The goal of this exercise it to have a minimal parser which will parse expressions as the ML languages do. Namely to have function application to have the highest priority. The key to this seems to have a minimal set of productions in the base rule. The app rule defines that application groups to the left.

The type expr from Syntax module has the following interpretation: Int-s are numbers, Fn-s are predefined function names and App and Plus have the obvious and natural meaning.

A way to test it is to run mehnir --interpret --interpret-show-cst parser.mly

let char_0 = Char.code '0'
let split n s =
let len_s = String.length s in
let res = Array.make n 0 in
let rec slide pos =
if pos < len_s && s.[pos] <> ' ' then
pos + 1 |> slide
else pos
#! /bin/bash
SRC=/dev/urandom
len=${1-12}
i=1
while (( $i <= len )); do
if (( ($i + 1) % 3 == 0 )) ; then
cat $SRC | base64 | tr -dc aeiouy | head -c1
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Easy JavaScript Testing></title>
<style>
.pass:before {
content: 'PASS: ';
color: blue;
font-weight: bold;
trait A
case object a extends A
case object b extends A
trait B
case object x extends B
case object y extends B

Keybase proof

I hereby claim:

  • I am vrotaru on github.
  • I am vrotaru (https://keybase.io/vrotaru) on keybase.
  • I have a public key ASAuaOcLxLWR2FtMDOTotdYXZxyxrpTdPKm-Pi3uiTavOAo

To claim this, I am signing this object: