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 { Collection } from "../../deps.ts";
import { BaseRestApiUrl } from "../constants/mod.ts";
import { HttpError } from "../handler/errors/http.ts";
export class RestClient extends Collection<string, Record<any, any>> {
constructor() {
super();
}
async request(
href: string,
// async createSticker({
// description, filePath, name, tags, fileName
// }: {
// /**
// * The Name of the Sticker
// */
// name: string,
// /**
// * The Description of the Sticker
// */
with open("school.txt") as f:
data = f.read()
lines = data.split("\n")
total_words = len(data.replace("\n",""))
total_lines = len(lines)
vowels = 0
consonants = 0
/// 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();
@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"}
/>
@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 / 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 {
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,
<Button
loading={loading}
onClick={() => {
if (inputMode === "audio" && chunks.current.length === 0) {
if (
navigator.mediaDevices &&
navigator.mediaDevices.getUserMedia
) {
navigator?.mediaDevices
// 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,