retrace
tool is inside <android-sdk>/tools/proguard/bin
folder.Place the stack traces in a file and run the following command:
|
|
The following HTTP error may happen when adding a private module (repo) to the project even if your SSH keys are properly configured and you have access to the private repo. Private means it’s not a publicly open project on Github/Gitlab/etc.
The reason for that is that the go mod
tool tries to verify the module with its public checksum database, but it cannot find the module listed there (because it’s private).
To skip the check we can declare the repo as private:
Another option is to disable the checksum database verification:
Recently I noticed the adaptive brightness of my phone doesn’t work. Here is the fix:
Open Settings
and click Apps and notifications
Click on the link See all 123 apps
Find an app called Device Health Services
and click it
Open Storage & cache
of the app and click Clear storage
Click on the button Reset adaptive brightness
It seems to work for the moment
To forward requests coming to a local TCP port to another server [host:port] connected via SSH we can use a config file or direct command line arguments. To use a config file, it should be named config
and placed inside the ~/.ssh
folder. Here is a sample ~/.ssh/config
file with some options:
This will forward all requests hitting the local (client) TCP port 7070 to the localhost:8080 on the server and all requests for local TCP port 7171 to the localhost:8181 on the server. The above configuration will be used automatically when initiating an SSH connection by the alias:
|
|
In my humble opinion, modifying an XML node value with the Go standard xml package without describing all tags in data structures is not very intuitive. Hence this post is born. There are many ways to do it with their pros and cons. I’ll describe 2 ways. The first is simpler, but loses some XML elements like comments and possibly formatting. The other is more involved but preserves everything from the initial document, including comments and formatting.
Below is the XML document we’ll use as an example and the node we’ll modify is app>description>version
. We’d like to set the version value from 1.0
to 2.0
. Assume the XML file is called application.xml
|
|
If a program using channels or mutexes is stuck because of synchronization problems, we can send an abort signal to kill the process and print the stack traces of currently running go routines to debug where the program might have hanged. Find the PID of the running program with ps and type:
|
|
The post describes how to unmarshal time.Duration
which is not supported by the default JSON unmarshaler, but the example can be used to unmarshal any custom type.
Here is the JSON we’re unmarshaling:
We’d like to convert the 5s
value to a time.Duration
value corresponding to 5 seconds and get the JSON to unmarshal in the following data structure:
One way to do it is to implement the Unmarshaler interface and handle the conversion in our UnmarshalJSON function.
|
|
Below is the complete example. We unmarshal the JSON into a temprary structure where 5s
is a standard string
. Then we convert the string to time.Duration vaue and set it in our structure.
|
|
counterfeiter is a command-line tool for generating fake implementation of Go interfaces.
One of the best things we can do when writing Go programs is to design our components’ dependencies to be based on local interfaces. By local I mean interfaces which are needed and defined by a given component. Consider the following example: we have a http server, a service component and a database dependency.
|
|
The service component has a database dependency. It may be any kind of external object - client to another service, a cache/database, message queue, whatever. This dependency is expressed as an interface inside the service package. In effect, the service is telling its initialiser: when you create me, please give me an object which implements my service.Storage
interface, cause that’s what I need to execute my functions.
This design has some nice benefits. The service component doesn’t know and care how the storage dependency is implemented. All it knows and cares about is that it has a SomeData() (*storage.Data, error)
function. We can supply whatever object we wish to the service, as long as it implements the interface.
Here comes the counterfeiter
|
|
If we want to use different authentication keys for a particular Git repo, we can edit the config
file of the repo and add the sshCommand
setting.
Navigate to the repository’s Git configuration directory:
|
|
In the folder there’s a file called config
. We are interested in the core
section. To use a particular SSH key for Git, we would write the command as shown below. Replace the name of the key file with your own.