Skip to content

Instantly share code, notes, and snippets.

View peacefixation's full-sized avatar

Matt Jarvis peacefixation

  • Melbourne, Australia
View GitHub Profile
@peacefixation
peacefixation / records.txt
Last active August 23, 2019 03:10
Prog records for Abel
Aria - One [https://www.discogs.com/Aria-One/release/4996]
Austin Leeds - Moondiver [https://www.discogs.com/Austin-Leeds-Force-51/master/356216]
Cass & Slide - Diablo (Evolution Mix) [https://www.discogs.com/Cass-v-Slide-Diablo/master/34028]
D. Troy - Sixteen U (Antoine 909 Remix) [https://www.discogs.com/DTroy-Sixteen-U/release/408047]
Decepticons - Eastern Promise [https://www.discogs.com/Decepticons-Eastern-Promise/master/450988]
Decepticons - Deep Underground (Jade's journey through the underworld mix) [https://www.discogs.com/Decepticons-Deep-Underground/master/552944]
Deep Funk Project - 2 Heavy [https://www.discogs.com/Deep-Funk-Project-2-Heavy-Dirty-Logic/master/247225]
DJ Gogo - Anjuna [https://www.discogs.com/DJ-Gogo-Anjuna/release/163498]
Jimmy Van M - E.C.I-P.S [https://www.discogs.com/Jimmy-Van-M-ECI-PS/release/6087]
Osamu M - Moon Over [https://www.discogs.com/Osamu-M-Moon-Over/release/252977]
@peacefixation
peacefixation / gist:bfd3388f63ed04e94dac80a86954daaa
Created July 1, 2019 08:24
Controlling MS PowerPoint with JavaScript
https://docs.microsoft.com/en-us/office/dev/add-ins/quickstarts/powerpoint-quickstart
https://medium.com/@ferrygunawan/controlling-powerpoint-slides-with-alexa-and-websocket-fd3c91c0901b
https://www.npmjs.com/package/slideshow
@peacefixation
peacefixation / mx.go
Created May 8, 2019 02:48
Check valid MX record
import (
"fmt"
"net"
"strings"
)
// isValidEmailMX looks up the MX records for the email address and to check if the domain is valid
func isValidEmailMX(emailAddress string) (bool, error) {
parts := strings.Split(emailAddress, "@")
if len(parts) != 2 {
@peacefixation
peacefixation / aesgcm.go
Created May 7, 2019 00:35
AES-GCM encryption
package crypto
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"io"
)
@peacefixation
peacefixation / Crypto.java
Last active May 1, 2019 09:55
Encrypt JPA entity fields with AES
package crypto;
import CryptoException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.InvalidAlgorithmParameterException;
@peacefixation
peacefixation / trace.go
Created April 10, 2019 03:05
Trace function name, line number
func trace() string {
pc := make([]uintptr, 15)
n := runtime.Callers(2, pc) // 2 -> the calling function's frame details
frames := runtime.CallersFrames(pc[:n])
if frame, ok := frames.Next(); ok {
// frame.File is the full file path
return fmt.Sprintf("%s:%d", frame.Function, frame.Line)
}
return ""
}
@peacefixation
peacefixation / update-join.sql
Created March 27, 2019 04:31
Postgres update join
-- given two tables with a foreign key
-- and the requirement to set a field in tableA to the value of the corresponding field in tableB
-- in this case setting tableA.someField to tableB.someOtherField where tableA.fk_id = tableB.id
-- tableA (
-- id
-- someField
-- fk_id
-- )
@peacefixation
peacefixation / json-marshal.go
Last active March 26, 2019 02:21
Implement MarshalJSON and UnmarshalJSON on a custom type
import (
"fmt"
"strings"
"time"
)
const timeFormat = "2006-01-02 15:04:05"
// JSONTime a wrapper for time.Time that unmarshalls with a custom date format
type JSONTime struct {
@peacefixation
peacefixation / subnet.go
Last active March 27, 2019 01:33
Subnet contains IP
// SubnetContainsIP check if an IP address is part of the subnet given by the CIDR (ie. '192.168.0.0/24')
func SubnetContainsIP(CIDR, addr string) (bool, error) {
_, ipNet, err := net.ParseCIDR(CIDR)
if err != nil {
return false, fmt.Errorf("Error parsing CIDR '%s'", CIDR)
}
host, _, err := net.SplitHostPort(addr)
if err != nil {
return false, fmt.Errorf("Error parsing address '%s'. %v", addr, err)
@peacefixation
peacefixation / middleware.go
Last active March 27, 2019 01:34
HTTP middleware
import "github.com/julienschmidt/httprouter"
// usage
// router.POST("/path", BasicAuth(someRequestHandler))
// BasicAuth middleware for incoming requests that must include basic authentication
func BasicAuth(handler httprouter.Handle) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
log.Printf("Authorizing request from %s", r.RemoteAddr)