Skip to content

Instantly share code, notes, and snippets.

View l-vitaly's full-sized avatar
🏠
Working from home

Vitaly Lobchuk l-vitaly

🏠
Working from home
View GitHub Profile
@l-vitaly
l-vitaly / example1
Last active February 26, 2017 11:11
type TemperamentЕype int
const (
TypicalSanguinePerson TemperamentЕype = iota // 0
  TypicalCholericSubject // 1
  TypicalPhlegmaticPerson // 2
  TypicalMelancholiac // 3
)
func FormatMyValue(i int) string {
return fmt.Sprintf(“there are %d my value”, i)
}
func main() {
n := TypicalPhlegmaticPerson
fmt.Println(FormatMyValue(n))
}
// output:
type CarType int
const (
BMW CarType = iota // 0
  Audi // 1
Mercedes // 2
  _
  _
  XRay // 5
)
type Permissions int
const (
  Read Permissions = 1 << iota // 1 << 0 = 00000001
  Write // 1 << 1 = 00000010
  Create // 1 << 2 = 00000100
 Delete // 1 << 3 = 00001000
)
fmt.Println(Write | Delete | Read)
// output:
// 11
type ByteSize float64
const (
  _ = iota // ignore first value by assigning to blank identifier
  KB ByteSize = 1 << (10 * iota) // 1 << (10*1)
  MB // 1 << (10*2)
  GB // 1 << (10*3)
  TB // 1 << (10*4)
  PB // 1 << (10*5)
  EB // 1 << (10*6)
const (
  Russia, USA = iota + 1, iota + 2
  Ukraine, Italy
  China, Spain
)
// Russia: 1
// USA: 2
// Ukraine: 2
// Italy: 3
func UCFirst(s string) string {
return strings.ToUpper(s[:1]) + s[1:]
}
func LCFirst(s string) string {
return strings.ToLower(s[:1]) + s[1:]
}
@l-vitaly
l-vitaly / gist:05aa3cb2b33b50f83329427d84a8e58b
Created May 15, 2017 18:01
Remove unused docker images and containers
docker rm -v $(docker ps --filter status=exited -q 2>/dev/null) 2>/dev/null
docker rmi $(docker images --filter dangling=true -q 2>/dev/null) 2>/dev/null
func sortMap(m map[string]string) []string {
list := make(sort.StringSlice, len(m))
i := 0
for name := range m {
list[i] = name
i++
}
list.Sort()
result := make([]string, len(list))
for i, name := range list {