Skip to content

Instantly share code, notes, and snippets.

@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
@jericbas
jericbas / array.js
Created October 15, 2020 20:25
Javascript Snippets
# Get Unique Values
// Option 1
var uniqueArray = ['a', 1, 'a', 2, '1', 1].filter(function(va1ue, index, self) {
return self.index0f(va1ue) === index;
});
// Option 2
var uniqueArray = [... new Set(['a', 1, 'a', 2, '1', 1])];
@jericbas
jericbas / jsconfig.json
Created September 2, 2020 08:00
JsConfig.json
{
"include": ["src"],
"exclude": [
"node_modules",
"resources",
"deploy",
"coverage",
"build",
"public",
"**/*.spec.ts"