On 11th December 2024, Bulgarian weightlifter Karlos Nasar achieved something extraordinary again by setting two new World Records in the 89kg category: a 183kg Snatch and 405kg Total.
It was amazing!
On 11th December 2024, Bulgarian weightlifter Karlos Nasar achieved something extraordinary again by setting two new World Records in the 89kg category: a 183kg Snatch and 405kg Total.
It was amazing!
Sometimes Android wireless pairing from Device Manager UI does not work. This may happen because of WIFI network settings, which are not under our control (i.e. co-working space, cafe, hotel).
A fix that may work is using the adb
CLI commands for manual pairing.
Go to phone Settings->Developer Options->Wireless Debugging
and
click Pair device with pairing code
.
A dialog shows Pair Code plus device IP address and port.
Note that IP:PORT in this dialog is different from your local device IP:PORT reported on the previous screen. We’ll use the other one later. For pairing we use must use this one in the Dialog window.
|
|
Enter Pairing Code displayed on your phone screen. Pairing should succeed.
Now connect to the device by using the other port number displayed before the Pairing dialog popup.
|
|
Now phone should be paired successfully with the dev computer.
Install or download yt-dlp
Open terminal.
|
|
Audio quality is number from 0 (best) to 10 (worst).
|
|
Works for Facebook videos too with URL like: https://www.facebook.com/watch/?v=280191971840839
Recently I’ve been working on a small Go library.
I wrote unit tests to cover most of the major functionality.
I got code coverage 33%
And I became suspicious.
Because go test -race -coverprofile=coverage.out ./...
includes all
auto-generated Fake objects used by unit tests in the calculation.
Depending on how many and how large the fake objects are, real code
coverage is reduced by that much. After removing fakes from the calculation,
code coverage was raised to 62%!
This will include all Fake objects code and will reduce the real code coverage of our tests.
If we want to use go tool cover
and our fake files start with
the prefix fake_
(i.e. counterfeiter):
If you made the same mistake, you must know that your code coverage is much higher than you, and everybody else think it is :)
Cheers!
I recently learned an interesting feature in the Goa framework, which we use for some of our services. How can we return a ZIP file which is created by a service function implementation, but also include additional custom headers in the response?
Big thanks to one of the Goa creators/contributors Raphael Simon, who helped me with this issue very quickly in the Goa Slack channel!
Goa provides default response encoders for JSON, XML, GOB and plain text/bytes. In my case the plain bytes response was almost enough, but I wanted to have additional response headers returned to the client.
As I wanted to have Content-Type: application/zip
header, I wrote a small encoder
using the default TextEncoder as example and everything worked fine.
I wanted to have one additional response header specifying the name of the ZIP file
which was dependent on some internal resource characteristics. More specific, I wanted
to include a response header Content-Disposition: attachment; filename="myfile.zip"
where myfile.zip
could be different with every request.
The simple text/bytes encoder cannot do this, because there’s no way I can give it more
specific values from the Service implementation - I can only return []byte
slice as
response.
With Goa, if you need to return more specific headers, you have to define them in a Goa DSL response type.
|
|
Now my small custom bytes encoder receives this object, but the body is wrapped in a generated wrapper
object which I must cast to the specific ExportZipResult
type in order to get the body bytes.
It didn’t seem natural as it means that this bytes encoder will only be usable for that specific
function and won’t be useful for other similar functions. That’s when I decided to write in the Slack
channel and to my surprise the creator of Goa responded within a few hours.
It turned out that Goa provides a custom DSL function which instructs the code generation process
to skip the creation of any response encoder for that function. Instead, you must implement a function
which returns an object containing all header values which you’d like to return,
plus an io.ReadCloser
for the bytes that you want to return to the client.
|
|
Now there is no need for writing any custom Encoder and the function that implements the creation of the ZIP archive looks like this.
|
|
And it works like charm! :)
Imagine you have a struct with some fields which are always there,
but you also have some fields which are dynamically populated with
different [key, value]
pairs, which cannot be described with static
types upfront.
The attributes
field is map and may contain an arbitrary number of values for each record.
This is the field that I want to store in JSON column. The other fields are stored in
statically defined columns with their respective types.
BigQuery infer schema does not work with maps. So doing something like this won’t work.
|
|
Even if you make the Attributes
field type json.RawMessage
it won’t work again.
Manually create the schema and try again.
|
|
This won’t work (with the Golang client) as BigQuery won’t convert the map
to JSON. If we change the field type to json.RawMessage
it won’t work again.
We make the Order
type implement the bigquery.ValueSaver
interface and serialize the attributes
field as JSON string.
|
|
Ebitengine is a Go game development engine. Games can be built for Linux, MacOS, Windows, Android, iOS and Nintendo Switch.
I did some basic experiments during a few vacation days. This post is about something which wasn’t obvious to me how to implement and took me some hours to figure out. Hopefully it may spare you some time.
Under the hood Ebitengine uses gomobile to create bindings for languages like Java and C/C++.
This article is especially interesting if you need to call Go functions from Java or C/C++ and vice-versa.
I make a Go game which runs on Android, but I’d like to show Ads using 3rd party
SDK like Unity or Facebook Audience Network. This means I’ll have to integrate
a Java or ObjC library in the native app. For example, on Android it could be
implemented in the showAds
method below:
|
|
The problem is that MainActivity
doesn’t know when to call show ads, as it doesn’t know anything
about the internal state of the game - game updates and state changes happen in the Go code.
So, at any point in time, only the Go side knows if it’s time to show an advert. Now the problem
comes down to how the Go code can call the showAds()
Java method?
My current solution is presented below and it works. I don’t feel it optimal since it requires to keep a global variable reference to the game object, but for now I haven’t found an improvement (and I don’t know if it’s an issue at all).
It shows how to call Go functions from Java as well as Java functions from Go.
It looks like neither Hyperledger Aries Go framework, nor the Google Tink crypto library, which it uses under the hood, provide helper functions to convert public key bytes to JWK format (or I haven’t found the way). When you export public key bytes from the KSM, they are unmarshalled from their internal representation and serialized using x509.MarshalPKIXPublicKey()
, elliptic.Marshal()
, and some are marshalled as JSON using json.Marshal()
to custom Aries PublicKey struct. This means that we can’t use standard Go JOSE libraries to convert these public keys to JWK directly.
This post shows how to make two kinds of keys to JWK, but I’ll try to explain the process I followed to discover them, so if you need to export other public key types, you’ll probably know where to look.
One of the key types - NISTP256ECDHKWType - is mandatory in the current implementation of Hyperledger Aries Go if you want to use authenticated encryption (authcrypt) of DIDComm messages and follow the DIDComm V2 spec.
Why would you want to convert Aries public keys to JWK?
To use them as verification methods in DID documents. It is a common and widely supported encoding of public keys in DID documents (
publicKeyJwk
)
Below are example functions to convert ECDSA and ECDSA-ECDH-KW keys:
|
|
By looking at the public key serialization process for your needed key type.
Keys are created by different KeyManager implementations.
Public keys are serialized in the pubkey_writer.go file. Best to checkout the Hyperledger Aries Go github repo and dive into this file and follow the different serialization functions for the key types you need.
We’ve been using go-watcher for
local development with docker-compose to automatically rebuild a given service
when its source code changes. From Go 1.20+ onwards the go-watcher
binary no
longer works, because it’s using a build flag -i
which has been deprecated
for a long time, but now is finally removed. Because of that the compilation
fails with error. See it here.
The project is no longer maintained, and it seems that the authors are not going to update it.
Now I’m using a replacement called guard. Usage is almost identical as you can see in the examples below.
Note: we commit vendor, that’s why we build/install with
-mod=vendor
Example Dockerfile using go-watcher
to watch and rebuild a service.
|
|
Example Dockerfile using guard
to watch and rebuild a service.