Skip to content

Instantly share code, notes, and snippets.

View housingdreams's full-sized avatar

David Pennington housingdreams

View GitHub Profile
@housingdreams
housingdreams / json.go
Created April 13, 2022 21:36
Example of adding validation to a json unmarshal for things like required fields or regex validation via github.com/asaskevich/govalidator or https://github.com/go-playground/validator
func UnmarshalWithValidation(data []byte, p interface{}) error {
err := json.Unmarshal(data, p)
if err != nil {
return err
}
isValid, err := govalidator.ValidateStruct(p)
if err != nil {
return err
}
@housingdreams
housingdreams / docker-compose.yml
Created February 18, 2022 22:10 — forked from valekar/docker-compose.yml
Docker Compose gist for MYSQL
version: "3.7"
services:
db:
image: mysql:5.7
restart: "unless-stopped"
ports:
- 3309:3306
# uncomment the volume mount to import .sql files
# during database initalization
# volumes:
@housingdreams
housingdreams / use-local-storage.js
Created October 5, 2021 17:02 — forked from nihlton/use-local-storage.js
useLocalStorage React Hook
import { useState, useCallback, useEffect } from 'react'
const customEvent = 'myMagicalStorageHook'
export default function useLocalStorage(
key,
initialValue,
lifeSpan = Infinity
) {
const [storedValue, setStoredValue] = useState(() => {
@housingdreams
housingdreams / Testing-In-Golang.md
Created October 2, 2021 17:06
Collection of links and examples showing testing, microservices, mocks, interfaces, and many other common solutions in Go (golang)
@housingdreams
housingdreams / checkout_all_repos.go
Last active September 20, 2021 17:51
Checkout all organization repos using Go
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/exec"
"strings"
@housingdreams
housingdreams / setup_android.md
Created July 21, 2021 19:36
Setup android studio on a Mac OSX will full support for command line tooling

Minimal install using android studio + builtin JDK

# https://developer.android.com/studio/command-line/variables
export ANDROID_SDK_ROOT="${HOME}/Library/Android/sdk"                              # required
export ANDROID_SDKMANAGER="${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/"         # emulator, sdkmanager, etc..
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home" # bundled JDK
export PATH=$ANDROID_SDK_ROOT:$ANDROID_SDKMANAGER:$PATH
@housingdreams
housingdreams / nested_errors.go
Created July 21, 2021 15:40
Example of finding a root error with Go: https://play.golang.org/p/C_A50VPZa4X
package main
import (
"errors"
"fmt"
"log"
)
var errTCP = errors.New("tcp connection failed")
@housingdreams
housingdreams / duck_typing_model.ts
Last active March 9, 2022 18:35
Example of using duck typing to implement just a subset of an interface we need
interface Datastore {
GetUser(): User;
SaveUser(u: User): void;
}
class User {}
class MySQLDatastore implements Datastore {
public GetUser(): User { return new User(); }
public SaveUser(u: User): void { return }