Skip to content

Instantly share code, notes, and snippets.

@robinglen
robinglen / slack.js
Last active September 2, 2022 12:31
Format messages to send to Slack for Bookworms integration
import slackifyMarkdown from "slackify-markdown";
const headerForSlackMessage = () => {
return [
{
type: "header",
text: {
type: "plain_text",
text: "Bookmarks",
},
@robinglen
robinglen / bookworms.js
Last active September 2, 2022 12:31
How to load bookmarks and use them for Slack integration
// importing the required exposed methods from bookworms
import { loadBookmarks, generateBookmarks } from "bookworms";
// don't really like this global but its fine for this hack
let bookmarks = "";
// load the config into memory
const init = async () => {
// for production add some error handling
const { body } = await loadBookmarks.fetchBookmarkConfig("./bookmarks.yaml");
@robinglen
robinglen / server.js
Last active September 2, 2022 12:31
Fastify server for Bookworms slack integration
import Fastify from "fastify";
import fastifyForm from "fastify-formbody";
import { init } from "./bookworms.js";
import { sendBookMarks, sendBookmarkCommands} from "./slack.js";
const fastify = Fastify();
// fastifyForm is needed to get the body from a POST request
fastify.register(fastifyForm);
// creating a hook for Slack slash commands
@robinglen
robinglen / hello-world-node-fastify-clustered.js
Created September 16, 2018 16:34
Simple hello world in Node, using Fastify and clustering for Medium post
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
const fastify = require('fastify')();
const port = 8123;
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
@robinglen
robinglen / hello-world-node-fastify.js
Created September 16, 2018 16:32
Simple hello world in Node, using Fastify for Medium post
const fastify = require('fastify')();
const port = 8123;
fastify.get('*', (req, res) => {
res.send('Hello World');
});
fastify.listen(port, () => {
console.log(`Fastify "Hello World" listening on port ${port}`);
});
@robinglen
robinglen / hello-world-node-native.js
Last active September 13, 2018 11:55
Simple hello world in Node, using native HTTP for Medium post
const http = require('http');
const port = 8123;
const server = http.createServer((req, res) => {
res.write('Hello World');
res.end();
});
server.listen(port, () => {
console.log(`HTTP "Hello World" listening on port ${port}`);
@robinglen
robinglen / hello-world.go
Created September 13, 2018 11:48
Simple hello world in Go for Medium post
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {