Skip to content

Instantly share code, notes, and snippets.

View pmbanugo's full-sized avatar
:shipit:

Peter Mbanugo pmbanugo

:shipit:
View GitHub Profile
@pmbanugo
pmbanugo / hacker-news.js
Created February 1, 2024 22:47
Cron Atlas: Top 5 HackerNews Stories Via Email
export async function handler() {
const topStoriesUrl = "https://hacker-news.firebaseio.com/v0/topstories.json";
// Fetch the top stories IDs
const response = await fetch(topStoriesUrl);
const storyIds = await response.json();
const top5StoryIds = storyIds.slice(0, 5);
// Fetch the story details for each top story in parallel
const storyDetailsPromises = top5StoryIds.map((id) =>
fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`).then((res) =>
@pmbanugo
pmbanugo / knative-kong-routing.yaml
Created January 29, 2022 18:57
Kong Ingress Route to multiple ksvc based on path & HTTP Method
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: hello-service-host-rewrite
# The plugin must be created in the same namespace as the ingress.
namespace: kong
plugin: request-transformer
config:
add:
headers:
createNotification(message) {
return new Notification(`${message.author.name} sent a message`, {
body: message.text
});
}
checkNotificationPromise() {
try {
Notification.requestPermission().then();
} catch (e) {
return false;
}
return true;
}
componentDidMount() {
this.askNotificationPermission();
}
askNotificationPermission = async () => {
// check if the browser supports notifications
if ("Notification" in window) {
if (this.checkNotificationPromise()) {
const permission = await Notification.requestPermission();
this.handlePermission(permission);
<div style="text-align:center">
<h1>Conversational UI</h1>
</div>
<kendo-chat [messages]="messages" [user]="user"></kendo-chat>
export class AppComponent {
readonly bot: User = {
id: 0,
name: "bot"
};
user: User = { id: Date.now().toString() };
messages: Message[] = [
{
author: this.bot,
sendMessage(e: SendMessageEvent): void {
const message = e.message;
if (!this.user.name) {
this.user.name = message.text;
let newMessage = Object.assign({}, message);
newMessage.text = `Welcome to the chat ${message.text}!`;
newMessage.author = this.bot;
this.messages = [...this.messages, newMessage];
} else {
<kendo-chat
[messages]="messages"
[user]="user"
(sendMessage)="sendMessage($event)"
></kendo-chat>
private conversation: Channel;
async initialiseChatClient(): Promise<void> {
const response = await fetch("http://localhost:8080/v1/token", {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({