Skip to content

Instantly share code, notes, and snippets.

View samebchase's full-sized avatar
🦑

Samuel Chase samebchase

🦑
View GitHub Profile
use std::strbuf::StrBuf;
fn reverse_sentence(sentence: ~str) -> ~str {
let mut buffer = StrBuf::new();
let mut string_vector: Vec<~str> = Vec::new();
for word in sentence.split(' ') {
string_vector.push(word.to_owned());
}
#include<iostream>
#include<vector>
using std::vector;
using std::cout;
using std::endl;
using std::cin;
int main(void)
@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
#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 / 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 <vector>
#include <cassert>
#include <iostream>
#include <forward_list>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
@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
~
@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 / 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 / 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 { ')' }