Skip to content

Instantly share code, notes, and snippets.

View josephspurrier's full-sized avatar

Joseph Spurrier josephspurrier

View GitHub Profile
@josephspurrier
josephspurrier / values_pointers.go
Last active November 19, 2024 10:43
Golang - Asterisk and Ampersand Cheatsheet
/*
********************************************************************************
Golang - Asterisk and Ampersand Cheatsheet
********************************************************************************
Also available at: https://play.golang.org/p/lNpnS9j1ma
Allowed:
--------
p := Person{"Steve", 28} stores the value
@josephspurrier
josephspurrier / aescmd.go
Created December 23, 2014 07:11
Golang - Encrypt, Decrypt, File Read, File Write, Readline
package main
import (
"bufio"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"fmt"
"io"
"io/ioutil"
@josephspurrier
josephspurrier / structs_interface.go
Last active March 21, 2024 08:11
Golang - Understand Structs and Interfaces
// Also available at: https://play.golang.org/p/yTTpB5gB6C
package main
import (
"fmt"
)
// *****************************************************************************
// Example 1 - Struct vs Struct with Embedded Type
@josephspurrier
josephspurrier / hotreload.go
Last active October 13, 2023 16:19
Golang HTTP Redirect using JavaScript and Long Polling
package main
import (
"bytes"
"errors"
"fmt"
"io"
"log"
"os"
"os/exec"
@josephspurrier
josephspurrier / openswan-aws.md
Last active September 27, 2023 12:12
Set up VGW on AWS with OpenSwan

Set up VGW on AWS with OpenSwan

You will need 2 VPCs. The Internet VPC will have the Internet Gateway and the OpenSwan EC2 instance. The Project VPC will have your application or Kubernetes cluster.

Internet VPC

  • VPC CIDR: 10.230.30.0/24
  • Private Subnet: 10.230.30.128/25 - Route Table with 0.0.0.0/0 to NAT
  • Public Subnet: 10.230.30.0/25 - Route Table with 0.0.0.0/0 to IGW, 10.224.36.0/23 to OpenSwan Instance
  • NAT Gateway in the public subnet with an IP of 52.15.61.171
@josephspurrier
josephspurrier / Dockerfile
Created December 3, 2020 02:14
AWS Lambda Container in Go
FROM public.ecr.aws/lambda/go:1
# Copy function code
COPY hello ${LAMBDA_TASK_ROOT}
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "hello" ]
@josephspurrier
josephspurrier / main.go
Last active March 8, 2023 08:52
OpenAI/ChatGPT Terminal in Go
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
@josephspurrier
josephspurrier / addimport.go
Last active October 28, 2022 14:34
Add Import using ast in Go
// Source: https://gitlab.pro/googlesource/tools/blob/ae534bcb6ccdd13487d0491c2194d10ebcd30ff3/astutil/imports.go
// Source: https://golang.org/src/go/doc/example.go#L262
package main
import (
"bytes"
"fmt"
"go/ast"
"go/parser"
@josephspurrier
josephspurrier / loadCSV.php
Last active September 28, 2022 10:34
Parse a CSV file in PHP, remove hidden characters, escape fields to prepare for MySQL, and return an associative array.
// Auto detect line endings
ini_set('auto_detect_line_endings', true);
function loadCSV($file)
{
// Create an array to hold the data
$arrData = array();
// Create a variable to hold the header information
$header = NULL;
@josephspurrier
josephspurrier / .bash_profile
Last active September 13, 2022 21:25
macOS Bash Profile
#################################################################################
#
# Bash Configurations and Aliases for OS X
#
# Latest: https://gist.github.com/josephspurrier/acf7327726df6587a56ff2c2062314fa
# This was modified so it can be included in your ~/.zshrc file with the command:
# source ~/.bash_profile
#
# It's recommended to use oh-my-zsh:
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"