Skip to content

Instantly share code, notes, and snippets.

View jac18281828's full-sized avatar
🦌

John Cairns jac18281828

🦌
View GitHub Profile
@jac18281828
jac18281828 / golangci.yml
Created September 14, 2024 15:23
go lang lint example
run:
timeout: 5m
linters:
disable-all: true
enable:
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # detects when assignments to existing variables are not used
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
@jac18281828
jac18281828 / animal.rs
Created September 10, 2024 00:23
Rust trait plaything
use core::panic;
trait Animal {
fn name(&self) -> &'static str;
fn talk(&self) {
println!("{} cannot talk", self.name());
}
}
struct Dog;
@jac18281828
jac18281828 / diehard.rs
Last active September 2, 2024 22:22
The generalized diehard problem in rust
use std::collections::{HashSet, VecDeque};
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
struct State {
containers: Vec<i64>,
}
#[derive(Debug, Clone, Eq, PartialEq)]
enum Operation {
Fill(usize), // Fill container i
@jac18281828
jac18281828 / parse_number_or_name.rs
Created August 30, 2024 17:40
Parse values of different types in rust, pipelined
use anyhow::Result;
enum Numbers {
One,
Two,
Three,
}
enum Names {
@jac18281828
jac18281828 / dal.rs
Last active August 28, 2024 16:40
DataAccessLayr example DAL in rust
trait DataAccessLayr {
fn init() -> Self;
fn write(&self, status: &eigenlayer::OperatorAVSRegistrationStatus) -> eyre::Result<()>;
fn read(&self, status: &mut eigenlayer::OperatorAVSRegistrationStatus) -> eyre::Result<()>;
}
@jac18281828
jac18281828 / alloy.rs
Last active August 27, 2024 19:27
Alloy working with struct ABI data
use eyre::Result;
use tracing::debug;
use serde::{Serialize, Deserialize};
use alloy::{
primitives::{Address, U256, B256},
sol,
};
use IRewardsCoordinator::RewardsClaimed;
@jac18281828
jac18281828 / rpcserver.rs
Created August 21, 2024 16:59
run jsonrpsee RpcServer
pub async fn run_server(host: String, port: u16) -> eyre::Result<SocketAddr> {
// Add a CORS middleware for handling HTTP requests.
// This middleware does affect the response, including appropriate
// headers to satisfy CORS. Because any origins are allowed, the
// "Access-Control-Allow-Origin: *" header is appended to the response.
let cors = CorsLayer::new()
// Allow `POST` when accessing the resource
.allow_methods([Method::POST])
// Allow requests from any origin
.allow_origin(Any)
@jac18281828
jac18281828 / config.rs
Created August 20, 2024 19:08
config.json in rust
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct Config {
#[serde(rename = "serverHost", default = "default_host")]
pub server_host: String,
#[serde(rename = "serverPort", default = "default_port")]
pub server_port: u16,
}
@jac18281828
jac18281828 / Dockerfile
Created August 3, 2024 00:36
Certora Dockerfile
FROM debian:stable-slim
RUN export DEBIAN_FRONTEND=noninteractive && \
apt update && \
apt install -y -q --no-install-recommends \
ca-certificates apt-transport-https \
curl sudo \
python3-pip python3-venv python3 \
default-jre && \
apt clean && \
@jac18281828
jac18281828 / Dockerfile
Created July 30, 2024 19:00
Install ethereum in ubuntu Dockerfile
FROM ubuntu:24.04
ARG HTTP_PORT=8545
ARG ETH_VERSION=1.14.7
RUN apt-get update \
&& apt-get install -y software-properties-common \
&& add-apt-repository -y ppa:ethereum/ethereum \
&& apt-get update \
&& apt-get install -y ethereum sudo \