Skip to content

Instantly share code, notes, and snippets.

@adamhjk
adamhjk / BUCK
Last active April 27, 2023 23:27
Brutalist buck2 + cargo rule
load("//build-rules/cargo.bzl", "cargo_library")
cargo_library(
name = "dal",
package = "dal",
build_type = "debug",
srcs = glob(["lib/dal/**/*.rs", "lib/dal/build.rs"]),
out = "libdal"
)
@adamhjk
adamhjk / service.rs
Created May 28, 2020 14:34
tonic with tracing, opentelemetry, and context propagation
use opentelemetry::api::propagation::text_propagator::HttpTextFormat;
use tracing::{debug, info};
use tracing_futures::Instrument as _;
use tracing_opentelemetry::OpenTelemetrySpanExt as _;
#[tonic::async_trait]
impl crate::protobuf::kubernetes_server::Kubernetes for Service {
async fn kubernetes_deployment_component_get(
&self,
mut request: tonic::Request<crate::protobuf::KubernetesDeploymentComponentGetRequest>,
@adamhjk
adamhjk / trace_prop.ts
Last active May 20, 2020 19:17
Opentelemetry manual trace propagation
import { WebTracerProvider } from "@opentelemetry/web";
import { ZoneContextManager } from "@opentelemetry/context-zone";
import { CollectorExporter } from "@opentelemetry/exporter-collector";
import * as api from "@opentelemetry/api";
const provider = new WebTracerProvider({
//plugins: [new DocumentLoad() as any, new UserInteractionPlugin()],
plugins: [new DocumentLoad() as any],
});
provider.addSpanProcessor(
@adamhjk
adamhjk / simpleTypescript.ts
Created April 22, 2020 14:30
A simple example of typescript being helpful
interface AssociationConstructor {
typeName: Association["typeName"];
methodName: Association["methodName"];
fieldName?: Association["fieldName"];
}
interface BelongsToConstructor
extends Omit<AssociationConstructor, "methodName"> {
fromFieldPath: BelongsTo["fromFieldPath"];
methodName?: Association["methodName"];
@adamhjk
adamhjk / proto-annotate.toml
Last active January 15, 2020 04:50
What I mean about graphql
protoPackageName = "si.account"
service.Account.CreateAccount.skipauth = true
service.Account.CreateAccount.mutation = true
service.Account.GetBillingAccount.query = true
service.Account.CreateUser.mutation = true
service.Account.GetUser.query = true
service.Account.ListUsers.query = true
service.Account.ListWorkspaces.query = true
service.Account.ListOrganizations.query = true
@adamhjk
adamhjk / integration.rs
Created December 5, 2019 19:47
tonic integration tests
use lazy_static::lazy_static;
use tokio;
use tracing::{self, debug};
use tracing_subscriber::{self, EnvFilter, FmtSubscriber};
use ureq;
use std::env;
use si_account::{protobuf, protobuf::server::Account, service::Service};
use si_data::Db;
@adamhjk
adamhjk / sample.rs
Created February 15, 2016 20:43
Sample of exhaustive pattern matching
pub fn wait_for_leader(&self) -> bool {
self.wait_for_it(Duration::seconds(5), || {
let election = self.election();
match election.find_path(&["mine", "status"]) {
Some(status) => match status.as_string() {
Some("Finished") => true,
Some(_) => false,
None => false,
},
None => false,
case ENV['CHEF_ENVIRONMENT']
when "a"
chef_server_url "http://a/organizations/FOO"
client_key "a.pem"
when "b"
chef_server_url "http://b/organizations/FOO"
client_key "b.pem"
end
#[derive(Debug, Clone, Copy)]
pub enum State {
Init,
Configure,
Starting,
Running,
Finished,
}
pub struct Default {
@adamhjk
adamhjk / chef_style.rs
Created March 23, 2015 23:06
Chef Style DSL in Rust
// This code actually works, and does the equiv to what Chef code would do.
// It also works as a 'reader' for things, so you can get the data back
// when you as for it.
#[macro_use] extern crate chef;
fn cleaner() {
let file = file_r!{"/etc/passwd");
// Would print Some(0)
println!("file owner: {:?}", file.owner());
// A create action