Skip to content

Instantly share code, notes, and snippets.

Learning JavaScript and ReactJS...

Stephane Mensah waptik

Learning JavaScript and ReactJS...
View GitHub Profile
waptik / bot.ts
Created Sep 3, 2021
Custom session adapter for grammyjs using supabase. Please give it a try and comment for feedback
View bot.ts
import { Bot, Context, session, SessionFlavor } from 'grammy'
import { CustomSessionAdapter } from './session'
// This bot will collect some basic statistics about each chat. They can be
// retrieved with the `/stats` command.
// This is the data that will be saved per chat.
interface SessionData {
messages: number
edits: number
waptik / paginate.ts
Created Jul 29, 2021
Mongoose paginate typescript
View paginate.ts
/** @see **/
export async function queryPaginate<T>(
model: ModelType<T>,
pageNum = 1,
filter: MongooseFilterQuery<DocumentType<T>>,
populate?: string[],
): Promise<IPaginatedData<T[]>> {
const [docs, total] = await Promise.all([
waptik / theme.ts
Created Jul 12, 2021
Styling the inner div of tiptap v2 with chakra-ui
View theme.ts
import { extendTheme } from "@chakra-ui/react";
import { mode } from "@chakra-ui/theme-tools";
// Currently a bug with theme.config typings for initialColorMode. Workaround.
interface ThemeConfig {
useSystemColorMode?: boolean;
initialColorMode: "light" | "dark";
waptik / index.ts
Created Jul 12, 2021
A custom extension for tiptap v2 to for image upload
View index.ts
import { Node, nodeInputRule } from "@tiptap/core";
import { mergeAttributes } from "@tiptap/react";
import { uploadImagePlugin, UploadFn } from "./upload_image";
* Tiptap Extension to upload images
* @see
* @since 7th July 2021
View bypass-isp.txt
## Introduction
Whenever you open a website, your device will send DNS request, most internet connection uses ISP's DNS servers by default, so basically your ISP and possibly government could know what sites you access.
This is basically how site blocking works.
Many ISPs have a blocklist on their DNS servers, if your device sends DNS request of a domain that is in their blocklist, they will block it.
Fortunately there are many ways to bypass it, one of them is by changing DNS on our devices, but if you are using a traditional way like by using and, ISP could still sniff and intercept the DNS request because it's un-encrypted.
waptik / test_array_of_objects.js
Last active May 8, 2021
[SOLVED] - I need help to: 1: rename keys to lowercase values 2: remove empty objects with one non-null key
View test_array_of_objects.js
// current code
const arrs = [
comments: 'asd',
movement: 'Back Squat',
userID: 'wDHZv3OL55SIymHkhMUejNleNkx1',
weight: '330',
waptik / trackImages.ts
Last active Apr 18, 2021
How to get and save photo by group media in telegrafjs
View trackImages.ts
import { Composer, MiddlewareFn } from "telegraf"
import { logAction } from "app/core/helpers/logAction"
import { BotContext } from "types"
import { report } from "../helpers"
import { withoutKeys } from "app/core/helpers/misc"
import { Message } from "typegram"
// @see
waptik / regex id.ts
Last active Apr 2, 2021
regex to filter bot command and args
View regex id.ts
// ref
const re=/(?<code>(c|g)_\w+)(.)(?<to>to)(.)(?<id>id\d+)/
console.log(re.exec("c_84www to id890890")) // returns ["c_84www to id890890", "c_84www", "c", " ", "to", " ", "id890890", index: 0, input: "c_84www to id890890", groups: {code: "c_84www", to: "to", id: "id890890"}]
waptik / example.ts
Created Apr 2, 2021
implementation of telegraf-session using Prisma as datastore based on
View example.ts
import { Context, Telegraf } from 'telegraf'
import { PrismaClient } from '@prisma/client'
import { session } from 'utils/telegraf-session-prisma' // path to session module
const prisma = new PrismaClient()
interface SessionData {
messageCount: number
// ... more session data go here
waptik / toSlug.ts
Created Mar 29, 2021
Generate slugs following's pattern
View toSlug.ts
import { parameterize } from "inflected"
import { nanoid } from "nanoid"
export function toSlug(slug: string) {
slug = parameterize(slug)
const nano = nanoid(4)
const id = nano.toLowerCase().replace(/[-_]/g, "")
return `${slug.replace("_", "")}-${id}`