Skip to content

Instantly share code, notes, and snippets.

View craicoverflow's full-sized avatar
🏠
Working from home

Enda craicoverflow

🏠
Working from home
View GitHub Profile
@craicoverflow
craicoverflow / pre-commit
Last active February 21, 2022 11:03
Pre-commit Git hook for Go code
#!/bin/sh
# Run some pre commit checks on the Go source code. Prevent the commit if any errors are found
echo "Running pre-commit checks on your code..."
FILES=$(go list ./... | grep -v /vendor/)
# Format the Go code
go fmt ${FILES}
@craicoverflow
craicoverflow / main.go
Last active March 2, 2019 19:55
Accessing and printing an environment variable value in Go
package main
import (
"fmt"
"os"
)
func main() {
// Store the PATH environment variable in a variable
path, exists := os.LookupEnv("PATH")
@craicoverflow
craicoverflow / main.go
Last active February 28, 2019 20:08
Setting an environment variable in Go
package main
import (
"fmt"
"os"
)
func main() {
// Set the USERNAME environment variable to "MattDaemon"
os.Setenv("USERNAME", "MattDaemon")
@craicoverflow
craicoverflow / main.go
Last active March 2, 2019 19:49
Load environment variables from a .env file in Go using godotenv
package main
import (
"log"
"github.com/joho/godotenv"
"fmt"
"os"
)
// init is invoked before main()
@craicoverflow
craicoverflow / config.go
Last active March 2, 2019 19:52
Config file in Go which uses environment variables and falls back on a default value
package config
import (
"os"
)
type GitHubConfig struct {
Username string
APIKey string
}
@craicoverflow
craicoverflow / main.go
Last active February 28, 2019 21:21
Using the config struct in Go
package main
import (
"fmt"
"log"
"github.com/joho/godotenv"
"github.com/craicoverflow/go-environment-variables-example/config"
)
package main
import (
"fmt"
"log"
"github.com/craicoverflow/go-environment-variables-example/config"
"github.com/joho/godotenv"
)
@craicoverflow
craicoverflow / config.go
Last active March 8, 2019 18:43
Config struct that handles strings, bools, integers and slices
package config
import (
"os"
"strconv"
"strings"
)
type GitHubConfig struct {
Username string
@craicoverflow
craicoverflow / Alert.js
Created April 21, 2019 11:32
React Alert component using hooks
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types";
/**
* Customisable alert component that remains hidden until called.
*
* @param {boolean} props.visible - The current visibility of the component.
* @param {number} [props.duration] - The time in milliseconds to display the component for. If not set, the component will stay open.
* @param {func} onTimeoutEnd - Set visible state of component from parent.
* @param {*} props.children - Child components.
@craicoverflow
craicoverflow / mdc-cheatsheet.md
Last active July 30, 2019 08:14
A list of useful commands to get Mobile Developer Console installed

MDC Cheatsheet

aerogear/mobile-developer-console

Development

Use the dedicated script to start Minishift. This enables CORS gives the developer user cluster-admin privileges.

Setup