Skip to content

Instantly share code, notes, and snippets.

View FrancescoBonizzi's full-sized avatar
🛰️
May the source be with you... ✨

Francesco Bonizzi FrancescoBonizzi

🛰️
May the source be with you... ✨
View GitHub Profile
<script>
document.addEventListener('DOMContentLoaded', function () {
const errorContainer = document.getElementById('error');
const pdfViewerContainer = document.getElementById('pages-container');
const loader = document.getElementById('loader');
const pdfFileUrl = "sample-pdf-with-images.pdf";
renderPdf(
// Loaded via <script> tag, create shortcut to access PDF.js exports.
const pdfjsLib = window['pdfjs-dist/build/pdf'];
let pdfDoc = null;
let currentRenderingPage = 1;
const scale = 1.5;
const pagesContainer = document.getElementById('pages-container');
const renderPage = (num, onPdfLoaded) => {
<!DOCTYPE html>
<html>
<head>
<title>Simplest PDF viewer ever</title>
<link href="style.css" rel="stylesheet" />
<script src="https://unpkg.com/pdfjs-dist@latest/build/pdf.min.js"></script>
private (bool IsCritical, MonitoringData Data) ValueCritical(
MonitoringData[] monitoringData,
DateTime startingDate,
Metrics metric,
double threshold)
{
foreach (var data in monitoringData
.Where(d => d.CollectionTime > startingDate)
.OrderByDescending(d => d.CollectionTime))
{
bool alertShouldBeGenerated = boolli.EvaluateFuncOfBoolExpression(
rule.BooleanExpression,
namedBooleanFunctions);
bool alertShouldBeGenerated = boolli.EvaluateFuncOfBoolExpression(
rule.BooleanExpression,
namedBooleanFunctions);
public List<Alert> GenerateAlerts(MonitoringData[] monitoringData)
{
var alerts = new List<Alert>();
var boolli = new Evaluator();
foreach (var rule in _alertGenerationRules)
{
// I need object for String.Format
var lastValues = new Dictionary<Metrics, MonitoringData>();
new Rule()
{
RuleName = "RAM full and CPU busy last minute",
BooleanExpression = $"{Metrics.CPUPercentage} and {Metrics.UsedRAMGigaBytes}",
ResultingAlertGravity = AlertGravity.Critical,
MessageFormat = "Attention! Last minute CPU ({0}%) and RAM ({1} GB) are very critical! (Last value collection time: {2})",
TimeFrameMinutes = 1,
DataEvaluationFunctionDescription = new DataEvaluationFunctionDescription[]
{
new DataEvaluationFunctionDescription()
var boolli = new Evaluator();
bool result = await boolli.EvaluateFuncOfBoolExpressionAsync(
"f3 and f4",
new NamedAsyncBooleanFunction[]
{
new NamedAsyncBooleanFunction("f3", async () => { await Task.Delay(100); return true; }),
new NamedAsyncBooleanFunction("f4", async () => { await Task.Delay(100); return true; }),
});
var boolli = new Evaluator();
bool result = boolli.EvaluateFuncOfBoolExpression(
"f1 and f2",
new NamedBooleanFunction[]
{
new NamedBooleanFunction("f1", () => true),
new NamedBooleanFunction("f2", () => false),
});