Skip to content

Instantly share code, notes, and snippets.

View zoernert's full-sized avatar

Thorsten Zoerner zoernert

View GitHub Profile
Metric CO2Eq
blocks 1
bounce_drops 2
bounces 2
clicks 2
deferred 2
delivered 20
invalid_emails 0
opens 10
processed 15
@zoernert
zoernert / totalco2.js
Created September 16, 2021 22:36
Calculating total CO2 Emission of MailStats
let totalco=0;
for(let i=0;i<mailStats.length;i++) {
for(let j=0;j<mailStats[i].stats.length;j++) {
for (const [key, value] of Object.entries(mailStats[i].stats[j].metrics)) {
if(key == "blocks") totalco2+=1
if(key == "bounce_drops") totalco2+=2
if(key == "bounces") totalco2+=2
if(key == "clicks") totalco2+=2
if(key == "deferred") totalco2+=2
@zoernert
zoernert / sendgridCO2compensation.js
Created September 16, 2021 22:48
Sendgrid CO2 Offsetting using RapidAPI service
const sendgridAPIKey = 'YOUR_SENDGRID_API_KEY';
const rapidAPIKey = 'YOUR_RAPIDAPI_KEY';
const fromDate = new Date(new Date().getTime() - (7*87600000)).toISOString().split('T')[0]; // last 7 days
const axios = require("axios");
// Retrieve Statistics from Sendgrid
const sendgridStatsResponds = await axios.get("https://sendgrid.com/v3/stats?start_date="+fromDate,{
headers: {
@zoernert
zoernert / runkit.js
Created September 16, 2021 23:06
Runkit implementation of Sendgrid CO2 Offset Script
const app = async function() {
const sendgridAPIKey = process.env.sendgridAPIKey;
const rapidAPIKey = process.env.rapidAPIKey;
const fromDate = new Date(new Date().getTime() - (7*87600000)).toISOString().split('T')[0]; // last 7 days
const axios = require("axios");
// Retrieve Statistics from Sendgrid
@zoernert
zoernert / RunInPostman.md
Created October 4, 2021 14:39
CO2 Offset in Postman

Run in Postman

@zoernert
zoernert / openapi3.yaml
Created October 5, 2021 01:53
ID-Ideal AP8 - CO2 Event - Structure Definition
openapi: 3.0.0
info:
title: ID-Ideal - AP8
description: >
Sample Requests using the [Corrently Ecosystem](https://corrently.io) as implementation. You might get an `account` using the [Create Stromkonto Endpoint](https://api.corrently.io/v2.0/stromkonto/create) or use one from an existing eWallet.
[![Run in Postman](https://run.pstmn.io/button.svg)](https://god.gw.postman.com/run-collection/15081091-766401d6-06c2-47a3-bb3e-35aac41992d9?action=collection%2Ffork&collection-url=entityId%3D15081091-766401d6-06c2-47a3-bb3e-35aac41992d9%26entityType%3Dcollection%26workspaceId%3D9bdc41fc-ebac-4de7-96fb-4e7650494186)
contact: {}
version: '1.0'
@zoernert
zoernert / contracts...espaccounting.sol
Created December 29, 2021 11:54
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.11+commit.d7f03943.js&optimize=true&runs=200&gist=
pragma solidity ^0.8.0;
import "./espledger.sol";
contract espaccounting {
mapping (address => espledger) public ledgers;
function transfer(address from,address to, uint256 value) public returns (bool success) {
espledger ledger = ledgers[msg.sender];
@zoernert
zoernert / contracts...espledger.sol
Created December 29, 2021 11:56
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.11+commit.d7f03943.js&optimize=true&runs=200&gist=
pragma solidity ^0.8.0;
contract espledger {
mapping (address => uint256) public balanceDebit;
mapping (address => uint256) public balanceCredit;
uint256 public totalSupply = 0;
@zoernert
zoernert / step1.json
Created January 5, 2022 12:34
Sample Flow
[{"id":"db85efb31b8d6c63","type":"tab","label":"Presentation Processing Service","disabled":false,"info":""},{"id":"bc8ea23eafbd50c9","type":"SmartContract","z":"db85efb31b8d6c63","name":"Alice","Connection":"709fcd56ae2bfcc5","Contract":"446e716af8a146aa","Resolver":"79856bb80496c409","AllowInject":"","RetryTX":true,"rapidAPIkey":"","pps":"","x":490,"y":100,"wires":[[],[],["8b80cd4520f6c3f6"],[]]},{"id":"55bf9f3bf037d791","type":"inject","z":"db85efb31b8d6c63","name":"Buy MegaConcert Ticket","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"presentation\":{\"event\":\"Mega Concert\"}}","payloadType":"json","x":290,"y":100,"wires":[["bc8ea23eafbd50c9"]]},{"id":"8b80cd4520f6c3f6","type":"debug","z":"db85efb31b8d6c63","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":100,"wires":[]},{"id":"709fcd56ae2bfcc5","type":"DLTConnection","name":"Integr
@zoernert
zoernert / step2.json
Created January 5, 2022 13:03
Sample Flow
[{"id":"db85efb31b8d6c63","type":"tab","label":"Presentation Processing Service","disabled":false,"info":""},{"id":"bc8ea23eafbd50c9","type":"SmartContract","z":"db85efb31b8d6c63","name":"Alice","Connection":"709fcd56ae2bfcc5","Contract":"446e716af8a146aa","Resolver":"79856bb80496c409","AllowInject":"","RetryTX":true,"rapidAPIkey":"","pps":"","x":490,"y":100,"wires":[[],[],["902e10e94df6036e"],[]]},{"id":"55bf9f3bf037d791","type":"inject","z":"db85efb31b8d6c63","name":"Buy MegaConcert Ticket","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"presentation\":{\"event\":\"Mega Concert\"}}","payloadType":"json","x":290,"y":100,"wires":[["bc8ea23eafbd50c9"]]},{"id":"902e10e94df6036e","type":"SmartContract","z":"db85efb31b8d6c63","name":"TicketA","Connection":"d26ccfb316876b3e","Contract":"446e716af8a146aa","Resolver":"79856bb80496c409","AllowInject":"","RetryTX":true,"rapidAPIkey":"","pps":"http://localhost:1880/eventPPS","x":680,"y":1