Skip to content

Instantly share code, notes, and snippets.

View natdm's full-sized avatar

Nathan Hyland natdm

View GitHub Profile
@natdm
natdm / main.go
Created September 22, 2016 02:11
Testing Negroni middleware knowledge
package main
//Messing with Negroni subroutes.
import (
"fmt"
"io"
"log"
"net/http"
"os"
@natdm
natdm / app.go
Created September 22, 2016 14:26
Playing with context
package main
import (
"fmt"
"time"
"golang.org/x/net/context"
)
func main() {
@natdm
natdm / app.go
Created September 26, 2016 15:40
Check if a file has a particular set of bytes in it, and replace it with other bytes.
package main
import (
"bytes"
"io/ioutil"
"log"
"os"
)
//Open a file, read the bytes, check if the bytes have a sequence of bytes, then replace those bytes with other ones
@natdm
natdm / readByes.md
Created September 26, 2016 16:15
Compare bytes from a slice of bytes to a file and replace them with other bytes if found.

Reading and replacing some bytes!

Here is the entire application. Below that is a step by step guide.

package main

import (
	"bytes"
	"io/ioutil"
@natdm
natdm / gscript.sh
Last active January 17, 2017 16:50
AWS AMI script for Go/Glide/Git
#!/bin/bash
# Install and extract go
sudo wget -P /home/ec2-user/ https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
cd /home/ec2-user/
tar -xzf go1.7.4.linux-amd64.tar.gz
# Set up env. variables
export GOROOT=/home/ec2-user/go
export PATH=$PATH:$GOROOT/bin
@natdm
natdm / PIPELINES.md
Last active November 3, 2017 18:22
Showing composable, concurrent pipelines in Go

Pipelines in Go are really neat. They're composable functions that allow you to chain concurrent events together, safely.

If you have the need to call API after API after API, witl the same data, maybe pipelines could help. Imagine you have the following:

func create(item Object) Object {
  // do things, call APIs
  return item
}
definition(
name: "Smarter Nightlight",
author: "Nathan Hyland",
description: "Turns on lights when it's dark and motion is detected and lights are not already on. Turns lights off when it becomes light or some time after motion ceases.",
category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-luminance.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-luminance@2x.png"
)
preferences {