Skip to content

Instantly share code, notes, and snippets.

View jmsdnns's full-sized avatar

Jms Dnns jmsdnns

View GitHub Profile
@jmsdnns
jmsdnns / studyguide.prompt
Created May 3, 2025 15:23
A simple prompt you can put in an LLM to get a CLI-style experience with multiple /commands
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>
@jmsdnns
jmsdnns / lib.rs
Created April 24, 2025 18:12
Using Rust library to parse yaml from Ocaml
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,
}
@jmsdnns
jmsdnns / README.md
Created April 23, 2025 18:37
Using Rust library in Ocaml

Example: Calling Rust libs from Ocaml

Create rust project and an ocaml directory.

cargo new rahst --lib
mkdir camls

Then replace everything in rahst/src/lib.rs with the following:

@jmsdnns
jmsdnns / beez_plan_parser_2.rs
Last active March 31, 2025 15:47
I used the nom crate in the previous gist. This uses winnow instead. People don't use nom anymore, apparently. lol
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)]
@jmsdnns
jmsdnns / beez_plan_parser.rs
Created March 30, 2025 15:12
my first try at building a parser for execution plans in killabeez
use nom::{
IResult, Parser,
branch::alt,
bytes::complete::{tag, take_until},
character::complete::{char, multispace0, space0},
multi::many0,
sequence::delimited,
};
pub mod errors;
@jmsdnns
jmsdnns / tf_file_type.ml
Last active March 7, 2025 14:04
pattern matching on terraform json variations
(* 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
@jmsdnns
jmsdnns / create_sg.rs
Created March 1, 2025 19:48
Two ways of saying the same thing: rust & hcl
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()
@jmsdnns
jmsdnns / jmap.ml
Created February 3, 2025 00:14
A port scanner in Ocaml. Rudimentary form done to learn how Ocaml does networking.
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 () ->
@jmsdnns
jmsdnns / jsonlite.ml
Created January 26, 2025 07:15
Querying a sqlite DB from Ocaml. JSON is stored in a column and selects are done on JSON values.
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, " ^
@jmsdnns
jmsdnns / downloader.ml
Last active January 17, 2025 20:24
My first Ocaml program. It downloads two files at the same time using LWT.
(*
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