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.css
Created August 6, 2021 09:53
React useState ("Toggle")
main{
display: flex;
min-height: 100vh;
justify-content: center;
flex-direction: column;
background-color: #282c34;
padding: 10px 500px;
@gtchakama
gtchakama / index.html
Created August 18, 2021 12:55
A Demo of how to shake an element on hover.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.container {
position: relative;
}
@gtchakama
gtchakama / main.css
Created August 22, 2021 07:37
Typical Device Breakpoints.
/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {...}
/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {...}
/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {...}
/* Large devices (laptops/desktops, 992px and up) */
@gtchakama
gtchakama / index.js
Created August 22, 2021 09:51
Rendering Lists in React JS. -( map )
import React from "react";
import ReactDOM from "react-dom";
const brands = ["Dell", "Huawei", "Samsung", "RedMi", "Apple"];
const BrandList = () => (
<div>
<ul>{brands.map(brand => <li key={brand}> {brand} </li>)}</ul>
</div>
);
@gtchakama
gtchakama / main.js
Created October 1, 2021 04:40
Permutations - Generates all permutations of an array's elements (contains duplicates).
const permutations = arr => {
if (arr.length <= 2) return arr.length === 2 ? [arr, [arr[1], arr[0]]] : arr;
return arr.reduce(
(acc, item, i) =>
acc.concat(
permutations([...arr.slice(0, i), ...arr.slice(i + 1)]).map(val => [
item,
...val,
])
),
@gtchakama
gtchakama / main.js
Created October 1, 2021 05:11
Query selector shorthand
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
const mainContent = $('.main-content');
const externalLinks = $$('a[target="_blank"]');
@gtchakama
gtchakama / main.js
Created February 15, 2022 05:17
Converting Object to an Array
const zoo = {
lion: '🦁',
panda: '🐼',
};
Object.keys(zoo);
// ['lion', 'panda']
Object.values(zoo);
// ['🦁', '🐼']
{
"adverts": [
{
"company": "Econet",
"heading": "Kevin Kruse",
"promo": "39%",
"link": "https://gist.github.com",
"social": "https://gist.github.com",
"image": "https://i.ibb.co/rFKZHFn/frank-mckenna-Eg-B1u-SU5t-RA-unsplash.jpg"
},
@gtchakama
gtchakama / main.js
Created October 19, 2022 07:41
Initialize a Date with Time Zone using JavaScript
const date = new Date();
// ✅ Get a string according to a provided Time zone
console.log(
date.toLocaleString('en-US', {
timeZone: 'America/Los_Angeles',
}),
); // 👉️ "1/15/2022, 11:54:44 PM"
console.log(
@gtchakama
gtchakama / main.js
Created January 18, 2023 22:03
filter array of objects by another array of objects
const array = [
{ id: 1, name: 'a1', sub: { id: 6, name: 'a1 sub' } },
{ id: 2, name: 'a2', sub: null },
{ id: 3, name: 'a3', sub: { id: 8, name: 'a3 sub' } },
{ id: 4, name: 'a4', sub: null },
{ id: 5, name: 'a5', sub: { id: 10, name: 'a5 sub' } },
];
const anotherArray = [
{ id: 1, name: 'a1', sub: { id: 6, name: 'a1 sub' } },