Skip to content

Instantly share code, notes, and snippets.

Avatar

Tomas Fagerbekk tomfa

View GitHub Profile
View remove-gpg-user.sh
#!/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 Sep 16, 2020
Draft EC2 instance with RDS using Terraform.
View database.tf
# 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 Jul 1, 2020
React Native OTP input
View OTP.tsx
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();
@tomfa
tomfa / react-native-next-input-focus.jsx
Last active Jul 1, 2020
React Native: Focus next element on complete
View react-native-next-input-focus.jsx
import React, { useCallback, useRef, useState } from 'react';
import { TextInput } from 'react-native';
export const useInputFocus = () => {
const refs = useRef({});
const [currentFocus, setCurrentFocus] = useState('');
const focus = useCallback(
key => {
if (refs.current[currentFocus]) {
refs.current[currentFocus].blur();
@tomfa
tomfa / .git_profile
Last active Jun 22, 2020
Useful Git aliases
View .git_profile
# My Git aliases
#
# Add these by putting this file in home directory + adding the following line to .bash_profile:
# source ~/.git_profile
#
# (alternatively, just copy in whatever you want to your .bash_profile)
# Diff between where I am and master
alias gdm='git diff master...head'
View swear.js
/*
* Swear
*
* Replaces callback functions with Promises
*
* Example reading a file with fs:
* const fs = require('fs');
*
* const path = '/path/to/file.txt'
* const fileContent = await swear(fs.readFile, path)
View Project Euler #28
def numbers(width):
assert width % 2 == 1, "Need odd numbered size"
sum = 1
last_number = 1
i = 3
while i <= width:
sum += last_number * 4 + (i - 1) * 10
last_number += (i - 1) * 4
i += 2
return sum
View PE #28
def numbers(width):
assert width % 2 == 1, "Need odd numbered size"
sum = 1
last_number = 1
i = 3
while i <= width:
sum += last_number * 4 + (i - 1) * 10
last_number += (i - 1) * 4
i += 2
return sum
View PE #26
from decimal import *
getcontext().prec = 2000
def find_recurring_length(divisor):
digits = (Decimal(1) / Decimal(divisor)).as_tuple().digits[:-1]
precision = getcontext().prec -1
if len(digits) != precision:
return 0
recurring = 0
@tomfa
tomfa / example_completed_notification.xml
Last active Mar 12, 2021
Docusign webhook xml example
View example_completed_notification.xml
<?xml version="1.0" encoding="utf-8"?>
<DocuSignEnvelopeInformation xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.docusign.net/API/3.0">
<EnvelopeStatus>
<RecipientStatuses>
<RecipientStatus>
<Type>Signer</Type>
<Email>tomas@echo.com</Email>
<UserName>Tomas Fagerbekk</UserName>