Skip to content

Instantly share code, notes, and snippets.

View bonface221's full-sized avatar
:octocat:
coding

Bonface Maina | TechWithTwin bonface221

:octocat:
coding
View GitHub Profile
@bonface221
bonface221 / calc.c
Created April 8, 2025 10:43
C program to calculate the area of a land. Write a C program that accepts the length and width of a rectangular piece of land in foot, converts them into meters and then calculates the area. The program shuould then output the length,width and area in metres. Use a function. Hint 1 foot = 0.3metres and area = length * width
#include <stdio.h>
#include <string.h>
/*
Write a C program that accepts the length and width of a rectangular
piece of land in foot, converts them into meters and then calculates
the area. The program shuould then output the length,width and area in
metres. Use a function. Hint 1 foot = 0.3metres and area = length * width
*/
@bonface221
bonface221 / calc.c
Created April 2, 2025 19:47
Simple Addition, Division and multiplication Calculator in C
#include <stdio.h>
double operate(char opr, double num1, double num2)
{
if (opr == 'a')
return num1 + num2;
if (opr == 's')
return num1 - num2;
@bonface221
bonface221 / greatest.c
Created April 2, 2025 11:15
Checking the greatest number in C
#include <stdio.h>
int max(int num1, int num2, int num3)
{
if (num1 > num2 && num1 > num3)
{
return num1;
};
if (num2 > num1 && num2 > num3)
@bonface221
bonface221 / prisma.md
Last active August 9, 2024 11:30
Prisma relationship type generator

Since Prisma queries do not include relations by default (you have to use the include option), the generated types do not include them either. You can create the type you are looking for using one of our built-in utility types, though.

import { Prisma } from '@prisma/client'
type FactionWithOwner = Prisma.FactionGetPayload<{
  include: { owner: true }
}>

Here we use the FactionGetPayload type and pass in some query options as the generic parameter to get the desired type.

MySQL Cheat Sheet

Help with SQL commands to interact with a MySQL database

MySQL Locations

  • Mac /usr/local/mysql/bin
  • Windows /Program Files/MySQL/MySQL version/bin
  • Xampp /xampp/mysql/bin

Add mysql to your PATH

@bonface221
bonface221 / index.py
Created July 31, 2024 10:45
PYTHON images rename script
# rename all the images inside images folder into
# to sisters-on-the-outside-regional-leaders-training-day-2 + timestamp .jpj
import os
import time
import requests
# get the current working directory
path = os.getcwd()
@bonface221
bonface221 / save-file.ts
Last active July 22, 2024 10:02
saving files in nextjs on the public folder
"use server";
import path from "path";
import fs from "fs";
import { uuid } from "uuidv4";
const UPLOAD_DIR = path.resolve(process.env.ROOT_PATH ?? "", "public/uploads");
export const SaveFileAction = async (data: FormData) => {
@bonface221
bonface221 / doc.md
Created July 20, 2024 18:46
ERROR: SQLITE_CANTOPEN: unable to open database file

Just chmod 777 for database and uploads then I can start it successfully.

@bonface221
bonface221 / doc.md
Last active July 18, 2024 11:19
NextJS - Appending a query param to a dynamic route

Just add more param to current router then push itself

` // ... const { query } = useRouter(); // ...

@bonface221
bonface221 / doc.md
Created July 17, 2024 06:32
Restarting your server

shutdown now -r