Friday, December 14, 2012
Monday, December 10, 2012
strftime
Go's time.Time already have Format, which is very human readable. However if you try to "embed" time format in longer strings, Format might expand things that you want to stay fixed. Take for example "/report06/2006", the first "06: will be expanded to the current year.
Python's strftime is less human readable but requires explicit escaping to it's easier to write string with embedded time directives. Now you can have strftime in Go as well.
To get it, run the usual go get bitbucket.org/tebeka/strftime.
Python's strftime is less human readable but requires explicit escaping to it's easier to write string with embedded time directives. Now you can have strftime in Go as well.
To get it, run the usual go get bitbucket.org/tebeka/strftime.
Tuesday, December 4, 2012
snowball
I wanted to play a bit with cgo. As a project I tried to have Go bindings to snowball.
One of the problems was that snowball does not come as a library but an archive of sources. cgo can handle C source files, but all in the same directory. I had to "flatten" the source tree, rewriting #include directives (sed FTW!).
One the above was done, the rest was pretty much straightforward. I confess that at the beginning I wanted to write a lot of C helper functions, but managed to resist the temptation :)
You can get it with go get bitbucket.org/tebeka/snowball. Note the building takes time - that's C compilation for you :)
One of the problems was that snowball does not come as a library but an archive of sources. cgo can handle C source files, but all in the same directory. I had to "flatten" the source tree, rewriting #include directives (sed FTW!).
One the above was done, the rest was pretty much straightforward. I confess that at the beginning I wanted to write a lot of C helper functions, but managed to resist the temptation :)
You can get it with go get bitbucket.org/tebeka/snowball. Note the building takes time - that's C compilation for you :)
Friday, October 26, 2012
nrsc - Take 2
After getting some good comments on nrsc and reading more. I re-wrote the implementation to append a zip file to the executable and serve resources from there (idea from Carlos Castillo).
The order you do the packing has change, you first "go build" and then run the nrsc script.
Here the nrsc script that packs the zip into the executable. The nrsc API didn't change that much.
The order you do the packing has change, you first "go build" and then run the nrsc script.
Here the nrsc script that packs the zip into the executable. The nrsc API didn't change that much.
Tuesday, October 23, 2012
nrsc - Resource Compiler
IMO one of the nicest things in Go is the "single executable deployment". However this breaks down when you have some templates, css files, ...
For this I created nrsc, it's a resource compiler that will compile your resources to a local nrsc package which you can include in your project. Building your project after running nrsc will embed all the resource in the executable.
To install nrsc just run go get bitbucket.org/tebeka/nrsc
Here's an example on how to use nrsc in your code:
For this I created nrsc, it's a resource compiler that will compile your resources to a local nrsc package which you can include in your project. Building your project after running nrsc will embed all the resource in the executable.
To install nrsc just run go get bitbucket.org/tebeka/nrsc
Here's an example on how to use nrsc in your code:
Friday, September 21, 2012
Jenkins/Hudson Integration
The most dominate CI system is Jenkins (was Hudson).
Jenkins has a nice integration with xunit XML output for tests. I wrote a little utility that converts go test -v output to xunit compatible XML called go2xunit. (install with the usual go get bitbucket.org/tebeka/go2xunit).
The view on Jenkins (tests are failing intentionally) is like the below.
When you click on the tests you get
There's a demo directory with an example bash script. The project configuration looks something like the below. Note the "Execute Shell" command and "Publish JUnit tests report" sections.
Happy Testing.
Jenkins has a nice integration with xunit XML output for tests. I wrote a little utility that converts go test -v output to xunit compatible XML called go2xunit. (install with the usual go get bitbucket.org/tebeka/go2xunit).
The view on Jenkins (tests are failing intentionally) is like the below.
When you click on the tests you get
There's a demo directory with an example bash script. The project configuration looks something like the below. Note the "Execute Shell" command and "Publish JUnit tests report" sections.
Happy Testing.
Thursday, September 6, 2012
seamless - now with multiple backends
Updated seamless to support multiple backends (thank you Fabrizio for helping out).
The new API is:
You can install either via go get bitbucket.org/tebeka/seamless or by downloading the binaries.
The new API is:
- /set?backends=host:port,host:port
- /add?backend=host:port
- /remove?backend=host:port
- /get
You can install either via go get bitbucket.org/tebeka/seamless or by downloading the binaries.
Friday, August 10, 2012
seamless - always up services in 85 lines of Go
At work we're debating on how to upgrade servers that need to be up all the time. This prompted me to write seamless.
It's a 1 to 1 TCP proxy which lets you switch the backend via an HTTP interface (on a different port than the one being proxied).
Typical workflow will be:
go install bitbucket.org/tebeka/seamless
or if you don't have the go runtime, you can download the binaries.
72 85 lines.
It's a 1 to 1 TCP proxy which lets you switch the backend via an HTTP interface (on a different port than the one being proxied).
Typical workflow will be:
- Start backend on internal port
- Start seamless and proxy exposed port to backend
- When upgrading start new backend on different external port
- Tell seamless to switch backends
go install bitbucket.org/tebeka/seamless
or if you don't have the go runtime, you can download the binaries.
Tuesday, July 3, 2012
timeat
A small command line utility to display the current time at a given location. It's a mash between Google Maps API (JSON) and Geonames (XML).
Saturday, April 28, 2012
Thursday, April 19, 2012
Open file/urls with default program
Here's the code for a cross platform way to open file/uri with default application.
You can also install the package with
go install bitbucket.org/tebeka/desktop
You can also install the package with
go install bitbucket.org/tebeka/desktop
Monday, April 16, 2012
Web/Desktop Application
Currently there's no easy/cross platform way to write desktop applications in go.However I found out the for simple UI (which in my case covers most of them). I can get away with writing the application as a web server and point the user browser to it.
Here is a small example for a guest book:
Saturday, April 7, 2012
Building Go Projects
Now that Go1 is out, the way to build projects is using the go tool. I found out that the following process works for me.
I have a directory goroot somewhere and there under src I have all my projects. Then I use the following Makefile (this is an example from selenium/webdriver client).
I have a directory goroot somewhere and there under src I have all my projects. Then I use the following Makefile (this is an example from selenium/webdriver client).
Wednesday, December 14, 2011
dayrange
While working on something else, I need to write a little utility function that returns a range of days. (When the new time package make it to release, this should be much simpler).
Tuesday, December 6, 2011
AppEngine Demo - URL Shortener
Here you can find a small AppEngine Go example.It is a URL shortener (like bit.ly). I shows the following capabilities:
- HTTP Serving
- Templates
- Datastore
- Task Queue
- Logging
- Memcache
Sunday, November 27, 2011
Reversim Interview
Had great fun talking about Go with Ran and Ori at Reversim.
You can listen to the podcast here (note: it's in Hebrew).
You can listen to the podcast here (note: it's in Hebrew).
Tuesday, November 8, 2011
A simple atexit library
Go does not have an atexit library (and will probably never have). Below is a small implementation of such a library. Note that you have to use atexit.Exit and not os.Exit in your program.
As usual, you can install with goinstall bitbucket.org/tebeka/atexit
And here is an example program (the funky import is due to running this program as a test in the source directory)
As usual, you can install with goinstall bitbucket.org/tebeka/atexit
And here is an example program (the funky import is due to running this program as a test in the source directory)
Monday, October 24, 2011
expvar
The expvar let you expose variables via HTTP/JSON protocol. Here at Adconion we call these metrics, and more than once they have been very instrumental in debugging and monitoring services.
We usually combine the metrics with an external monitoring system such as Nagios or OpenNMS. We set some thresholds for alerts and also chart some of them metrics over time.
Below is a small demo on how to use the package.
We usually combine the metrics with an external monitoring system such as Nagios or OpenNMS. We set some thresholds for alerts and also chart some of them metrics over time.
Below is a small demo on how to use the package.
Thursday, October 20, 2011
Network programming with Go
Network programming with Go is a nice into. It also has a great chapter explaining the new template package.
Tuesday, October 11, 2011
Number → English
Had some fun converting num2eng.py to Go and making it a web service.
Subscribe to:
Posts (Atom)




