Bugs Become Features

  • Home
  • About
  • Research
  • Projects
  • Publications
  • Teaching
  • Blog
  • Archives

Golang

17 posts tagged with "Golang"

  • 22 Sep 2014
    Search Gear 20 Cleaning Up

    Cleaning up those nasty files func (tw *twitter) cleanUp(entity string) (string, error) { if entity == "" { entity = “myHome” } cleanTime := time.Now().AddDate(0, 0, -2) fileName := strings.Join([]string{entity, “_”, cleanTime.Format(“2006-01-02”), “.json”}, “”) if err := os.Remove(fileName); err != nil { log.Println(“Failed to”, err) } return fileName, nil } So why not have this as a cloud service, and why not allow the grouping of people you follow? Also investigate twitter security better, especially around the developer api.

  • 19 Sep 2014
    Search Gear 19 Regular Expressions

    func getItem(entries toml.Value) func() (string, error) { i := -1 return func() (string, error) { rExpression := regexp.MustCompile("(-([A-Z]+|[A-Z]+[1-9])-)") i += 1 if i < len(entries.AsArray()) { if rExpression.FindString(entries.AsArray()[i].AsString()) != "" { foundString := rExpression.FindString(entries.AsArray()[i].AsString()) switch foundString { case "-YY-": replaceWith := strconv.Itoa(time.Now().Year()) entity := rExpression.ReplaceAllLiteralString(entries.AsArray()[i].AsString(), replaceWith[2:4]) return entity, nil case "-YY1-": replaceWith := strconv.Itoa(time.Now().Year() + 1) entity := rExpression.ReplaceAllLiteralString(entries.AsArray()[i].AsString(), replaceWith[2:4]) return entity, nil case "-YYYY-": replaceWith := strconv.Itoa(time.Now().Year()) entity := rExpression.

  • 09 Sep 2014
    Search Gear 18 - Anonymous Functions and Closures

    Now, I also need a function to process wildcards out of hashtags maybe creating multiple requests from a single tag. Let’s go with anonymous functions and closures, which in flirted with on day 7, what seems like years ago now! https://gobyexample.com/closures func getItem(entries toml.Value) func() string { i := -1 return func() string { i += 1 if i Then a function to loop ‘collect’ for each tag, user, and home.

  • 08 Sep 2014
    Search Gear 17 - TEST the TWITTER COLLECTOR

    First run Starts at: Wed Aug 27 03:44:15 +0000 2014 Ends at: Wed Aug 27 07:49:42 +0000 2014 19 records at 09:21 August 27th 2014 Removed file.Sync() after each tweet is written to ‘disk’ (buffer I expect) which makes things much quicker. Second run Starts at: Wed Aug 27 10:33:48 +0000 2014 Ends at: Wed Aug 27 13:38:09 +0000 2014 20 records at 14:51 August 27th 2014 DO NOT APPEND

  • 29 Aug 2014
    Search Gear 16 - json Decoder Encoder

    OK OK my test worked locally it seems but not via drone. No idea why - at this point I don’t much care long as they work for me. Now code changes to encode and decode tweets, efficiency be damned - lets just move on. https://dev.twitter.com/docs/working-with-timelines Tweets returned in reverse chronological order - so not optimal for writing to a file. func (tw *twitter) collect(toGet string) (string, error) { var searchResult []anaconda.

  • 28 Aug 2014
    Search Gear 15 - Half Way - Interfaces

    I’m half way through my 30 days of code, it wont all be contiguous but I hope the 30 day sprint will get me much further forward with go. Then it will be back to a day a week of gophering. My third week of gophering suggests that if you don’t know about interfaces then you are screwed. You can get by without them but all the cool kids are using them, and documentation being what it is; BAD I mean, without being able to investigate the package code directly you only hope is to code without reuse.

  • 27 Aug 2014
    Search Gear 14 - Pseudo Constructors!

    Changed the config twitter caller to a pseudo constructor thus func NewTwitter(file string) (*twitter, error) { tw := new(twitter) var parser toml.Parser if _, err := ioutil.ReadFile(file); err != nil { tw.errors = errors.New(co.Lang("could not find the configuration file, you'll need to provide these setting for twitter to work")) } else { toml := parser.ParseFile(file) tw.userKey = toml.GetString("twitter.user-key") tw.userSecret = toml.GetString("twitter.user-secret") tw.apiKey = toml.GetString("twitter.api-key", "26276391-gtihvXIuNXzCD4HTOjx8630O8IPq19m810TxkLMmd") tw.apiSecret = toml.GetString("twitter.api-secret", "bYkulR93l70elsjZysjjDpxQT69RVF2GIUcjoMIkrADoc") tw.users, _ = toml.

  • 26 Aug 2014
    Search Gear 13 - Variable Scoping!

    OK so what next? Need to query ‘my’ twitter timeline every ‘so often’. ‘So often’ is defined by the number of tweets returned from the maximum of 200 as allowed by twitters API. The number of tweets returned defines the period that twitter is queried (not sure if these - every so often - episodes will be this flexible as it may be a cron is required on some server somewhere - maybe just a background process http://stackoverflow.

  • 25 Aug 2014
    Search Gear 12 - Format Files / Code Review Comments!

    So before test format the files in that directory with: go fmt then go test -v go test -cover go test -coverprofile=coverage.out go tool cover -func=coverage.out go tool cover -html=coverage.out NICE! AND I HAVE 100% Coverage and all tests pass! Good read: http://jeffknupp.com/blog/2014/08/19/go-is-fun-familiar-and-fast/ Now thoughts for the next bit of the application - or at least requirements https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline https://github.com/dafang/anaconda/blob/master/timeline.go https://code.google.com/p/go-wiki/wiki/CodeReviewComments go get code.google.com/p/go.tools/cmd/goimports go get code.google.com/p/go.tools/cmd/gofmt Code Review Comments Format Files Go Gofmt Goimports Golang

  • 21 Aug 2014
    Search Gear 11- Testing and Coverage!

    Thanks @rob_pike for sorting me out on cover and style. Rule for today run ‘go fmt’ to get that go code nice and formatted to standard style conventions! https://www.youtube.com/watch?v=ndmB0bj7eyw go-imports tool http://blog.golang.org/laws-of-reflection go test -v go test -cover go test -coverprofile=coverage.out go tool cover -func=cover.out go tool cover -html=coverage.out http://blog.golang.org/cover ~Oh you are joking! Simon-Harpers-iMac:searchgear sharper$ go test -cover cover bitbucket.org/sharpic/searchgear cover: internal error: block 3 overlaps block 4 /Users/sharper/Development/go/src/bitbucket.org/sharpic/searchgear/configure.go:#883,#1345 /Users/sharper/Development/go/src/bitbucket.

  • 19 Aug 2014
    Search Gear 9 - Drone.io and More Testing!

    Search Gear Notes Drone.io come through with an Academic account with free repos’! Nice one Brad @droneio. A-Level results day so no much Go-ing on! But re ran my test code after system restart - just in case it was anything I did in yesterdays session which didn’t continue through to today and SUCESS! Simon-Harpers-iMac:searchgear sharper$ go run searchgear.go (string) (len=25) “piJNV9nZS5dYDxTTc6H” Thank You Gods of Go! So lets rebuild some of the config work I neglected yesterday and the day before while trying to get Go to work again!

  • 18 Aug 2014
    Search Gear 8 - Go doesn't like encfs it seems!

    Search Gear Notes Go, doesn’t like encfs it seems! Something strange is happening - a day trying to run my go code to no avail - go itself seems fine - but something strange is going on with the packages I’ve gone and got. So I think it maybe the cocktail app run on Friday evening http://www.maintain.se/cocktail/ - which is supposed to clean the system - but may have crashed early.

  • 15 Aug 2014
    Search Gear 7 - gocheck, gobyexample, toml-go!

    Search Gear Notes Go, gocheck, gobyexample, toml-go Thanks to @gniemeyer - gustavo @ http://niemeyer.net who pointed me at http://tour.golang.org/ so that I could understand receivers (which is the way go does methods). Stumbled over closures - but put right by @mmcgrana https://gobyexample.com/closures Alright now it’s time to get started - but I think I’ll use the vanilla go testing framework to start with. So initially (see Day 5): I need to

  • 14 Aug 2014
    Search Gear 6 - Spew, Hopwatch, toml-go!

    Search Gear Notes Go, Spew, Hopwatch, toml-go Debugging github.com/davecgh/go-spew github.com/emicklei/hopwatch hopwatch uses go-spew Dump and Dumpf Both are good and seem useful. http://ernestmicklei.com/2012/12/14/hopwatch-a-debugging-tool-for-go/ go-toml-config does not work and the documentation is wrong. Persistently get ‘panic: myconfig.conf is not a valid TOML file. See https://github.com/mojombo/toml' even when it’s the test file from https://github.com/mojombo/toml package main import “github.com/stvp/go-toml-config” var ( title= config.String(“title”, “Unknown”) name = config.String(“owner.name”, “”) git = config.String(“owner.GitHub”, “”) bio = config.

  • 13 Aug 2014
    Search Gear 5 - A Week of Go!

    Search Gear Notes Go, A Week of Go! So this is just a short reflection note. Go seems to be a reasonably good language to learn. I like a number of the features although I think sometimes the running of those programs especially when learning the language leaves a lot to be desired (I’d particularly like there to be a lenient build mode available for us newbies). I think that trying to learn go as well as a different programming paradigms, such as test driven development, also is apt to confuse things; and finally, I think that the documentation and examples provided in some third-party developed packages leaves a lot to be desired.

  • 07 Aug 2014
    Quite Down Twitter!

    Twitter Recently, actually for the past year, I’ve not been following anyone new on twitter. I use twitter as a work information stream, but I’ve been frustrated by the number of tweets unrelated to the work. Now I know that everyone uses twitter in their own way, and I also know some prefer to blend their tweets preferring the more holistic picture this presents. But for me it’s all about work, and Facebook is all about friends.

  • 05 Aug 2014
    Why 'Go'?

    Well ‘go’ is a procedural language and is based on c and c++, in fact it is an attempt to bring c upto date for the 21st century. It keeps the small language footprint of c, updates the OO of c++ and critically introduces 21st century aspects such as concurrency and routine error and test driven tooling. Go is search-able via ‘golang’ and the first small book I’ve read initially confirms it has the features I like.

← All Tags

Simon Harper

Professor of Computer Science, University of Manchester

© 2026 Simon Harper. All rights reserved.

Connect

Built with Hugo