Skip to content

Instantly share code, notes, and snippets.

View waptik's full-sized avatar
💻
Learning JavaScript and ReactJS...

Stephane Mensah waptik

💻
Learning JavaScript and ReactJS...
View GitHub Profile
@waptik
waptik / ngrok_hostname.sh
Created January 21, 2024 22:00 — forked from rjz/ngrok_hostname.sh
Get ngrok hostname from command line
#!/bin/sh
# ngrok's web interface is HTML, but configuration is bootstrapped as a JSON
# string. We can hack out the forwarded hostname by extracting the next
# `*.ngrok.io` string from the JSON
#
# Brittle as all get out--YMMV. If you're still reading, usage is:
#
# $ ./ngrok_hostname.sh <proto> <addr>
#
@waptik
waptik / turbo-workspaces-error.sh
Created January 4, 2024 22:48
cli error message for @turbo/workspaces package when migrating from yarn to pnpm
>>> TURBOREPO
Welcome, let's convert your project.
? Where is the root of your repo? .
? Convert from yarn workspaces to: pnpm workspaces
Converting project from yarn to pnpm.
@waptik
waptik / .gitpod.Dockerfile
Created December 23, 2023 22:28
Current gitpod configuration files for my deno fresh app
FROM gitpod/workspace-full
RUN curl -fsSL https://deno.land/x/install/install.sh | sh
RUN /home/gitpod/.deno/bin/deno completions bash > /home/gitpod/.bashrc.d/90-deno && \
echo 'export DENO_INSTALL="/home/gitpod/.deno"' >> /home/gitpod/.bashrc.d/90-deno && \
echo 'export PATH="$DENO_INSTALL/bin:$PATH"' >> /home/gitpod/.bashrc.d/90-deno
@waptik
waptik / personas.menu.ts
Last active December 18, 2023 18:33
a simple pagination handler in grammY using the menu plugin
let pageIndex = 0;
/**
* A function that generates a paginated menu
*
* @param index The index of the page to generate
* @returns A range of the menu
*/
function personalityMenuRange(
@waptik
waptik / Backsticks.txt
Created November 27, 2023 17:42
Ummmm
Certainly! Here's a TypeScript function that takes a text string as input and returns an array of code snippets found within code blocks wrapped in triple backticks(```) or `<code>`:
```typescript
function extractCodeSnippets(text: string): string[] {
const codeSnippets: string[] = [];
const regex = /```([\s\S]*?)```|<code>([\s\S]*?)<\/code>/g;
let match;
while ((match = regex.exec(text)) !== null) {
const codeSnippet = match[1] || match[2];
@waptik
waptik / 1701015161995.txt
Created November 26, 2023 18:53
chatgpt response from api
Certainly! Here's a TypeScript function that takes a text as input and returns an array of code snippets found within multiple lines code blocks wrapped in triple backticks (```) or `<code>` tags with language tags:
```typescript
function extractCodeSnippets(text: string): { language: string, code: string }[] {
const codeBlockRegex = /```(\w+)\n([\s\S]*?)```|<code(?:\s+class="language-(\w+)")?>([\s\S]*?)<\/code>/g;
const codeSnippets: { language: string, code: string }[] = [];
let match;
while ((match = codeBlockRegex.exec(text)) !== null) {
const [, language1, code1, language2, code2] = match;
@waptik
waptik / crypto.ts
Last active October 23, 2023 03:26
Immitating nodejs' cryptoHmac+Buffer.from in Deno by reproducing lemonsqueezy's webhook payload signing(https://github.com/amosbastian/template/blob/bdc77731d4f0dfef0bd2529205c8dd5b733d5b4a/apps/web/app/api/lemonsqueezy/route.ts#L76)
// @see https://github.com/denoland/deno/blob/main/cli/tests/unit_node/crypto/crypto_hash_test.ts#L17
export * as crypto from 'node:crypto';
@waptik
waptik / bot.ts
Last active October 6, 2023 09:05
An example on how to use grammY's Interactive Menus plugin
// I'm using deno
import "https://deno.land/std@0.178.0/dotenv/load.ts";
import { green } from "https://deno.land/std@0.178.0/fmt/colors.ts";
import { itemsMenu } from './menus/example.menu.ts';
const grammy = new Bot<GrammyContext>(Deno.env.get("BOT_TOKEN")||""); // replace `BOT_TOKEN` inside `.env` file with your own telegram bot's token
// attaching the menu to bot to get it to work if not we'll get the following errors inside the terminal
// `Error: Cannot send menu 'bot-items-menu'! Did you forget to use bot.use() for it?`
@waptik
waptik / bot.ts
Last active August 30, 2023 12:38
This is a minimal codebase of getting grammY to work with nextjs pages directory. Please use this version of `next-connect`: `"next-connect": "^0.13.0",`
import { Bot, Context } from "grammy";
export const bot = new Bot<Context>(process.env.TELEGRAM_BOT_TOKEN ?? "");
// attach your middlewaew, commands and other stuff to your bot
// eg. bot.use(myCommands)
// path: /utils/telegram/bot.ts
@waptik
waptik / webapp.html
Created June 14, 2023 03:58
rendered webapp page in deno fresh
<html
lang="en"
style="--tg-viewport-height: 100vh; --tg-viewport-stable-height: 100vh"
>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script
src="/_frsh/refresh.js"
nonce="1734e1df1f3e44caaee66e087bc657e6"