Skip to content

Instantly share code, notes, and snippets.

@techjanitor
techjanitor / upload.go
Last active January 31, 2016 13:32
Upload to a multipart/form-data form
func UploadPosts(file, date, name, comment, url string) (err error) {
// Make a new multipart writer with a buffer
var b bytes.Buffer
w := multipart.NewWriter(&b)
// This is just a random form field
if err = w.WriteField("name", name); err != nil {
return
}
@techjanitor
techjanitor / magic.go
Last active August 29, 2015 14:07
Check file signatures like libmagic
image, err := os.Open(imagefile)
if err != nil {
err = errors.New("problem opening file")
return
}
defer image.Close()
// Check file type
bytes := make([]byte, 4)
n, _ := image.ReadAt(bytes, 0)
@techjanitor
techjanitor / md5_tee.go
Last active August 29, 2015 14:07
Get MD5 hash with TeeReader
// Make new md5
hasher := md5.New()
// Make a new file
image, err := os.Create(imagefile)
if err != nil {
err = errors.New("problem creating file")
return
}
@techjanitor
techjanitor / sfs.go
Last active August 29, 2015 14:07
Query Stop Forum Spam
func CheckStopForumSpam(ip string) error {
sfs_endpoint, err := url.Parse("http://api.stopforumspam.org/api")
if err != nil {
return errors.New("error parsing sfs endpoint")
}
queryValues := url.Values{}
if ip == "" {