Skip to content

Instantly share code, notes, and snippets.

@alexsavio
alexsavio / nested_access.py
Created August 30, 2022 12:53
Python simple nested structure access
# -*- coding: utf-8 -*-
from functools import singledispatch
def getvalue(value, path, default=None):
"""Get a named attribute or item from an object; getvalue(x, 'y.z')
is equivalent to x.y.z
When a default argument is given, it is returned when the attribute doesn't
exist; without it, None returned
List indexing supported x.0.y.1.z etc.
@alexsavio
alexsavio / handlebars_helpers.rs
Created October 10, 2023 09:01
handlebars helpers
use handlebars::{Handlebars, RenderError, HelperDef, RenderContext, Helper, Context, handlebars_helper};
use serde_json::Value as Json;
// #[allow(non_camel_case_types)]
// pub struct is_defined;
// impl HelperDef for is_defined {
// fn call_inner<'reg: 'rc, 'rc>(
// &self,
// h: &Helper<'reg, 'rc>,
@alexsavio
alexsavio / handlebars_helpers.md
Created October 21, 2023 07:50
A blog post on how to write Handlebars.rs helpers

Author: Alexandre Manhães Savio [email protected]

Date: 10.10.2023

Handlebars is a modern and extensible templating solution originally created in the JavaScript world. It’s used by many popular frameworks like Ember.js and Chaplin. It’s also ported to some other platforms such as Java.

Handlebars is a template rendering engine but lacks extensive filters and transformers for context data during rendering. Like many such libraries, Handlebars allows you to create custom operations, called 'helpers'.

Here I will write an instruction set on how to write custom helpers for handlebars-rust.

@alexsavio
alexsavio / cargo_lambda_action.yml
Created October 15, 2024 12:40
Raw Github Actions template to run cargo lambda packaging
---
name: "Template: Test, compile and zip Rust Lambdas"
on:
workflow_call:
inputs:
function-name:
required: true
type: string
description: |