Get mass assignable attributes for model - ruby-on-rails-3

How can i get mass assignable attributes for model?
I found this, but it seems to me kinda dirty.
Game.accessible_attributes.to_a.reject{|i| i.empty?}
Is there any cleaner way?

I don't understand why the is the reject function.
Did you try this :
Game.accessible_attributes

Related

Dynamically getting TensorFlow type by string?

I'm dynamically casting my tensor into different types based on what the input type string is.
How do I get tf.float64 from a string 'float64'? I tried tf.getattr('float64'), but tf is a module that has no getattr method.
I'm hacking it by creating a lookup for now, but I'm sure there's a cleaner way.
Solved it myself:
tf.dtypes.as_dtype('float32')

Makes using a URI as predicate them to a property?

I have only the following Turtle statement:
x isAuthorOf y
If I have only this statement where isAuthorOf is used as a predicate, means this that I can conclude that isAuthorOf is also a Property without instanciation (isAuthorOf rdf:type rdfs:Property)?
Thanks in advance.
Yes, an IRI used ad a property implies it is a property. However, without declaration you won't know if it's a datatype or an object property.

Type inference failed: RecyclerViewActions.scrollTo()

From java:
onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollTo(
hasDescendant(withText(artistResult.getNameVariations().get(0)))));
Trying to convert to Kotlin:
onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollTo(
hasDescendant(withText(artistResult.nameVariations[0]))))
I get this stacktrace:
Error:(63, 71) Type inference failed: Not enough information to infer parameter VH in fun <VH : RecyclerView.ViewHolder!> scrollTo(itemViewMatcher: Matcher<View!>!): RecyclerViewActions.PositionableRecyclerViewAction!
Please specify it explicitly.
I'm not entirely sure where I can specify "it" explicitly. When this has come up previously it's because I didn't initialise the value correctly, but here I'm calling a method. Any ideas?
I needed to add <RecyclerView.ViewHolder> to scrollTo
onView(withId(R.id.recyclerView)).perform(
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
hasDescendant(withText(artistResult.nameVariations[0]))))
One can get easily confused about which VH among many(specially if multiple VHs in a single RecyclerView) to use, you can simply use Generic ViewHolder i.e RecyclerView.ViewHolder like :
RecyclerViewActions.actionOnItem<RecyclerView.ViewHolder>
RecyclerViewActions.actionOnHolderItem<RecyclerView.ViewHolder>
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>
etc.
I hope this helps.
I´m just going to leave my solution here in case anyone needs it.
onView(withId(androidx.preference.R.id.recycler_view))
.perform(actionOnItem<RecyclerView.ViewHolder>(hasDescendant(withText(R.string.settings_reset_app)), click()).atPosition(1));
do this:
onView(withId(R.id.recycler_view))
.perform(RecyclerViewActions.scrollToPosition(11))

rb-appscript: Accessing parent reference?

Is there an easy way to find the parent element reference of a reference?
For example, suppose I have the following reference:
ref = app("System Events").processes["Safari"].windows[1].buttons[1]
I would like to do something similar to the following:
ref.parent # => app("System Events").processes["Safari"].windows[1].buttons
Or even:
ref.parent # => app("System Events").processes["Safari"].windows[1]
I've looked over the documentation and guides and haven't been successful. I also tried a big no-no by monkey-patching the Appscript::Reference class and adding my own methods but it starts to break my specs in ways that are difficult to troubleshoot. I also thought about using eval but that seemed like a worse idea. Any thoughts?
After a bit of chin scratching, I think I might have a solution:
ref = app("System Events").processes["Safari"].windows[1].buttons[1]
ref.attributes[its.name.eq("AXParent")].value.get
Returns
[app("/System/Library/CoreServices/System Events.app").application_processes["Safari"].windows["rb-appscript: Accessing parent reference? - Stack Overflow"]]
Is that the kind of thing?
Ian

bison: Cant deal with Conflict, which route should i take?

Here is a simple explanation of the problem. Keep in mind this isnt the real problem
Lets say in my language functions cannot return pointers and member vars cannot be references. Bison is complaining (with like 40 reduce/reduce problems) about not deducing if the type in type what is a function or member variable. I know it but its ridiculous to have >40 conflicts from this one line.
Class Name { ...
Type& func() {
Type* Var=0
Type What
How should i deal with this? should i use %glr-parser and set expect/expect-rr to a value? or should i use a Type that has everything and filter what is legal or not in code? It looks like my choices are have more conflicts/ambiguity VS writing more code to deal with it. I am not sure which is worse so i wonder if any of you guys had to deal with this.
You shouldn't try to express type constraints in the grammar. This was proven pretty conclusively by the Algol-68 fiasco documented by Wirth and others.