How to make a Toast in top-level AsyncTask class

I have a top-level Fetch class that extends AsyncTask and I have a MainActivity. I can’t get the Fetch class to make a toast due to not having an instance of the MainActivity or its context. I have tried to pass the MainActivity to the Fetch class but it potentially leaks memory. I have tried setting a WeakReference instance of the context, but I can’t make a toast from that.

I have read many other posts about this and most seem to have a static inner-class but mine is top-level and I would prefer to keep it that way.

The MainActivity creates an instance of Fetch and then executes it.

Handle part (book class) with titletoc / xelatex

Referring to this thread: Handle part (book class) with titletoc
, I’ve a new file, this time compiled with xelatex (and no more with pdflatex).

If I use the same code for titletoc, section titles are no more correctly aligned, I mean centered. It’s very evident in the first part title, as you can see in the under pic:

enter image description here

The code:

documentclass[a4paper,11pt]{book}
usepackage{fontspec}
usepackage{polyglossia}
usepackage{titlesec,titletoc}
usepackage{etoolbox}

setmainfont{EB Garamond}
setmainlanguage[babelshorthands=true]{italian}
PolyglossiaSetup{italian}{indentfirst=false}
frenchspacing

makeatletter
patchcmd@part
  {thepart}
  {protectnumberline{thepart}}
  {}{FAIL}
makeatother

makeatletter
contentsmargin[-1.55em]{1.55em}

titlecontents{part}
  [0em]
  {addvspace{1.5pc}filcenter}
  {largepartname~thecontentslabelendgrafbfseries}
  {large}
  {}
  [addvspace{.5pc}]

titlecontents{chapter}
  [4em]
  {vspace*{baselineskip}mdseries}
  {contentslabel[hfillthecontentslabel]{3em}enspace}
  {hspace*{0.5em}}
  {}
  []

titlecontents{section}
  [4em]
  {vspace*{.2baselineskip}mdseriessmall}
  {contentslabel[hfillthecontentslabel]{3em}enspace}
  {}
  {hfillllap{makebox[dimexprlinewidth-1.3pc][l]{makebox[1pc][r]{thecontentspage}}}}
  []

titlecontents*{subsection}
  [4.525em]
  {footnotesize}
  {}
  {}
  {, thecontentspage}
  [~--~]
  []
makeatletter@addtoreset{chapter}{part}makeatother

begin{document}

tableofcontents

part{Title}

chapter{First Chapter}

chapter{Second Chapter}

part{Long Title of the Second Part}

chapter{First Chapter}

chapter{Second Chapter}

part{Very Long Title of the Third Part}

chapter{First Chapter}

chapter{Second Chapter}

end{document}

What could be the cause of the problem? Thanx!

Random Forest: Class specific feature importance

I’m using the bigrf R-package to analyse a dataset with ca. 50.000 observations x 120 variables, classified into two groups.

After growing a forest of 1000 trees, I investigate the importance and relationship of the 120 features in the relation to the 2 classes using, respectively, the fastimp and interactions functions, which produce very nice results.

However, I’m now interested in investigating the problem using 3 (or more) rather than 2 classes. In this case, the Gini variable importance calculated by fastimp only relates to overall importance.

My question is: Is there a way to calculate a class-specific Gini variable importance, or some similar measure?

Add class to UL in menu block if block has class

I have a menu that I am display in a menu block. I am using the Block Class module to add a class to my menu block.

For example: I have a menu called “About Page Menu” that has 3 menu items. I place a the menu block for that menu and add the class “tabs” to that block.

What I would like to do is add a class to the UL element in the menu block if the menu block has a class = tabs.

For example:

# file: block--system-menu-block.html.twig
{% if attributes.hasClass('tabs') %}
  {% set content_attributes = content_attributes.addClass('newClass') %}
{% endif %}

However, the rendering of the UL element is handled in another file: menu.html.twig.

Is there a way to either:

  • set the class of the UL element from block--system-menu-block.html.twig
  • or set the class of the UL element in menu.html.twig by referencing the parent block’s attributes?

This would be fairly simple with jquery:

$('nav.tabs').each(function(){
  $('ul', $this).addclass('newClass');
});

Thanks in advance for your help.

How would you design the abstraction/class(es)/component(s) of a third-party service/api used in your…

Lets say you were designing a Twitter client for people with people could see tweets and post tweets? How would you design the twitter api abstraction? Many of the api wrappers I’ve seen feature an client object that takes as input, the credentials of a user. Something similar to the code below:

twitter = TwitterClient(auth) # maybe (username & password) OR token
twitter.post_tweet(message)

To me, this client is now bound to this user and only operate on this user’s account. If another user logs in, should we create another client object or is there a better way? It seems like the program memory would dramatically increase if every user initiated the instantiation of a program object? Is there a better way to this?

Does casting a spell from an item allow you to apply class abilities that are used when casting a spell?

This question is updated to request additional answers and details in light of information now available in the Dungeon Master’s Guide.

In the released DM basic rules, Lost Mine of Phandelver, Hoard of the Dragon Queen, and the DMG teaser there are wands, staves, and rings that you can use to cast spells.

  1. Do abilities that trigger from casting a spell activate when casting a spell from an item?

  2. Can the character modify the spell using class abilities when
    casting a spell from an item?

Examples include:

  1. An abjurer Wizard’s arcane ward recovering hit points from a Dispel Magic cast from a Ring of Spell Storing

  2. A sorcerer using Twinned Spell on a ray of enfeeblement from a Staff of Power

  3. An evocation wizard using Sculpt Spell on a fireball from a Wand of Fireballs.

Now that the DMG is out we have some clearer rules on casting spells from items (DMG p. 141):

Some magic items allow you to cast a spell from the item. The spell is cast at the lowest possible spell level, doesn’t expend any spell slots, and requires no components, unless the item’s description says otherwise The spell uses its normal casting time, range and duration, and the user of the item must concentrate if the spell requires concentration.

A magic item, such as certain staffs, may require you to use your own spellcasting ability when you cast a spell from the item.

Does whether or not you can apply class abilities to the casting of the spell depend whether the item uses the user’s own spellcasting ability (such as the Staff of Fire) versus an item that comes with a fixed spellcasting ability built-in (such as the Wand of Fireballs)?

Does it matter if it’s something that triggers more or less automatically like Arcane Ward, versus something you have to control, like Careful Spell?