Skip to content

Instantly share code, notes, and snippets.

@christophberger
christophberger / functionaloptions.go
Created October 15, 2014 21:15
Functional Options in Go
// Functional Options
// Written to help me wrapping my brains around Functional Options - see this
// blog post about a speech by Dave Cheney:
// http://dotgo.sourcegraph.com/post/99643162983/dave-cheney-functional-options
//
// The idea behind Functional Options:
// How to add options to an API later without breaking the API?
// Solution:
package main
@christophberger
christophberger / windisablesnaptodefaultbutton.go
Created February 5, 2015 21:40
Disable Snap To Default Button behavior in Windows (Go source)
/*A command-line tool for setting the mouse speed on Windows machines.
This comes in handy when using different mouses (e.g. at work and at home)
that require different speed settings.
Dependencies: sys package (go get golang.org/x/sys/...)
License:
Copyright (c) 2015, Christoph Berger <[email protected]>
@christophberger
christophberger / winsetmousespeed.go
Created February 5, 2015 21:47
Switch Mouse Speed in Windows 7 (Go source)
/*A command-line tool for setting the mouse speed on Windows machines.
This comes in handy when using different mouses (e.g. at work and at home)
that require different speed settings.
Dependencies: sys package (go get golang.org/x/sys/...)
License:
Copyright (c) 2015, Christoph Berger <[email protected]>
@christophberger
christophberger / GoAndWait.md
Last active August 29, 2015 14:18
GoAndWait (go generate test, using reusee/ccg)

GoAndWait

  • Tests code generation using ccg (reusee/ccg).
  • Encapsulates a concurrency pattern.

GoAndWait wraps a common concurrency pattern into a generic function:

  • The items of a list shall be processed concurrently
  • The main routine must wait until all items have been processed
@christophberger
christophberger / typecast.go
Last active April 25, 2016 08:37
Approach to accessing struct-specific attributes through an interface using typecast in Go
package main
import "fmt"
// The interface.
type interf interface {
Method(string) string
}
// A struct.

Keybase proof

I hereby claim:

  • I am christophberger on github.
  • I am christophberger (https://keybase.io/christophberger) on keybase.
  • I have a public key ASC8b-gcdQzzyAjieAUZNehGbw2z1Fd2V2xp8SduLfHYxAo

To claim this, I am signing this object:

@christophberger
christophberger / container.go
Created October 30, 2016 15:41
A container in less than 60 lines of Go
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func main() {
@christophberger
christophberger / tui_code_1_start.go
Last active April 4, 2017 09:30
Code from github.com/appliedgo/tui
package main
// Under normal circumstances, importing two UI libraries at the
// same time is probably not a good idea, as each has its own event
// loop. This demo code takes care of using only one of these
// libraries at a time.
import (
"fmt"
"log"
"os"
@christophberger
christophberger / tui1start.go
Last active April 4, 2017 09:38
Code snippet from github.com/appliedgo/tui: start
package main
// Under normal circumstances, importing two UI libraries at the
// same time is probably not a good idea, as each has its own event
// loop. This demo code takes care of using only one of these
// libraries at a time.
import (
"fmt"
"log"
"os"
@christophberger
christophberger / tui2termui.go
Last active April 4, 2017 09:39
Code snippet from github.com/appliedgo/tui: termui
func runTermui() {
// Initialize termui.
err := t.Init()
if err != nil {
log.Fatalln("Cannot initialize termui")
}
// `termui` needs some cleanup when terminating.
defer t.Close()
// Get the height of the terminal.