3163. String Compression III

Given a string word, compress it using the following algorithm: Begin with an empty string comp. While word is not empty, use the following operation: Remove a maximum length prefix of word made of a single character c repeating at most 9 times. Append the length of the prefix followed by c to comp. Return the string comp.
/**
 * @param {string} word
 * @return {string}
 */
var compressedString = function(word) {
    // Initialize an empty string to store the compressed result
    let comp = '';

    // While there are characters left in the word
    while (word.length > 0) {
        // Get the current character to process
        let currentChar = word[0];
        // Initialize the count for the current character
        let count = 0;

        // Count the number of consecutive occurrences of the current charact

GIT Repair commit

```
git add .
````

```
git commit --amend --no-edit
```
Si hace falta actualizar en Github
```
git push --force
```

testing_where_not_exist

SELECT CASE
    WHEN EXISTS (
        SELECT 1
        FROM fact_combination_selections_temp src
        JOIN $ENRICHED_SCHEMA.fact_combination_selections tgt
        ON src.combination_selection_rn = tgt.combination_selection_rn
        AND src.exchange_rate = tgt.exchange_rate
        AND src.bet_resettled_flag = tgt.bet_resettled_flag
    ) THEN 'true'
    ELSE 'false'
END AS match_exists;

Transformation float64 to float32 for numerical columns of pandas dataframe

df = df.astype({col: 'float32' for col in df.select_dtypes(include='float64').columns})

test_exists_clause

SELECT CASE
    WHEN EXISTS (
        SELECT 1
        FROM fact_combination_selections_temp src
        JOIN $ENRICHED_SCHEMA.fact_combination_selections tgt
        ON src.combination_selection_rn = tgt.combination_selection_rn
        AND src.exchange_rate = tgt.exchange_rate
        AND src.bet_resettled_flag = tgt.bet_resettled_flag
    ) THEN 'true'
    ELSE 'false'
END AS match_exists;

Uptime script

Listing uptime, can use in GeekTools
boottime=`sysctl -n kern.boottime | awk '{print $4}' | sed 's/,//g'`
unixtime=`date +%s`
timeAgo=$(($unixtime - $boottime))
uptime=`awk -v time=$timeAgo 'BEGIN { seconds = time % 60; minutes = int(time / 60 % 60); hours = int(time / 60 / 60 % 24); days = int(time / 60 / 60 / 24); printf("%.0f days, %.0f:%.0f:%.0f", days, hours, minutes, seconds); exit }'`
echo "Uptime: " $uptime

Calendar in shellscript

for use in Geektools
cal | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./#/g') /"

Dropdown Component

import React from 'react';
const Dropdown = ({ options, onSelect }) => {
  return (
 onSelect(e.target.value)}>      {options.map((option) => (                  {option.label}              ))}    
  );
};
export default Dropdown;

Loading Spinner Component

Description: A reusable loading spinner to simulate a loading effect. Use case: Show loading spinner when data from an API is yet to arrive.
import React from 'react';
const Spinner = ({ size, color }) => {
  const spinnerStyle = {
    width: size,
    height: size,
    borderTopColor: color,
    borderLeftColor: 'transparent',
    animation: 'spin 1s linear infinite',
    borderWidth: '2px',
    borderStyle: 'solid',
    borderRadius: '50%',
  };
  return (
  );
};
Spinner.defaultProps = {
  size: '6',
  color: 'rgba(59, 130, 246, 1)',
};
export default Spinner;

Button Component

Description: Reusable button component in React code. Use case: A UI button component that accepts different props.
import React from 'react';
import PropTypes from 'prop-types';
const Button = ({ type, className, children, ...props }) => {
  return (
    
      type={type}
      className={className}
      {...props}
    >
      {children}
  );
};
Button.propTypes = {
  type: PropTypes.oneOf(['button', 'submit', 'reset']),
  className: PropTypes.string,
  children: PropTypes.node.isRequired,
};
Button.defaultProps = {
  type: 'button',
  className: '',
};
export default Button;

Image Slider Component

Description: An image slider for displaying multiple images. Use case: Image carousel
import React, { useState } from 'react';
const ImageSlider = ({ images }) => {
 const [currentIndex, setCurrentIndex] = useState(0);
  const nextSlide = () => setCurrentIndex((prevIndex) => (prevIndex === images.length - 1 ? 0 : prevIndex + 1));
  const prevSlide = () => setCurrentIndex((prevIndex) => (prevIndex === 0 
images.length - 1 : prevIndex - 1));
  return (
      Prev            Next    
  );
};
export default ImageSlider;

Tabs Component

Description: A tab component for switching between different content. Use Case: Implementing tabbed navigation for different sections of a page
import React, { useState } from 'react';
const Tabs = ({ tabs }) => {
  const [activeTab, setActiveTab] = useState(0);
  return (
      {tabs.map((tab, index) => (                  key={index}          className={`tab ${index === activeTab ? 'active' : ''}`}          onClick={() => setActiveTab(index)}        >          {tab.title}        
      ))}
{tabs[activeTab].content}
);
};
export default Tabs;

Modal Component

Description: A component for displaying overlay modals. Use case: Displaying a notification modal.
import React from 'react';
const Modal = ({ isOpen, onClose, children }) => {
  return isOpen ? (
              {children}        Close          
  ) : null;
};
export default Modal;

Custom Hooks

Description: Creates a hook for reusing stateful logic. Use case: Fetching data from an API with reusable logic.
import { useState, useEffect } from 'react';
const useFetch = (url) => {
  const [data, setData] = useState(null);
  const [loading, setLoading] = useState(true);
  useEffect(() => {
    const fetchData = async () => {
      const response = await fetch(url);
      const data = await response.json();
      setData(data);
      setLoading(false);
    };
    fetchData();
  }, [url]);
  return { data, loading };
};
export default useFetch;

Forms

Description: React code that handles forms and input submission. Use case: Creating a form for user input.
import React, { useState } from 'react';
const Form = () => {
const [value, setValue] = useState('');
  const handleChange = (e) => setValue(e.target.value);
  const handleSubmit = (e) => {
    e.preventDefault();
    // Handle form submission
  };
  return (
Submit    
  );
};
export default Form;