Skip to content

Instantly share code, notes, and snippets.

View ahsanzizan's full-sized avatar
⚠️
Sup

Ahsan Awadullah Azizan ahsanzizan

⚠️
Sup
View GitHub Profile
@ahsanzizan
ahsanzizan / main.rs
Created March 8, 2024 07:34
An MD5 brute-forcer using Rust
extern crate crypto;
use crypto::digest::Digest;
use crypto::md5::Md5;
fn brute_force(hash: &str, charset: &str, max_length: usize) {
for length in 1..=max_length {
let mut attempt = vec![0; length];
loop {
let guess: String = attempt
@ahsanzizan
ahsanzizan / cycler_detector.py
Created February 1, 2024 09:41
Graph Theory Cycle Detector using DFS
class Graph:
def __init__(self, vertices):
self.vertices = vertices
self.adj_list = {v: [] for v in vertices}
def add_edge(self, u, v):
self.adj_list[u].append(v)
self.adj_list[v].append(u) # for undirected graph
def has_cycle(graph):
@ahsanzizan
ahsanzizan / transform.interceptor.ts
Created January 12, 2024 16:35
Response Transform Interceptor for Nest.JS
import {
Injectable,
NestInterceptor,
ExecutionContext,
CallHandler,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
export interface ResponseTemplate<T> {
@ahsanzizan
ahsanzizan / generator.py
Created January 11, 2024 01:53
A handy random string generator
import random
import string
def generate_random_string(length):
# Define the characters to choose from
characters = string.ascii_letters + string.digits + string.punctuation
# Generate a random string of the specified length
random_string = ''.join(random.choice(characters) for _ in range(length))
@ahsanzizan
ahsanzizan / apiResponses.ts
Created January 9, 2024 11:43
Next.js responses template
import { NextResponse } from "next/server";
export function Success(response: Object) {
return NextResponse.json({ status: 200, ...response }, { status: 200 });
}
export function Created(response: Object) {
return NextResponse.json({ status: 201, ...response }, { status: 201 });
}
@ahsanzizan
ahsanzizan / useTimer.ts
Last active January 9, 2024 11:37
A nifty hook for keeping track of time
import { useState, useEffect } from 'react';
const useTimer = () => {
const [seconds, setSeconds] = useState(0);
useEffect(() => {
const intervalId = setInterval(() => {
setSeconds((prevSeconds) => prevSeconds + 1);
}, 1000);
@ahsanzizan
ahsanzizan / prisma.ts
Created January 9, 2024 11:34
Ensure prisma client only instantiated once
import { PrismaClient } from '@prisma/client';
declare global {
interface CustomNodeJsGlobal extends NodeJS.Global {
prisma: PrismaClient;
}
}
const prisma: PrismaClient = global.prisma ?? new PrismaClient();