Skip to content

Instantly share code, notes, and snippets.

View alexaivars's full-sized avatar

Alexander Aivars alexaivars

  • Aivars AB
  • Sweden
View GitHub Profile
@alexaivars
alexaivars / gitmes.go
Created January 18, 2024 16:47
Analyzes the output of 'git diff --cached' to generate a meaningful commit message.
package main
import (
"bytes"
"context"
"fmt"
"log"
"os"
"os/exec"
@alexaivars
alexaivars / message.ts
Created January 16, 2024 18:12
This script analyzes the output of 'git diff --cached' to generate a meaningful commit message.
/**
* Usage:
* After staging files with git, run this script to generate a commit message.
* Command: ts-node tools/message.ts
* This script analyzes the output of 'git diff --cached' to generate a meaningful commit message.
* It utilizes the OpenAI client to process the diff and suggests a concise summary.
*/
import { config as dotenvConfig } from "dotenv";
import {
echo $(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1)
@alexaivars
alexaivars / useFirestorStream.ts
Last active January 13, 2022 10:09
React hook for a curser based fires store document list that watches entire document collection
import {
useCallback,
useEffect,
useMemo,
useReducer,
useRef,
useState,
} from "react";
import {
QueryDocumentSnapshot,
@alexaivars
alexaivars / generate-ssl-cert.sh
Created March 29, 2021 07:16
Self signed root CA for development
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# remove any existing directories and certificates
rm -rf $DIR/certs
# make directories to work from
mkdir -p $DIR/certs
module.exports = function (file, api, options) {
if (file.source.indexOf("export default") < 0) {
// no need to process the file if no `export default`
return;
}
const j = api.jscodeshift;
const root = j(file.source);
const filePath = file.path; // replace `filePath` if you want to test different names
type ComponentProps = { text: string } & React.HTMLAttributes<HTMLDivElement>;
type ComponentRef = HTMLDivElement;
const Component:React.FunctionComponent<ComponentProps> = React.forwardRef<ComponentRef, ComponentProps>(
({ text = 'default', className }, ref) => (
<div className={className} ref={ref}>
{text}
</div>
),
);
type ComponentProps = { text: string } & Pick<React.HTMLAttributes<HTMLDivElement>, 'className' | 'onClick'>;
const Component: React.FunctionComponent<ComponentProps> = ({
text = 'default',
...props
}) => (
<div className={className} {...props}>
{text}
</div>
);
import React from 'react';
import styled, { StyledComponentBase } from 'styled-components';
type ComponentProps = { text: string } & React.HTMLAttributes<HTMLDivElement>;
const Component: React.FunctionComponent<ComponentProps> = ({
text = 'default',
className,
...props
}) => (
<div className={className} {...props}>
import React from 'react';
import { render } from 'testUtils';
import { useQueryParam, useHistory } from './location';
describe('location hooks', () => {
describe('useHistory', () => {
it('changes path without loosing query parameteras', () => {
const HookWrapper = () => {
const { push } = useHistory({ keepQuery: true });
React.useEffect(() => {