Skip to content

Instantly share code, notes, and snippets.

View newme616's full-sized avatar

Matthias Neumayer newme616

View GitHub Profile
import {
defineDocumentType,
ComputedFields,
makeSource
} from 'contentlayer2/source-files';
import { writeFileSync } from 'fs';
import readingTime from 'reading-time';
import GithubSlugger from 'github-slugger';
import path from 'path';
// Remark packages
import asyncio
import base64
import json
import os
import pyaudio
from websockets.asyncio.client import connect
class SimpleGeminiVoice:
def __init__(self):
@newme616
newme616 / posthog-page-view.ts
Created May 29, 2024 07:39
posthog-page-view.ts
"use client";
import { usePathname, useSearchParams } from "next/navigation";
import { useEffect } from "react";
import { usePostHog } from "posthog-js/react";
export default function PostHogPageView() {
const pathname = usePathname();
const searchParams = useSearchParams();
const posthog = usePostHog();
@newme616
newme616 / route.ts
Created April 17, 2024 16:05
handle magic link protection
import NextAuth from "next-auth";
import type { NextApiRequest, NextApiResponse } from "next";
import { authOptions } from "@/lib/auth";
// try to avoid magic link protection from outlook
export async function GET(Request: NextApiRequest, Response: NextApiResponse) {
if (Request.method === "HEAD" || /lua-resty-http.+ngx_lua/.test(Request.headers["user-agent"])) {
console.log("Bot detected");
return Response.status(200).end();
}
@newme616
newme616 / openai.js
Last active March 19, 2024 16:56
openai
const completion = await openai.chat.completions.create({
model: azureId,
temperature: 0.9,
messages: [
{
role: 'system',
content: systemPrompt,
},
{
role: 'user',
<div className="mb-3 flex space-x-4">
{siteConfig.email && (
<a href={`mailto:${siteConfig.email}`}>
<Button variant="ghost" size="icon" aria-label="Email">
<MailIcon className="w-6 h-6" />
</Button>
</a>
)}
{siteConfig.github && (
@newme616
newme616 / gist:cab9ebb566a52e1de6f3256847ff33e8
Created December 6, 2023 10:40
select all checkboxes on page in chrome
(function() {
var aa = document.querySelectorAll("input[type=checkbox]");
for (var i = 0; i < aa.length; i++){
aa[i].checked = true;
}
})()
@newme616
newme616 / rename_md_files.js
Created June 6, 2023 16:18
Rename all .md files based on the title property
const fs = require('fs');
const path = require('path');
const folderPath = './blog2'; // Replace with the actual path to your folder
fs.readdir(folderPath, (err, files) => {
if (err) {
console.error(err);
return;
}
@newme616
newme616 / urlParams.js
Created March 22, 2023 08:21
pass along url params
const queryString = location.search;
// parse the query string into an object of key-value pairs
const urlParams = new URLSearchParams(queryString);
// get the value of the "piwik pro" parameter
const campaign = urlParams.get("pk_campaign");
// get piwik pro param or ref param
const source = urlParams.get("pk_source") || urlParams.get("utm_source") || urlParams.get("ref");
const medium = urlParams.get("pk_medium");
// save the parameter value in state
const urlParam = { campaign: campaign || "website", source: source || "website", medium: medium || "website" };
@newme616
newme616 / deploy.yml
Last active February 26, 2023 14:13
Github Action to deploy Gatsby on a FTP Webserver and adding env Variables
name: Deploy to Web
run-name: ${{ github.actor }} created a deployment.
on:
push:
branches:
- main
- dev