Skip to content

Instantly share code, notes, and snippets.

@jericbas
jericbas / Loop.js
Last active December 7, 2023 04:29
Loop
Certainly! Let's create more realistic test cases for each of the first seven functional methods, using scenarios related to vehicle, house, or land insurance. Each example will use an array with real-life-like data.
1. **forEach (Logging Vehicle Insurance IDs)**:
```javascript
const vehicleInsurances = [
@jericbas
jericbas / Json Preview.tsx
Last active November 9, 2023 09:12
json preview component
import React, { useState } from 'react';
interface JsonDisplayProps {
data: any; // You can use a more specific type based on what JSON you expect
}
const JsonDisplay: React.FC<JsonDisplayProps> = ({ data }) => {
const [isCollapsed, setIsCollapsed] = useState(true);
const jsonString = JSON.stringify(data, null, 2);
const truncateLimit = 100; // You can adjust the truncate limit as needed
@jericbas
jericbas / Last-of-array.ts
Last active November 3, 2023 09:16
Types
const dataArray = ['A', 'B', 'C', 'D', 'E'] as const;
type data = [...(typeof dataArray)];
type Last<T extends any[]> = T extends [...infer _, infer R] ? R : never;
const last: Last<data> = 'E'
@jericbas
jericbas / objectToJSX.tsx
Last active August 18, 2023 04:13
ObjectToJSX
import React, { ReactNode } from 'react';
interface ObjectProps {
[key: string]: any;
children?: ReactNode;
}
function objectToJSX(component: string, object: ObjectProps): JSX.Element {
if (typeof component !== 'string' || typeof object !== 'object') {
throw new Error('Invalid arguments provided.');
@jericbas
jericbas / Button.stories.tsx
Created August 11, 2023 16:43
Refining "args" type definition - Storybook 7
import { Button } from "./Button";
import { Meta, StoryObj as _StoryObj } from "@storybook/react";
import React from "react";
const meta: Meta<typeof Button> = {
title: "Button",
args: {
children: "Button",
}
};
@jericbas
jericbas / build.sh
Created March 11, 2023 13:44
Build Gatsby and push the contents of the public directory to another branch
#!/bin/bash
# Build the Gatsby site
npm run build
# Create a new branch for the build files
git branch build-files
# Checkout the new branch
git checkout build-files
@jericbas
jericbas / scan.js
Created January 20, 2023 11:52
Check if text is exist in the url
const got = require('got');
const { parse } = require('parse5');
const fs = require('fs');
const searchText = process.argv[2];
const listFile = process.argv[3] || 'list.txt';
fs.readFile(listFile, 'utf8', (err, data) => {
if (err) throw err;
const websiteList = data.split('\n');
@jericbas
jericbas / readme.md
Created January 17, 2023 10:48
Here is an example of how to run a Python script inside a virtual environment using cron:
  1. First, activate your virtual environment using the command:
source /path/to/virtualenv/bin/activate
  1. Now, you can run your python script inside the virtual environment
python /path/to/script.py
  1. To run this script at a specific time or interval, you can add a cron job.
@jericbas
jericbas / filebrowser.service
Last active April 2, 2021 14:25
Service Linux
[Unit]
Description=Filebrowser Service
After=network.target
[Service]
WorkingDirectory=/data
PIDFile=/var/run/filebrowser.pid
ExecStart=/usr/local/bin/filebrowser --cache-dir cache
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID