Skip to content

Instantly share code, notes, and snippets.

View PhantomKnight287's full-sized avatar
:shipit:
In Love With Terminal

Gurpal Singh PhantomKnight287

:shipit:
In Love With Terminal
View GitHub Profile
import { betterAuth, logger } from "better-auth";
import {
admin,
anonymous,
apiKey,
bearer,
captcha,
createAuthMiddleware,
emailOTP,
haveIBeenPwned,
# Use a specific version of Node
FROM node:18-alpine AS base
ARG DATABASE_URL
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
ENV DATABASE_URL=${DATABASE_URL}
# Set up environment for pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
@Cron(CronExpression.EVERY_MINUTE)
async streakCronJob() {
const users = await prisma.user.findMany();
for (const user of users) {
if (!user.timezone || !IANATimezones[user.timezone]) continue;
const userLocalTime = moment().tz(IANATimezones[user.timezone]);
// Fetch the last streak record
const lastStreakRecord = await prisma.streak.findFirst({
where: { userId: user.id },
// A Nestjs filter which "filters" out all exceptions to add custom logging logic
import { Request, Response } from 'express';
import { IncomingMessage } from 'http';
import {
ArgumentsHost,
BadRequestException,
Catch,
ExceptionFilter,
HttpException,
<Button
loading={loading}
onClick={() => {
if (inputMode === "audio" && chunks.current.length === 0) {
if (
navigator.mediaDevices &&
navigator.mediaDevices.getUserMedia
) {
navigator?.mediaDevices
import {randomBytes} from "crypto"
async createChat(userId: string, body: CreateChatDTO) {
const key = randomBytes(32).toString('base64');
const iv = randomBytes(16).toString('base64');
const chat = await prisma.chat.create({
data: {
id: `ch_${createId()}`,
name: body.name,
topic: body.topic,
@PhantomKnight287
PhantomKnight287 / error.dart
Created September 26, 2024 04:37
Helper to get error message from a class validator error
String getErrorMessage(dynamic error, [String? message]) {
if (error is String) {
return error;
} else if (error is Map) {
if (error['message'] is List) {
return error['message'][0];
} else {
return error['message'];
}
} else {
@PhantomKnight287
PhantomKnight287 / linkedin.ts
Created November 29, 2023 08:08
Linkedin Oauth in a nestjs application.
import jose from 'node-jose';
const urlToGetLinkedInAccessToken =
'https://www.linkedin.com/oauth/v2/accessToken';
export type LinkedInUser = {
iss: string;
aud: string;
iat: number;
exp: number;
@PhantomKnight287
PhantomKnight287 / bar.tsx
Last active July 17, 2023 06:19
Custom Bottom Bar
const bottomBarActions = useMemo(() => {
const actions = [
{
name: "Home",
icon: (
<Entypo
name="home"
size={24}
color={theme === "Dark" ? "#fff" : "#000"}
/>
/// Get Balance of your account or another user
#[poise::command(slash_command, prefix_command)]
pub async fn balance(
ctx: Context<'_>,
#[description = "Selected user"] user: Option<User>,
) -> Result<(), Error> {
let u = user.as_ref().unwrap_or_else(|| ctx.author());
ctx.defer().await.expect("Cannot defer");
let client = ctx.data();
let id = u.id.0.clone().to_string();