Skip to content

Instantly share code, notes, and snippets.

View techwithtwin's full-sized avatar

Bonface Maina | TechWithTwin techwithtwin

View GitHub Profile
@techwithtwin
techwithtwin / index.tsx
Created August 29, 2025 06:34
React native fullscreen modal
import React, {useState} from 'react';
import {Alert, Modal, StyleSheet, Text, Pressable, View} from 'react-native';
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
import {Dimensions} from 'react-native';
const windowWidth = Dimensions.get('window').width;
const windowHeight = Dimensions.get('window').height;
const App = () => {
const [modalVisible, setModalVisible] = useState(false);
@techwithtwin
techwithtwin / README.md
Created August 22, 2025 08:12
HackerNews Top Stories

Welcome! This task will help us gauge your React skills, your approach to problem-solving, and how comfortable you are working with APIs and modern frontend tooling.

📌 Task Overview

You’ll be building a small React app using Vite that fetches data from the HackerNews API.

The goal is to:

  1. Fetch a list of top story IDs from the HackerNews API.
@techwithtwin
techwithtwin / two-sum.js
Created August 7, 2025 19:05
Two number sum problem both with the slow and most efficient way!
/*
test 1;
nums = [2,7,11,15];
target = 9;
ans = [0,3];
test 2;
nums = [3,3];
target = 6;
ans = [0,1]
@techwithtwin
techwithtwin / whatsapp-btn.tsx
Created July 4, 2025 09:36
Whatsapp floating button
"use client";
import { Box } from "@chakra-ui/react";
import Image from "next/image";
const WhatsAppBtn = () => {
const handleContactWhatsapp = () => {
window.open("https://api.whatsapp.com/send/?phone=+254722781646");
};
return (
@techwithtwin
techwithtwin / hero.tsx
Created June 9, 2025 08:08
Hero section Chakra UI
import { marginX, sampleImage } from "@/utils/constants";
import {
Avatar,
AvatarGroup,
Box,
Button,
Flex,
Heading,
SimpleGrid,
Stack,
@techwithtwin
techwithtwin / example1.js
Created May 28, 2025 21:01
Array.reduce function explained by techwithtwin in a youtube video
/*
Add the total
const fruits = [
{ description: 'Mangoes', total: 3 },
{ description: 'PawPaw', total: 2.5 },
{ description: 'Oranges', total: 12 }
];
*/
@techwithtwin
techwithtwin / test.js
Created May 27, 2025 19:59
JavaScript map() function tutorial gist
//simple script to add a suffix of item length to an array item
const fruits = ["apples", "pawpaw", "oranges", "bananas"];
const fruitsWithSuffix = fruits.map((fruit, i) => fruit + i);
console.log(fruitsWithSuffix);
//using for loop
// const fruitsWithSuffix = [];
"use client";
import { AiFillInstagram } from "react-icons/ai";
import { FaLinkedin } from "react-icons/fa";
import { FaXTwitter } from "react-icons/fa6";
import { Box, Icon, Image, Stack, Text } from "@chakra-ui/react";
import { motion, useAnimation } from "framer-motion";
import Link from "next/link";
interface Props {
member: {
@techwithtwin
techwithtwin / upload.py
Created April 30, 2025 11:59
UPLOAD TO DIRECTUS
import os
import requests
import mimetypes
# Configuration
BASE_URL = "<your base url>"
FILES_ENDPOINT= f"{BASE_URL}/files"
UPLOAD_COLLECTION = f"{BASE_URL}/items/<collection to upload to>"
IMAGES_FOLDER= "./leg1"
DEFAULT_TYPE = 'leg1'
@techwithtwin
techwithtwin / providers.ts
Last active April 29, 2025 21:33
Chakra ui v3 sample theme
"use client";
import {
ColorModeProvider,
ColorModeProviderProps,
} from "@/components/ui/color-mode";
import { system } from "@/theme";
import { ChakraProvider } from "@chakra-ui/react";