Skip to content

Instantly share code, notes, and snippets.

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

TheVirginBrokey waptik

💻
Learning JavaScript and ReactJS...
View GitHub Profile
@waptik
waptik / Upload.tsx
Last active October 13, 2022 20:27
A POC for uploading files to a cloudflare r2 public bucket using presigned url in nextjs
// pages/Upload.tsx
import { getPresignedUrl } from "~/utils/files";
export default function Upload() {
const uploadPhoto = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
const name = encodeURIComponent(file?.name as string);
const type = encodeURIComponent(file?.type as string);
const res = await getPresignedUrl({ name, type, size: "" + file!.size });
@waptik
waptik / Upload.tsx
Created October 13, 2022 20:15
A POC of uploading files to a cloudflare r2 public bucket using presigned url
// pages/Upload.tsx
import { getPresignedUrl } from "~/utils/files";
export default function Upload() {
const uploadPhoto = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
const name = encodeURIComponent(file?.name as string);
const type = encodeURIComponent(file?.type as string);
const res = await getPresignedUrl({ name, type, size: "" + file!.size });
@waptik
waptik / aliceData.ts
Created August 30, 2022 11:12
An example of using the deno's x/epubgen
import {
Chapter,
Options,
} from "epubgen/util/mod.ts";
const date = new Date();
date.setFullYear(2000);
export const optionsAlice: Options = {
import { Column, DataTable } from '@saas-ui/react';
interface ExampleData {
id: string
name: string
email: string
}
const columns: Column<ExampleData>[] = [
@waptik
waptik / bot.ts
Created September 3, 2021 07:39
Custom session adapter for grammyjs using supabase. Please give it a try and comment for feedback
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
waptik / paginate.ts
Created July 29, 2021 08:37
Mongoose paginate typescript
/** @see https://discord.com/channels/612400042900193311/612406252164612129/869681421567000608 **/
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([
model
.find(filter)
@waptik
waptik / theme.ts
Created July 12, 2021 17:10
Styling the inner div of tiptap v2 with chakra-ui
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
waptik / index.ts
Created July 12, 2021 16:48
A custom extension for tiptap v2 to for image upload
import { Node, nodeInputRule } from "@tiptap/core";
import { mergeAttributes } from "@tiptap/react";
import { uploadImagePlugin, UploadFn } from "./upload_image";
/**
* Tiptap Extension to upload images
* @see https://gist.github.com/slava-vishnyakov/16076dff1a77ddaca93c4bccd4ec4521#gistcomment-3744392
* @since 7th July 2021
*
HOW TO UNBLOCK ANIMEPAHE (JUST IN CASE) AND OTHER BLOCKED SITES
## 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 8.8.8.8 and 8.8.4.4, ISP could still sniff and intercept the DNS request because it's un-encrypted.
@waptik
waptik / test_array_of_objects.js
Last active May 8, 2021 04:17
[SOLVED] - I need help to: 1: rename keys to lowercase values 2: remove empty objects with one non-null key
// current code
const arrs = [
{
comments: 'asd',
movement: 'Back Squat',
userID: 'wDHZv3OL55SIymHkhMUejNleNkx1',
weight: '330',
},
{