Skip to content

Instantly share code, notes, and snippets.

View gtchakama's full-sized avatar
🇿🇼
Full-Stack Developer

George T Chakama gtchakama

🇿🇼
Full-Stack Developer
View GitHub Profile
@gtchakama
gtchakama / main.js
Last active June 13, 2024 18:57
Gemini Template for image processing
import { useState } from "react";
import { GoogleGenerativeAI } from "@google/generative-ai";
function Gemini() {
const [loading, setLoading] = useState(false);
const [apiData, setApiData] = useState("");
const [selectedFile, setSelectedFile] = useState(null);
const genAI = new GoogleGenerativeAI(process.env.NEXT_PUBLIC__API_GEN_API);
@gtchakama
gtchakama / app.js
Created September 3, 2023 08:05
ReactJS File Upload
import React, { useState } from 'react';
import axios from 'axios';
// Define a functional component called FileUpload
const FileUpload = () => {
// Declare two state variables using the useState hook:
// - selectedFile: to store the currently selected file
// - uploadStatus: to display the upload status message
const [selectedFile, setSelectedFile] = useState(null);
@gtchakama
gtchakama / index.js
Created August 23, 2023 10:26
NodeJS CRUD With Postgres
const express = require('express');
const { Pool } = require('pg');
const app = express();
const port = process.env.PORT || 3000;
const pool = new Pool({
user: 'your_db_user',
host: 'localhost',
database: 'your_db_name',
@gtchakama
gtchakama / app.rb
Created August 8, 2023 09:37
A search filter to an array of objects in Ruby
# Sample array of user objects
users = [
{ id: 1, first_name: "John", last_name: "Doe", age: 30, email: "john@example.com" },
{ id: 2, first_name: "Jane", last_name: "Smith", age: 25, email: "jane@example.com" },
{ id: 3, first_name: "Michael", last_name: "Johnson", age: 35, email: "michael@example.com" },
{ id: 4, first_name: "Emily", last_name: "Brown", age: 28, email: "emily@example.com" }
]
# Function to apply the search filter
def search_users(query, users)
@gtchakama
gtchakama / app.js
Created June 7, 2023 14:02
A function that when given a URL as a string, parses out just the domain name and returns it as a string.
function domainName(url) {
// Remove protocol and www. prefix from domain
let domain = url.replace(/(https?:\/\/)?(www\.)?/, '');
// Remove everything after the first dot (including the dot)
domain = domain.split('.')[0];
return domain;
}
@gtchakama
gtchakama / index.js
Created April 13, 2023 18:06
Sort an array of objects by a specified property.
/**
* Sorts an array of objects by a specified property
*
* @param {Array} array - The array to sort
* @param {string} property - The property to sort by
* @returns {Array} - The sorted array
*/
const sortByProperty = (array, property) => {
return array.sort((a, b) => {
if (a[property] < b[property]) {
@gtchakama
gtchakama / index.html
Created April 11, 2023 13:36
Cool CSS Explosion
<!DOCTYPE html>
<html>
<head>
<title>Shaking Particles</title>
<style>
.shape {
position: absolute;
width: 50px;
height: 50px;
transform: scale(0.8);
@gtchakama
gtchakama / timer.tsx
Created April 6, 2023 13:02
A ReactJS Timer with progress bar
import { useEffect, useState } from "react";
const ThirtySecCounter = () => {
const [timeLeft, setTimeLeft] = useState(30);
useEffect(() => {
if (!timeLeft) return;
const intervalId = setInterval(() => {
setTimeLeft((prevTimeLeft) => prevTimeLeft - 1);
@gtchakama
gtchakama / api.tsx
Created April 5, 2023 04:21
Reactjs utility function that handles api calls in axios for login , signup , reset password and register
// api.ts
import axios, { AxiosResponse } from 'axios';
import apiConfig from './apiConfig';
// Define interfaces for request data types
interface LoginData {
email: string;
password: string;
}
@gtchakama
gtchakama / main.js
Created March 24, 2023 18:38
NavBar - Tailwind CSS
import { useState } from 'react'
import { Dialog } from '@headlessui/react'
import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline'
const navigation = [
{ name: 'Product', href: '#' },
{ name: 'Features', href: '#' },
{ name: 'Marketplace', href: '#' },
{ name: 'Company', href: '#' },
]