Is Tanjiro using the fire god's breath dance and Nezuko using his ability a deus ex machine? Does it have foreshadow? In chapter 19 against Rui the dance and the sanguine explosion take place, do they have a past reference? or is he a deus ex author's error? I need your help
It could be considered a Deus ex machina. To quote from its definition:

...a plot device whereby a seemingly unsolvable problem in a story is suddenly and abruptly resolved by an unexpected and unlikely occurrence.

The 'unsolvable problem' here would be the fight between Rui and Tanjiro since the latter was on the verge of losing to the former's seemingly overwhelming strength. Tanjiro then discovers a new skill using a different breathing technique and while it may not have 'abruptly resolved' the problem, it was 'unexpected and unlikely' since he was only shown to use Water breathing techniques and it was enough to buy time for reinforcements to arrive, as seen in Episode 20.
But was this an error? I don't think so. This event was meant as the beginning to unraveling of Tanjiro's past. Personally, I think it was a good way since it makes you curious about the background of Tanjiro's family, whether they were really just a family who makes charcoal or was there something more since his father seems to know breathing techniques. Was there foreshadowing before this? None. Rather, this is the foreshadowing to something later on in the storyline. All the unanswered questions from this part will eventually be answered later on as the story progresses. You can read the manga or wait for the anime to adapt everything.