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 / 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: "[email protected]" },
{ id: 2, first_name: "Jane", last_name: "Smith", age: 25, email: "[email protected]" },
{ id: 3, first_name: "Michael", last_name: "Johnson", age: 35, email: "[email protected]" },
{ id: 4, first_name: "Emily", last_name: "Brown", age: 28, email: "[email protected]" }
]
# 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: '#' },
]
@gtchakama
gtchakama / main.js
Created March 21, 2023 04:48
Simple component Selector using select options
import React, { useState } from "react";
import ComponantA from "./ComponantA";
import ComponantB from "./ComponantB";
import ComponantC from "./ComponantC";
function ChangeComponantSelect(){
const [selected,setSelected]=useState('First Componant')
const handleChange=(e)=>{
console.log(e.target.value)
@gtchakama
gtchakama / main.js
Created March 13, 2023 19:20
Recursive JavaScript Lambda
const AWS = require('aws-sdk')
const lambda = new AWS.Lambda()
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
const recursionLimit = 5
exports.handler = async(event) => {
await sleep(2000)
@gtchakama
gtchakama / main.js
Created March 13, 2023 19:20
Recursive JavaScript Lambda
const AWS = require('aws-sdk')
const lambda = new AWS.Lambda()
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
const recursionLimit = 5
exports.handler = async(event) => {
await sleep(2000)