Skip to content

Instantly share code, notes, and snippets.

Henri Koski heppu

Block or report user

Report or block heppu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View refactored_exception.go
type FailingStorage struct{}
func (f *FailingStorage) Add(k, v string) {
throw exception.New("now we fail")
}
var s = NewSafeStorage(&FailingStorage{})
func handleAdd(w http.ResponseWriter, r *http.Request) {
key := r.Host
value := r.Method
View refactored_err_failing.go
type FailingStorage struct{}
func (f *FailingStorage) Add(k, v string) (err error) {
return errors.New("now we fail")
}
var s = NewSafeStorage(&FailingStorage{})
View refactored_err.go
type FailingStorage struct{}
func (f *FailingStorage) Add(k, v string) (err error) {
return errors.New("now we fail")
}
var s = NewSafeStorage(&FailingStorage{})
func handleAdd(w http.ResponseWriter, r *http.Request) {
key := r.Host
value := r.Method
View original.go
type storage struct{}
func (s *storage) Add(k, v string) {}
var s = NewSafeStorage(&storage{})
func handleAdd(w http.ResponseWriter, r *http.Request) {
key := r.Host
value := r.Method
s.Add(key, value)
}
View safe_storage_changes.go
type Storage interface {
Add(key, val string) error
}
func (s *SafeStorage) Add(key, val string) error {
s.storageMu.Lock()
defer s.storageMu.Unlock()
return s.storage.Add(key, val)
}
View safe_storage.go
type Storage interface {
Add(key, val string)
}
type SafeStorage struct {
storageMu *sync.Mutex
storage Storage
}
func NewSafeStorage(storage Storage) *SafeStorage {
@heppu
heppu / main.go
Last active Jun 28, 2017
Go http client file descriptor leak
View main.go
/*
File that demostrates file descriptor leak
in case the client forgets to close response body
*/
package main
import (
"fmt"
"io/ioutil"
@heppu
heppu / ARCH_INSTALL.MD
Last active Sep 25, 2019
Installing Arch with GPT, dm-crypt, LUKS, LVM and systemd-boot
View ARCH_INSTALL.MD

Create bootable USB

dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx status=progress && sync

Boot from USB and set prepare system

loadkeys <your-keymap>
@heppu
heppu / limitter.go
Last active Dec 9, 2016
Limit parallel goroutines with buffered channel.
View limitter.go
package main
import (
"log"
"sync"
"time"
)
const Limit = 5
@heppu
heppu / arch_virtualization.MD
Created Mar 11, 2016
Arch virtualization and CoreOS
View arch_virtualization.MD

Arch virtualization

Check virtualization support

lscpu

Check KVM modules

zgrep CONFIG_KVM /proc/config.gz
You can’t perform that action at this time.