Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
willmurphyscode / temp.md
Created December 7, 2023 13:41
Temp: difference between GHSA schema and Vunnel schema

sqlite3 data/github/results/results.db "select record from results where id like '%GHSA-v7hc-87jc-qrrr%';" | jq . produces:

{
  "schema": "https://raw.githubusercontent.com/anchore/vunnel/main/schema/vulnerability/github-security-advisory/schema-1.0.1.json",
  "identifier": "github:go/ghsa-v7hc-87jc-qrrr",
  "item": {
    "Vulnerability": {},
    "Advisory": {
      "Classification": "GENERAL",
@willmurphyscode
willmurphyscode / main.go
Created November 4, 2023 09:32
mapstructure example
package main
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type moduleConfig struct {
ModuleBool bool `yaml:"module-bool" mapstructure:"module-bool"`
struct SomeCollection<'a> {
strings: Vec<&'a str>
}
impl<'a> SomeCollection<'a> {
pub fn new() -> Self {
SomeCollection { strings: Vec::new() }
}
pub fn insert(&mut self, s: &'a str) {
# first version
my_collection = SomeCollection.new
(1..10).each do |item|
value = "value number #{item + 1}"
my_collection.insert(value)
end
# second version
my_collection = SomeCollection.new
values = []
struct SomeCollection {
strings: Vec<String>
}
impl SomeCollection {
pub fn new() -> Self {
SomeCollection { strings: Vec::new() }
}
pub fn insert(&mut self, s: String) {
struct SomeCollection<'a> {
strings: Vec<&'a str>
}
impl<'a> SomeCollection<'a> {
pub fn new() -> Self {
SomeCollection { strings: Vec::new() }
}
pub fn insert(&mut self, s: &'a str) {
pub fn reduce_or(stack: &mut Vec<Token>) -> Result<Token, RuntimeError> {
// would return Err if the vector were not entirely
// made of Token::Operand(Type::Bool), since we can't reduce with `or`
// other values
let bool_result = unwrap_boolean_tokens(stack);
if let Ok(bool_vec) = bool_result {
Ok(Token::Operand(Type::Bool(
bool_vec.iter().any(|b| *b) // and reducer has "all" here
)))
} else {
fn reduce_subtraction(stack: &mut Vec<Token>) -> Result<Token, RuntimeError> {
let operands = unwrap_operand_tokens(stack);
match operands {
Ok(mut operand_vec) =>{
let initial_positive_option = operand_vec.pop();
if let Some(initial_positive) = initial_positive_option {
Ok(Token::Operand(
operand_vec
.iter()
.fold(initial_positive, |sum, value| sum - value)))
fn reduce_addition(stack: &mut Vec<Token>) -> Result<Token, RuntimeError> {
let operands = unwrap_operand_tokens(stack);
match operands {
Ok(operand_vec) => Ok(Token::Operand(
operand_vec
.iter()
.fold(0, |sum, value| sum + value))),
Err(_) => Err(RuntimeError{})
}
}
pub fn parse(bytes: &[u8]) -> Result<Vec<Token>, TokenizationError> {
let parse_result = tokens(bytes).to_result();
match parse_result {
Ok(token_vec) => Ok(token_vec),
Err(_) => Err(TokenizationError {})
}
}