Skip to content

Instantly share code, notes, and snippets.

View samebchase's full-sized avatar
🦑

Samuel Chase samebchase

🦑
View GitHub Profile
@samebchase
samebchase / balanced-parens.raku
Created November 28, 2020 12:26
balanced-parens.raku
#!/usr/bin/env raku
use v6.d;
use Grammar::Tracer;
grammar BalancedParens {
token TOP { <balanced-paren> }
token balanced-paren { <lparen> <balanced-paren>* <rparen> }
@samebchase
samebchase / simple-ns.raku
Created November 28, 2020 12:25
simple-ns.raku
#!/usr/bin/env raku
use v6.d;
use Grammar::Tracer;
grammar SimpleNs {
token TOP { <simple-ns> }
token simple-ns { <lparen> <ns-keyword> <.ws> <ns-name> <rparen> }
@samebchase
samebchase / trivial.raku
Created November 28, 2020 12:24
trivial.raku
#!/usr/bin/env raku
use v6.d;
use Grammar::Tracer;
grammar EmptyLispForm {
token TOP { <lparen> <rparen> }
token lparen { '(' }
token rparen { ')' }
@samebchase
samebchase / realistic-ns-with-actions.raku
Created November 28, 2020 12:24
realistic-ns-with-actions.raku
#!/usr/bin/env raku
use v6.d;
#use Grammar::Tracer;
grammar RealisticNs {
token TOP { <realistic-ns> }
token realistic-ns { <lparen>
<ns-keyword> <.ws> <ns-name> <.ws>
@samebchase
samebchase / raku-grammars.md
Last active November 29, 2020 13:35
[WIP]: Raku Grammars

Parsing Clojure namespace forms using Raku grammars

One day, I started wondering if it would be possible to parse Clojure namespace forms and generate a dependency graph of the various namespaces used in a real-world Clojure project. While that was the original motivation, I ended up down the Raku grammar rabbit hole, and had an enjoyable time learning how to use them. I'm glad you're joining me in reliving that journey.

Background

@samebchase
samebchase / Usage.txt
Created April 2, 2020 15:48
Utility to convert milliseconds since the UNIX Epoch to a readable timestamp. Also, handles timezone offsets.
~
❯ timestamp-from-ms 1585725108000
2020-04-01T07:11:48Z
~
❯ timestamp-from-ms 1585725108000 +5:30
2020-04-01T12:41:48+05:30
~
❯ timestamp-from-ms 1585725108000 -5:30
2020-04-01T01:41:48-05:30
~
#include <vector>
#include <cassert>
#include <iostream>
#include <forward_list>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
@samebchase
samebchase / print_triangle.ml
Created May 1, 2014 21:40
Print a triangle
(* http://www.problemotd.com/problem/party-hat/ *)
open Core.Std;;
open Sequence;;
let print_party_hat height =
let hat_width line_no =
2*line_no + 1 in
let print_char_n char n =
String.make n char
#include <map>
#include <tuple>
#include <vector>
#include <iostream>
#include <algorithm>
template<typename KeyType>
std::pair<KeyType, std::size_t> most_frequent_element(std::vector<KeyType> elts) {
std::map<KeyType, std::size_t> frequency_table;
@samebchase
samebchase / shortest_path.ml
Last active August 29, 2015 14:00
Learning how to use the ocamlgraph library
open Graph
module Vertex = struct
type t = string
let compare = Pervasives.compare
let hash = Hashtbl.hash
let equal = (=)
end
module Edge = struct