четвъртък, септември 20, 2018

Enable SHIFT+Numpad keys for navigation on Ubuntu 18.04

setxkbmap -option 'numpad:microsoft'

Another often helpful shortcut Ctrl+Alt+Arrow to navigate in source files after peeking into a function and going back to the previous.

On Ubuntu 18.04 by default these shortcuts are taken by the system. To free them up for use by editors, use the following:

gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left "[]"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right "[]"

четвъртък, септември 13, 2018

Safe way to cleanup Ubuntu boot partition


First check your kernel version, so you won't delete the in-use kernel image, running:
uname -r
Now run this command for a list of installed kernels:
dpkg --list 'linux-image*' | grep ^ii
and delete the kernels you don't want/need anymore by running this:
sudo apt-get remove linux-image-VERSION
Replace VERSION with the version of the kernel you want to remove.
When you're done removing the older kernels, you can run this to remove ever packages you won't need anymore:
sudo apt-get autoremove
And finally you can run this to update grub kernel list:
sudo update-grub



This is a direct copied response from askubuntu.com for preservation purposes, as things on the internet often disappear unexpectedly (and forever).

понеделник, юли 09, 2018

Custom type holding string OR int implementing the Marshaller interfaces for automatic marshal/unmarshal by the standard JSON library

package main

import (
 "encoding/json"
 "fmt"
 "log"
 "strconv"
)

type stringOrInt struct {
 Int    int
 String string
}

func (s *stringOrInt) MarshalJSON() ([]byte, error) {
 if s.Int != 0 {
  return []byte(strconv.Itoa(s.Int)), nil
 }
 if s.String != "" {
  return []byte(fmt.Sprintf(`"%s"`, s.String)), nil
 }

 return nil, nil
}

func (s *stringOrInt) UnmarshalJSON(data []byte) error {
 if len(data) == 0 {
  return nil
 }

 if data[0] == '"' {
  s.String = string(data[1 : len(data)-1])
  return nil
 }

 i64, err := strconv.ParseInt(string(data), 10, 64)
 if err != nil {
  return err
 }
 s.Int = int(i64)
 return nil
}

type envelope struct {
 ResourceOwnerID *stringOrInt `json:"resource_owner_id,omitempty"`
}

func main() {
 e1 := envelope{&stringOrInt{Int: 42}}
 e2 := envelope{&stringOrInt{String: "4-4-2"}}
 e3 := envelope{&stringOrInt{}}

 j1 := toJSON(e1)
 fmt.Println(j1)
 var e4 envelope
 err := json.Unmarshal([]byte(j1), &e4)
 if err != nil {
  log.Fatal(err)
 }
 fmt.Printf("Unmarshal: %+v\n", e4.ResourceOwnerID)

 j2 := toJSON(e2)
 fmt.Println(j2)
 var e5 envelope
 err = json.Unmarshal([]byte(j2), &e5)
 if err != nil {
  log.Fatal(err)
 }
 fmt.Printf("Unmarshal: %+v\n", e5.ResourceOwnerID)

 fmt.Println(toJSON(e3))
}

func toJSON(v interface{}) string {
 d, _ := json.Marshal(v)
 return string(d)
}

сряда, юли 04, 2018

NPM/Yarn error when building docker image from nodejs project (Ubuntu Linux 16.04)

The following error may happen on Linux when building the docker images for nodejs projects with scoped private repositories.

An unexpected error occurred: Request failed \"404 Not Found\""


One way to fix it follows:

Step 1 

Edit /etc/resolv.conf and change the DNS server to one that can be seen from docker containers:

nameserver 10.0.0.1
search npm-private-repo-domain.com

Step 2

sudo service systemd-resolved stop

сряда, декември 13, 2017

Cleanup disk space consumed by Docker

See the space used by Docker images, containers and volumes:
docker system df

Cleanup space used by containers:
docker system prune

Cleanup space used by volumes
docker volume prune
Total clean with force flag:
docker system prune -af

неделя, юли 16, 2017

Debug trace files location on Nexus 5X with Android 7+

After some cursing, because nowhere in Google I could find where these trace files are stored, I finally found them. The location is not mentioned and not even hinted in the 'trace use' documentation.
/sdcard/Android/data/com.company.mygame/files/filename.trace
If we use the os.Debug class to generate trace files and our app package is com.company.mygame:
Debug.startMethodTracing("mytracefile");
Debug.stopMethodTracing();
The file can be found and pulled like:
adb pull /sdcard/Android/data/com.company.mygame/files/mytracefile.trace
ALSO, USING traceview FROM THE COMMAND LINE HAS BEEN DEPRECATED!