Skip to content

Instantly share code, notes, and snippets.

View abel-masila's full-sized avatar
⚛️
Shipping code!

Abel Masila abel-masila

⚛️
Shipping code!
View GitHub Profile
<html>
<head>
<title></title>
</head>
<body style="margin: 0;">
<style>
@media only screen and (max-width: 600px) {
.main-table {
width: 100% !important;
}
useEffect(() => {
console.log({ url: process.env.REACT_APP_SOCKET_ENDPOINT });
function onConnect() {
console.log("Socket connected successfully");
setIsConnected(true);
console.log(personId); // Check if personId is logged correctly
socket.emit("join", { person_id: personId });
}
// Custom hook for mutations
const useCustomMutation = <T = unknown>(
mutationFn: (...args: any[]) => Promise<T>,
options?: UseMutationOptions<T, unknown, unknown>
) => {
return useMutation(mutationFn, {
onSuccess: (data) => {
// Handle success case
console.log('Mutation successful:', data);
},
function countRectangles(board) {
let count = 0;
let N = board.length;
let M = board[0].length;
for (let r = 0; r < N; r++) {
for (let c = 0; c < M; c++) {
for (let i = r; i < N; i++) {
for (let j = c; j < M; j++) {
let aCount = 0;
@abel-masila
abel-masila / nights.js
Last active March 24, 2023 21:24
hard stuff
function combineCustomNights(customNights) {
const result = [];
let currentRange = null;
customNights.sort((a, b) => new Date(a.date) - new Date(b.date));
customNights.forEach((night) => {
if (!currentRange) {
currentRange = { start: night.date, end: night.date, rooms: { ...night } };
delete currentRange.rooms.date;
function belongsToTriangle(x1, y1, x2, y2, x3, y3, xp, yp, xq, yq) {
// Calculate the length of the sides of the triangle
const lab = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
const lac = Math.sqrt((x3 - x1) ** 2 + (y3 - y1) ** 2);
const lbc = Math.sqrt((x3 - x2) ** 2 + (y3 - y2) ** 2);
// Check if the triangle is non-degenerate
if (lab + lac <= lbc || lab + lbc <= lac || lac + lbc <= lab) {
return "o";
}
function palindromeChecker(s, startindex, endindex, subs) {
let result = '';
for (let i = 0; i < startindex.length; i++) {
let sub = s.substring(startindex[i], endindex[i] + 1);
let count = new Array(26).fill(0);
for (let j = 0; j < sub.length; j++) {
count[sub.charCodeAt(j) - 97]++;
}
let oddCount = 0;
for (let j = 0; j < 26; j++) {
function makePalindrome(s, startindex, endindex, subs) {
let result = "";
for (let i = 0; i < startindex.length; i++) {
let substring = s.substring(startindex[i], endindex[i] + 1);
let count = 0;
let charMap = new Map();
for (let j = 0; j < substring.length; j++) {
charMap.set(substring.charAt(j), charMap.get(substring.charAt(j)) + 1 || 1);
}
for (let [char, freq] of charMap) {
// Value types can be three, value1, value2, value3
const items=[
{
"date": "2023-02-01",
"value1": 1,
"value2": 1
},
{
"date": "2023-02-03",
/* eslint-disable no-unused-expressions */
import React, { useState, useEffect } from "react";
import {
AppBar,
Button,
Card,
Dialog,
DialogActions,
DialogContent,