Skip to content

Instantly share code, notes, and snippets.

@ericzakariasson
ericzakariasson / customQueryString.js
Last active August 23, 2018 07:06
Custom query string formatter for use in input fields
/* Declare shortcuts and types */
const fieldMap = {
a: {
name: 'address',
type: String
},
s: {
name: 'approved',
type: Boolean,
relation: {
function useLocalStorage() {
const get = key => localStorage.getItem(key);
const set = (key, value) = localStorage.setItem(key, value);
return [get, set];
}
const Example = () => {
const [getLocalStorage, setLocalStorage] = useLocalStorage();
import React, { useCallback, useEffect, useRef, useState } from 'react'
// Types to be shared with frontend and backend
interface ApiResponseInfo {
code: number
message: string
[key: string]: unknown
}
interface ApiResponseCommon {
import { act, renderHook } from "@testing-library/react-hooks";
import { useArray } from "./useArray";
describe("useArray", () => {
describe("props", () => {
it("should have initial state", () => {
const { result } = renderHook(() =>
useArray({
initialState: ["a", "b", "c"],
class InternalError extends Error {}
type Predicate<T> = (item: T) => boolean;
function single<T>(array: T[], predicate?: Predicate<T>) {
const items = predicate ? array.filter(predicate) : array;
if (items.length !== 1) {
throw new InternalError("Array does not contain exactly one item");
}
@ericzakariasson
ericzakariasson / sql.helper.ts
Last active December 1, 2021 15:26
SQL helper
export enum TextInputTypes {
Raw,
Parameter,
}
export type Primitive = string | number | boolean;
export interface TextInputObject<Type extends TextInputTypes> {
type: Type;
value: Primitive;
describe("withRetry", () => {
it("should retry if when condition is true", async () => {
const fn = jest
.fn()
.mockImplementationOnce(() => {
throw new Error("Should throw");
})
.mockImplementationOnce(() => 1);
let retryCount = 0;
@ericzakariasson
ericzakariasson / what-did-you-get-done-this-week.sh
Created October 14, 2024 07:40
Small script to answer the question "What did you get done this week?"
#!/bin/bash
START_DATE=$(date -v -$(($(date '+%u') + 6))d '+%Y-%m-%d')
END_DATE=$(date -v -$(date '+%u')d '+%Y-%m-%d')
GIT_LOG=$(git log --since="$START_DATE" --until="$END_DATE" --pretty=format:"%h %s" --no-merges)
[ -z "$GIT_LOG" ] && { echo "No commits found."; exit 1; }
PROMPT="In less than 200 characters, summarize the following git commit history to answer the question 'What did you get done this week?'. Answer in the style of Elon Musk. The reader is in a hurry, so make sure it's easy to digest quickly. Start with 'This week'. ':\n$GIT_LOG"
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["mcpServers"],
"properties": {
"mcpServers": {
"type": "object",
"minProperties": 1,
"additionalProperties": {
"type": "object",
goal: address PR comments
- get PR comments
```bash
# Find PR for current branch
gh pr list --head $(git branch --show-current) | cat
# Get inline comments (most important)
gh api repos/:owner/:repo/pulls/PR_NUMBER/comments --jq '.[] | {author: .user.login, body: .body, path: .path, line: .line}' | cat