Skip to content

Instantly share code, notes, and snippets.

View sa-webb's full-sized avatar
:electron:
∑ ƒ ∆

Austin Webb sa-webb

:electron:
∑ ƒ ∆
View GitHub Profile
@zachshallbetter
zachshallbetter / README.md
Created September 29, 2023 21:33
Middleware Examples

Next.js Middleware Examples

This Gist contains a collection of Next.js Middleware examples that demonstrate various use cases and scenarios for enhancing your Next.js applications. Middleware in Next.js allows you to intercept, modify, and control the flow of requests and responses, making it a powerful tool for building robust web applications.

Middleware Examples

  1. Authentication Middleware (authenticationMiddleware.ts):
    • Checks if the user is authenticated based on a session cookie.
    • Redirects unauthenticated users to the login page.
  • Ensures users have the necessary role to access protected routes.
@Hachikoi-the-creator
Hachikoi-the-creator / App.tsx
Last active February 8, 2024 09:07 — forked from nimone/Carousel.jsx
Build a carousel component like instagram purely in ReactJS, TS and TailwindCSS
import Carousel from "./Carousel";
import img1 from "path-to-local-image.jpg";
import img2 from "path-to-local-image.jpg";
import img3 from "path-to-local-image.jpg";
export default function ImageCarousel() {
const slides = [img1, img2, img3];
return (
<div className="relative">
@danielmichaels
danielmichaels / httpx-hackernews-async-example.py
Created July 5, 2020 10:27
A short realworld example of how to use HTTPX's AsyncClient in a sync class.
"""
HackerNews module.
"""
import logging
import asyncio
from operator import itemgetter
import httpx
@ndrbrt
ndrbrt / wait-for-open-websocket-connection.js
Last active April 12, 2024 18:19
Wait for the WebSocket connection to be open, before sending a message.
const waitForOpenConnection = (socket) => {
return new Promise((resolve, reject) => {
const maxNumberOfAttempts = 10
const intervalTime = 200 //ms
let currentAttempt = 0
const interval = setInterval(() => {
if (currentAttempt > maxNumberOfAttempts - 1) {
clearInterval(interval)
reject(new Error('Maximum number of attempts exceeded'))
@rmoff
rmoff / connect_status.sh
Created May 1, 2019 09:58
Show status of all Kafka Connect connectors
curl -s "http://localhost:8083/connectors"| \
jq '.[]'| \
xargs -I{connector_name} curl -s "http://localhost:8083/connectors/"{connector_name}"/status" | \
jq -c -M '[.name,.connector.state,.tasks[].state]|join(":|:")' | \
column -s : -t | \
sed 's/\"//g' | \
sort
@kodekracker
kodekracker / draw_bounding_box_open_cv.py
Created June 20, 2018 18:31
To draw Bounding Box in a image using OpenCV python module
#!/usr/bin/env python
import cv2
import sys
def drawBoundingBoxes(imageData, imageOutputPath, inferenceResults, color):
"""Draw bounding boxes on an image.
imageData: image data in numpy array format
imageOutputPath: output image file path
inferenceResults: inference results array off object (l,t,w,h)
colorMap: Bounding box color candidates, list of RGB tuples.
@miguno
miguno / json-to-avro.sql
Last active December 17, 2022 03:20
Using ksqlDB to convert data (i.e., events/messages) in a Kafka topic from JSON to Avro format.
CREATE STREAM sensor_events_json (sensor_id VARCHAR, temperature INTEGER, ...)
WITH (KAFKA_TOPIC='events-topic', VALUE_FORMAT='JSON');
CREATE STREAM sensor_events_avro WITH (VALUE_FORMAT='AVRO') AS SELECT * FROM sensor_events_json;
@wesbos
wesbos / async-await.js
Created February 22, 2017 14:02
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}