Skip to content

Instantly share code, notes, and snippets.

# -*- coding: UTF-8 -*-
import sys
import socket
import sys
import socket
import time
def stringToDict(data):
arr = data.split('\r\n')
dick = {}
@heppu
heppu / arch_gpu_passthrough.MD
Last active October 8, 2021 20:46
Arch GPU passthrough

Install rpmextract

sudo pacman -Suy rpmextract

Get lates edk2.git-ovmf-x64

wget https://www.kraxel.org/repos/jenkins/edk2/edk2.git-ovmf-x64-XXXXXX.noarch.rpm
@heppu
heppu / arch_virtualization.MD
Created March 11, 2016 07:33
Arch virtualization and CoreOS

Arch virtualization

Check virtualization support

lscpu

Check KVM modules

zgrep CONFIG_KVM /proc/config.gz
@heppu
heppu / limitter.go
Last active December 9, 2016 08:21
Limit parallel goroutines with buffered channel.
package main
import (
"log"
"sync"
"time"
)
const Limit = 5
@heppu
heppu / ARCH_INSTALL.MD
Last active August 22, 2024 16:25
Installing Arch with GPT, dm-crypt, LUKS, LVM and systemd-boot

Create bootable USB

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

Boot from USB and set prepare system

loadkeys <your-keymap>
@heppu
heppu / main.go
Last active June 28, 2017 10:08
Go http client file descriptor leak
/*
File that demostrates file descriptor leak
in case the client forgets to close response body
*/
package main
import (
"fmt"
"io/ioutil"
type Storage interface {
Add(key, val string)
}
type SafeStorage struct {
storageMu *sync.Mutex
storage Storage
}
func NewSafeStorage(storage Storage) *SafeStorage {
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)
}
@heppu
heppu / original.go
Last active January 26, 2019 11:16
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)
}
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