code

Ping

There are two ways to ping go internal ping sys ping The go internal ping works only as root, therefor a sys ping is also provided until I can figure out how to fix this problem. Website Code is available at https://bitbucket.org/gotamer

Smtp

Now gotamer/mail also implements the io.Writer interface. Example: package main import ( "fmt" "bitbucket.org/gotamer/mail" ) func main() { s := new(mail.Smtp) s.SetHostname("smtp.gmail.com") s.SetHostport(587) s.SetFromName("GoTamer") s.SetFromAddr("xxxx@gmail.com") s.SetPassword("*********") s.AddToAddr("to@example.com") s.SetSubject("GoTamer test smtp mail") s.SetBody("The Writer below should replace this default line") if _, err := fmt.Fprintf(s, "Hello, smtp mail writer\n"); err != nil { fmt.Println(err) } } As an alternative to AddToAddr() there is SetToAddrs(). With SetToAddrs() you can set one or more recipients as a comma separated list.

Your Everyday Go Tools

Generates a random number between min and max func IRand(min, max int) int Generates a random strings between min and max func SRand(min, max int, readable bool) string Reverses the string func Reverse(s string) strings Shuffles the string func Shuffle(s string) string Links Pkg Documantation Repository

Encode/Decode Golang data to Gob files

Golang has a package called Gob to encode and decode values in to go specific binary format for transmiting as streams or for saving to file. Below are two functions, Load and Save to encode/decode go values including struct’s in to files. package main import ( "encoding/gob" "fmt" "os" "runtime" ) const file = "/tmp/test.gob" type User struct { Name, Pass string } func main(){ var datato = &User{"Donald","DuckPass"} var datafrom = new(User) err := Save(file, datato) Check(err) err = Load(file, datafrom) Check(err) fmt.

Citadel vCard Sync

Features Citadel Sync will work on most operating systems including Linux, Mac, PC, Android … Converts a multi vCard file in to many for each to hold a single contact Adds UID and REV fields to the vCard if missing Uploads vCards to a given remote [Citadel] Mail Server You can specify, which folder on the server to upload to Can populate the Display name field from first and last name, or populate first and last name from display name Features planned Compare revision state and sync in case you modify a vCard on the server.

Sometimes I fall in love with code

I don’t use this, since I need often more but isn’t this just need? http://play.golang.org/p/QFheQeChIn package main import "log" const debug debugging = true // or flip to false type debugging bool func (d debugging) Printf(format string, args ...interface{}) { d { log.Printf(format, args...) } } func main() { debug.Printf("foo %d %.2f", 42, 12.7) }

Go jkl

I just dumped my home made php script md2html and switched to jkl. This is basiclly my test post! jkl is a static site generator written in Go, based on Jekyll. All I had to do was convert my template to Go tempates, and add the YAML front matter to my markdown files. jkl is by far faster then md2html provides a build in server The Go templates are a bid easier to work with.

Read Folder

This is a Lambda function also called anonymous function within a regular function that scans a given directory and it’s sub directories returning an array of all php files within. Following is a snip output of the Zend files. [6] => /usr/share/php/Zend/Captcha/ReCaptcha.php [7] => /usr/share/php/Zend/Captcha/Base.php [8] => /usr/share/php/Zend/Feed/Rss.php [9] => /usr/share/php/Zend/Feed/Atom.php [52] => /usr/share/php/Zend/Feed/Writer/Source.php [53] => /usr/share/php/Zend/Feed/Pubsubhubbub.php [54] => /usr/share/php/Zend/Feed/Element.php [55] => /usr/share/php/Zend/Feed/Reader/Feed/Rss.php [90] => /usr/share/php/Zend/Feed/Builder.php [91] => /usr/share/php/Zend/Feed/Writer.php [92] => /usr/share/php/Zend/Config.

Autoload

I have been looking around for some good examples to use the new PHP autoloader interoperability standard according to the PHP Standards Recommendation #0 (PSR-0). And since I could find anything good, I had to figure it out by my self, here is the result. gist id=3027247 HowTo: <?php # Adds your library to the beginning of the php include path addInclude('~/code/libs', FALSE); $loader = new SplClassLoader(); # adds the php include path to the class $loader->setIncludePathLookup(true); $loader->add('Zend'); $loader->add('PEAR'); # Give the path if it isn't in the php include path like this $loader->add('Symfony', '/path/to/symfony'); $loader -> register(); ?

Messenger Laravel Framework

This is a fork and upgrade of the davzie message class. A info, error etc messenger class that allows you to add validation errors, statuses etc to flash data and then retrieve them in a nicely formatted way in your front-end. Automates the process a little when you’re adding and retrieving messages, especially in a CRUD type environment. The formatting integrates well with Twitter’s Bootstrap Alert formatting. This upgraded version works smoothly with the Laravel validation class