This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fetch, { Headers } from "node-fetch" | |
import * as p from "path" | |
const { HUBOT_GRAFANA_HOST, HUBOT_GRAFANA_API_KEY } = process.env | |
async function fetchFromGrafanaApi(path: string) { | |
let url = p.join(HUBOT_GRAFANA_HOST!, path) | |
let response = await fetch(url, { | |
method: "GET", | |
headers: new Headers({ | |
Authorization: `Bearer ${HUBOT_GRAFANA_API_KEY}`, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint esversion:6*/ | |
window.addEventListener("load", (event) => { | |
const video = document.querySelector("video"); | |
var model; | |
var cameraMode = "environment"; // or "user" | |
const startVideoStreamPromise = navigator.mediaDevices | |
.getUserMedia({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddScopedByHiddenCookie<IMessageService, HiddenMessageService, DefaultMessageService>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class HiddenCookieExtensions | |
{ | |
public static IServiceCollection AddScopedByHiddenCookie<TService, THiddenImplementation, TDefaultImplementation>(this IServiceCollection services) | |
where TService: class | |
where THiddenImplementation: TService | |
where TDefaultImplementation: TService | |
{ | |
services.AddScoped<TService>(provider => | |
{ | |
var context = provider.GetRequiredService<IHttpContextAccessor>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddControllers(); | |
services.AddHttpContextAccessor(); | |
services.AddTransient<DefaultMessageService>(); | |
services.AddTransient<ISecretKey, SecretKey>(); | |
services.AddTransient<HiddenMessageService>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DefaultMessageService : IMessageService | |
{ | |
public string GetMessage() => "Hello world!"; | |
} | |
public class HiddenMessageService : IMessageService | |
{ | |
private readonly ISecretKey _key; | |
public HiddenMessageService(ISecretKey key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IMessageService | |
{ | |
string GetMessage(); | |
} | |
[ApiController] | |
[Route("")] | |
public class MyController : ControllerBase | |
{ | |
private readonly IMessageService _messageService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df_delta = (spark.read | |
.format("delta") | |
.load("/mnt/{prefix}-{topic}-delta/delta-table")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w = df.writeStream; | |
if not streaming: | |
w = w.trigger(once=True) | |
(w.format("delta") | |
.option("checkpointLocation", checkpoint_location) | |
.foreachBatch(upsertToDelta) | |
.outputMode("update") | |
.start(delta_location)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upsertToDelta(df, batch_id): | |
(DeltaTable | |
.forPath(spark, delta_location) | |
.alias("t") | |
.merge(df.alias("s"), "s.kafka_key = t.kafka_key") | |
.whenMatchedUpdateAll() | |
.whenNotMatchedInsertAll() | |
.execute()) |
NewerOlder