Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am techjanitor on github.
  • I am oscillons (https://keybase.io/oscillons) on keybase.
  • I have a public key whose fingerprint is 38E0 8372 B3F6 6F58 40FA 6CD9 F1E5 E965 0091 5078

To claim this, I am signing this object:

@techjanitor
techjanitor / backup.sh
Last active February 3, 2016 04:59
mysql backup cron
#!/bin/bash
# creates a mysql backup
#
# CREATE USER 'backups'@'localhost' IDENTIFIED BY 'password';
# GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'backups'@'localhost';
# FLUSH PRIVILEGES;
#
# restore: innobackupex --copy-back /data/backups/whatever
# timestamp
@techjanitor
techjanitor / exec.go
Created June 11, 2015 18:16
concurrent exec: single producer, multiple consumer
package main
import (
"bufio"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
@techjanitor
techjanitor / gcs.go
Created May 9, 2015 04:08
Upload a file to Google Cloud Storage
package main
import (
"errors"
"fmt"
"golang.org/x/oauth2"
"golang.org/x/oauth2/jwt"
storage "google.golang.org/api/storage/v1"
"os"
)
@techjanitor
techjanitor / hmac.go
Created April 18, 2015 03:43
Example of web safe, hmac signed JSON messages
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"time"
)
@techjanitor
techjanitor / extensions.go
Created January 13, 2015 05:21
a way to check file extensions
package main
import (
"fmt"
"strings"
)
func main() {
ext := ".WEBM"
@techjanitor
techjanitor / contains.go
Created January 1, 2015 22:26
Case insensitive string comparison
func contains(s []string, e string) bool {
for _, a := range s {
if strings.EqualFold(a, e) {
return true
}
}
return false
}
@techjanitor
techjanitor / cloudflare.go
Last active August 29, 2015 14:12
Ban someone on cloudflare
package main
import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"net/url"
)
@techjanitor
techjanitor / sitemap.go
Created October 12, 2014 09:16
Generate Google sitemap
package main
import (
"bufio"
"encoding/xml"
"fmt"
"os"
)
func main() {
@techjanitor
techjanitor / scrape.go
Last active August 29, 2015 14:07
Scrape a website with GoQuery
func Scrape(address string) (b *bytes.Buffer) {
// Create a new goquery document from the address
doc, err := goquery.NewDocument(address)
if err != nil {
log.Fatal(err)
}
// A buffer for the CSV writer
b := &bytes.Buffer{}