Skip to content

Instantly share code, notes, and snippets.

@rickt
rickt / palindrome.go
Last active August 29, 2015 14:02
palindrome tester
package main
import (
"fmt"
"os"
)
// func main
func main() {
var s string = os.Args[1]
@rickt
rickt / asynchttpget.go
Last active August 29, 2015 14:02
example of how to do asynchronous http gets
package main
import (
"fmt"
"net/http"
"time"
)
var urls = []string{
"http://rickt.org",
@rickt
rickt / check-if-jpeg.go
Last active August 29, 2015 14:02
check if a file really is a JPEG or not
package main
import (
"fmt"
"image"
"image/jpeg"
"os"
)
func checkIsJPEG(filename string) error {
@rickt
rickt / randomstring.go
Created June 20, 2014 21:23
generate a random string
package main
import (
"crypto/rand"
"fmt"
)
func main() {
fmt.Printf("randstring = %s\n", rand_str(5)) // change "5" to be whatever length string you need
@rickt
rickt / url-escaping.go
Created June 20, 2014 21:20
how to properly escape URLs in go
package main
import (
"fmt"
"net/url"
)
func main() {
var Url *url.URL
package main
import "fmt"
import "regexp"
var email = regexp.MustCompile(`^[^@]+@[^@.]+\.[^@.]+$`)
var shortPhone = regexp.MustCompile(`^[0-9][0-9][0-9][.\-]?[0-9][0-9][0-9][0-9]$`)
var longPhone = regexp.MustCompile(`^[(]?[0-9][0-9][0-9][). \-]*[0-9][0-9][0-9][.\-]?[0-9][0-9][0-9][0-9]$`)
func main() {
@rickt
rickt / isascii.go
Last active August 29, 2015 14:02
check to see if something is ASCII or not
package main
import "fmt"
func isASCII(s string) bool {
for _, c := range s {
if c > 127 {
return false
}
}