Skip to content

Instantly share code, notes, and snippets.

View tomfa's full-sized avatar

Tomas Fagerbekk tomfa

View GitHub Profile
@tomfa
tomfa / deploy.yml
Created October 20, 2021 12:30
Github Action: depend on test to succeed for deployment
# place this file in .github/workflows/ folder in repo
#
# This will run tests on push to master branch, then
# deploy if test succeeds
#
# This is controlled by the job "deploy" value "needs: test"
name: Deploy
on:
@tomfa
tomfa / .github_slash_workflows_slash_release.sdk
Created May 23, 2021 12:03
semantic-release setup example
name: Release SDK
on:
push:
branches:
- master
jobs:
lint:
@tomfa
tomfa / yarn.npm.install.sh
Created May 21, 2021 22:23
Bash script to start any node project.
install() {
if test -f "package.json"; then
if test -f "package-lock.json"; then
npm install
elif test -f "yarn.lock"; then
yarn
else
echo "warning: no lock file"
yarn
fi
@tomfa
tomfa / Component.tsx
Last active October 9, 2021 18:07
NextJS storing state in URL
import { useQueryState } from 'next-usequerystate';
import { useEffect } from 'react';
const defaultData = {
name: 'Robert Paulsen',
age: 37,
}
const parse = (query) => {
try {
const json = JSON.parse(String(query));
return {
import { useState } from 'react';
export default function Component() {
const [name, setName] = useState('');
return (
<>
<input value={name} onChange={(e) => setName(e.target.value)} />
{name && (
<h1>
His name is <strong>{name}</strong>
@tomfa
tomfa / NextJSComponentWithQueryStringState.tsx
Created May 20, 2021 22:24
NextJS string state in URL query param
import useQueryString from './useQueryString'
export const Component = () => {
const [cat, setCat] = useQueryString<string>({
key: 'cat',
defaultValue: 'Robert Paulson',
});
return <h1>His name is <strong>{cat}</strong></h1>
@tomfa
tomfa / NextJSComponentWithUrlState.tsx
Last active May 20, 2021 21:57
NextJS JSON state in URL query param
import { parseUrlState } from './utils.query';
import useQueryString from './useQueryString'
type CatInfo = { name: string, age: number };
const defaultCatInfo = { name: 'Robert Paulson', age: 1 };
export const Component = () => {
const [cat, setCat] = useQueryString<CatInfo>({
key: 'cat',
defaultValue: defaultCatInfo,
@tomfa
tomfa / remove-gpg-user.sh
Created December 2, 2020 15:03 — forked from glogiotatidis/remove-gpg-user.sh
Git-crypt remove user.
#!/bin/bash
#
# Script to remove GPG key from git-crypt
#
# It will re-initialize git-crypt for the repository and re-add all keys except
# the one requested for removal.
#
# Note: You still need to change all your secrets to fully protect yourself.
# Removing a user will prevent them from reading future changes but they will
# still have a copy of the data up to the point of their removal.
@tomfa
tomfa / database.tf
Created September 16, 2020 21:30
Draft EC2 instance with RDS using Terraform.
# TODO: THIS FILE MIGHT HAVE TO GO TO OWN FOLDER database/main.tf
variable "security_group_ids" {
description = "Ids of VPC Security groups"
type = list(string)
}
variable "database_password" {
description = "Enter a new root SQL password. This variable is ignored if the DB is already set up."
type = string
@tomfa
tomfa / OTP.tsx
Last active July 1, 2020 23:26
React Native OTP input
import React, { useCallback, useRef, useState } from "react";
import { StyleSheet, TextInput, View } from "react-native";
export const useInputFocus = () => {
const refs = useRef<{ [key: string]: TextInput }>({});
const [currentFocus, setCurrentFocus] = useState<string>("");
const focus = useCallback(
(key: string) => {
if (refs.current[currentFocus]) {
refs.current[currentFocus].blur();