This is a follow-up to this Dart question.
Since Flutter doesn't support reflection and we can't use mirrors, how would you go about debugging, let's say an instance of firebase_database DatabaseReference ?
I'm trying to write tests, and knowing what key/values my reference contains will make it easier for me to write a proper test.
since Dart 3.12 you can use inspect(object) to achieve this
If you expect to have a built-in easy solution, then sorry : You can't.
BUT you can use plugins to serialize your own code, such as built_value. And print the serialized object.
On the other hand, if you want to print external code (DatabaseReference for instance), you'll have to manually transform that object in a combination of Map, List, and int/String/double.
Related
In Solidity, it's possible to use block.number and blockhash(uint blockNumber) returns (bytes32) to obtain the current blockhash from inside a function. I need do the same thing inside a Solana program. I'm using Anchor.
I went through Anchor docs and found a (deprecated) method to get recent blockhashes, but not the current blockhash. I've also tried finding similar projects that might rely on the current blockhash, but I haven't found anything yet.
Is it possible to access the current block hash from inside a Solana program function?
You were looking in the right place -- RecentBlockhashes is on its way out, but you can use the SlotHashes sysvar: https://docs.rs/solana-program/1.10.19/solana_program/slot_hashes/struct.SlotHashes.html
It's tougher to use since you can't deserialize the whole thing into memory on-chain, but you can at least deserialize slices of it.
Is there a way to use dictionary rather than using a yaml config for parameters.yml? I want to keep it as a Python Object because my IDE can then track the dependency easily. For my parameters, I am injecting functions in it.
If i need to use yml, I will have to use
def steps1(x, func1):
func1 = eval(func1)
And this will break the refactoring features easily.
You could overwrite the params property in your src.package_name.run.ProjectContext so that it uses a Python dictionary instead of the config loader. You’re also welcome to write up your custom ConfigLoader and use that instead (by overriding _create_config_loader), but that’s probably more effort.
Please bear in mind that parameters in Kedro are meant to be “as dumb as possible” though, as it’s considered static configuration and it’s better separated out of code. What you describe, with expressions, sounds more suited for nodes.
I'm trying to use the package intl but my brain fails to understand ...
Do you have a simple example of how to use it, when we come from chrome.i18n?
If you just want to localize some messages, I think that l10n would be nice to you. It generates PO files and use it to translate.
Here's a sample - https://github.com/dart-lang/sample-polymer-intl
Top-level explanation:
You write your message initially wrapped in an Intl.message call, which should be in a function that does just that. So, e.g.
hello() => Intl.message("Hello world");
print(hello());
If you run that it will just run without any modification. You can extract out the messages using bin/extract_to_arb.dart, translate them, and run bin/generate_from_arb.dart.
Compared to chrome.i18n:
You write your message in this wrapped-in-a-function-style and the default locale (let's say English) version just runs.
Your program doesn't read the JSON files directly, you run a code generator on them and it generates a library per locale.
You don't use getMessage or anything, it just runs the same way it did before.
To use messages from a particular locale you initialize the locale (which loads the deferred library) and then set it as the default.
It generates and consumes ARB files, and the interpretation of messages is like ICU.
Is that what you were looking for?
I call Ruby functions from my C++ code through the embedding commands (rb_eval and the like). Is there any way to stop the execution of the code partway, save the local variables, and restart it from the same spot later?
If you want to store Ruby variables for use later, you want to use a feature called Marshaling. Create a class in which you can store all variables you wish to save, and use Marshal::dump to store the class into a file. The data can be reconstituted into a Ruby variable again later by using Marshal::load.
Restarting your code from a particular point might not be as easy. You can marshal classes and data but not necessarily the state of the entire Ruby interpreter itself. One possibility is to store enough state information in your marshaled data to let you re-load the data and figure out where you need to pick up.
In response to a previous question on how to achieve a certain effect with Swing, I was directed to JDesktopPane and JInternalFrame. Unfortunately, scala.swing doesn't seem to have any wrapper for either class, so I'm left with extending it.
What do I have to know and do to make minimally usable wrappers for these classes, to be used with and by scala.swing, and what would be the additional steps to make most of them?
Edit:
As suggested by someone, let me explain the effect I intend to achieve. My program controls (personal) lottery bets. So I have a number of different tickets, each of which can have a number of different bets, and varying validities.
The idea is displaying each of these tickets in a separate "space", and the JInternalFrames seems to be just what I want, and letting people create new tickets, load them from files, save them to files, and generally checking or editing the information in each.
Besides that, there needs to be a space to display the lottery results, and I intend to evolve the program to be able to control collective bets -- who contributed with how much, and how any winning should be split. I haven't considered the interface for that yet.
Please note that:
I can't "just use" the Java classes, and still take full advantage of Scala swing features. The answers in the previous question already tell me how to do what I want with the Java classes, and that is not what I'm asking here.
Reading the source code of existing scala.swing classes to learn how to do it is the work I'm trying to avoid with this question.
You might consider Scala's "implicit conversions" mechanism. You could do something like this:
implicit def enrichJInternalFrame(ji : JInternalFrame) =
new RichJInternalFrame(ji)
You now define a class RichJInternalFrame() which takes a JInternalFrame, and has whatever methods you'd like to extend JInternalFrame with, eg:
class RichJInternalFrame(wrapped : JInternalFrame) {
def showThis = {
wrapped.show()
}
}
This creates a new method showThis which just calls show on the JInternalFrame. You could now call this method on a JInternalFrame:
val jif = new JInternalFrame()
println(jif.showThis);
Scala will automatically convert jif into a RichJInternalFrame and let you call this method on it.
You can import all java libraries directly into your scala code.
Try the scala tutorial section: "interaction with Java".
Java in scala
You might be be able to use the scala.swing source as reference e.g. http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk/src/swing/scala/swing/Button.scala
What sort of scala features are you trying to use with it? That might help in coming up with with an answer. I.e. - what is it you're trying to do with it, potentially in Java? Then we can try to come up with a nicer way to do it with Scala and/or create a wrapper for the classes which would make what you're trying to do even easier.
In JRuby, you could mix in one (or more) traits into JDesktopPane or JInternalFrame instead of extending them. This way you wouldn't have to wrap the classes but just use the existing objects. As far as I know, this is not possible with Scala traits.
Luckily, there is a solution, almost as flexible as Ruby's: lexically open classes. This blog article gives an excellent introduction, IMHO.