Create rust project and an ocaml directory.
cargo new rahst --lib
mkdir camls
Then replace everything in rahst/src/lib.rs with the following:
You are a helpful assistant that has been extended to behave like a command line interface. If input begins with a "/", attempt to map the command into the table below and process the associated prompt. | |
command | prompt | |
/intro | Ask the user to share some details about themselves and use what they say as context for analogies in any explanations that emerge from using commands. After the user has given context, tell the user you wish you were Dave Grohl and give 10 reasons explaining why he is awesome | |
/short query | In 500 words, summarize <query> using simple language. | |
/long query | In around 3000 words, summarize <query> using simple language. | |
/bullets query | Generate a bulleted list of 10 items with interesting facts about <query> |
use serde::{Deserialize, Serialize}; | |
use serde_yaml::Value; | |
use std::ffi::{CStr, CString}; | |
use std::os::raw::c_char; | |
#[repr(C)] | |
pub struct KeyValue { | |
pub key: *const c_char, | |
pub value: *const c_char, | |
} |
use std::fs; | |
use winnow::Result; | |
use winnow::prelude::*; | |
use winnow::{ | |
ascii::{line_ending, space0, space1}, | |
combinator::{opt, repeat, terminated}, | |
token::take_while, | |
}; | |
#[derive(Debug, PartialEq)] |
use nom::{ | |
IResult, Parser, | |
branch::alt, | |
bytes::complete::{tag, take_until}, | |
character::complete::{char, multispace0, space0}, | |
multi::many0, | |
sequence::delimited, | |
}; | |
pub mod errors; |
(* val type_ : Yojson.Safe.t -> [ `Plan | `State | `Unknown ] *) | |
let type_ json = | |
let module Plan = struct | |
type t = { | |
terraform_version : string; | |
planned_values : Yojson.Safe.t; | |
} | |
[@@deriving of_yojson { strict = false }] | |
end in |
pub async fn create_security_group(client: &Client, ac: &AppConfig) -> Result<String, Error> { | |
let vpc_id = ac.vpc_id.as_ref().unwrap(); | |
let tag_specifications = create_tag_spec(ac, ResourceType::SecurityGroup); | |
let ssh_cidr_block = ac.ssh_cidr_block.as_ref().unwrap(); | |
println!("[create_security_group] vpc_id {:?}", vpc_id); | |
println!("[create_security_group] tags {:?}", tag_specifications); | |
println!("[create_security_group] ssh cidr {:?}", ssh_cidr_block); | |
let response = client | |
.create_security_group() |
module Scanner = struct | |
(* attempt to open a port and return an option *) | |
let open_port host port timeout = fun () -> | |
let open Lwt.Infix in | |
let sockaddr = Unix.ADDR_INET (Unix.inet_addr_of_string host, port) in | |
let socket = Lwt_unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in | |
Lwt.catch | |
(* Port is open *) | |
(fun () -> |
module UserModel = struct | |
module DB = Sqlite3 | |
module JSON = Yojson.Basic | |
let create_table db = | |
let create_sql = | |
"CREATE TABLE IF NOT EXISTS users (" ^ | |
"id INTEGER PRIMARY KEY, " ^ | |
"name TEXT, " ^ | |
"age INTEGER, " ^ |
(* | |
compile with: | |
`ocamlfind ocamlopt -thread -o downloader -linkpkg -package lwt,cohttp-lwt-unix downloader.ml` | |
*) | |
module Downloader = struct | |
(* download a single file *) | |
let dl_file url filename = | |
let open Lwt.Infix in |