Personal favorites
I used to wander around a dangerous area of the city smoking rock (only one several month binge period in my life), but I've been homeless a few times as well, for a few weeks each time. Long enough to learn a LOT. Precautions? Some may sound silly at first, but listen up...
(1) Don't wear eyeglass. Wear contacts! Particularly if you're white. You WILL be looked at as a weak nerd or geek by street-tough people, who have always been idiotic enough to hold this outlook.
(2) Carry a knife in self defense, as well as for self-confidence. Not a gun, a knife. With legal length blade in your area. Make sure it's a good one that could withstand being thrust into a person's chest, because: You will only EVER pull it out if you're prepared to use it. If you pull it but aren't prepared to use it, somebody else will force you to. And make damn sure the other person doesn't have a gun, LOL.
(3) KNOW your streets. If you do not, walk with confidence anyway, as if you casually strolled down the most dangerous streets at 3AM. "Act as if" and people will believe you.
(4) Never, never, never do anything stupid if you get ripped off. For example, threaten to call the cops. Either take it with grace and walk away, or punch the offending dealer in the face... your call. Don't threaten, ever.
(5) If possible, go with a buddy who knows the area. If you're white, preferably a non-white buddy. Sorry, no prejudice intended, but on the mean streets white people are sometimes the minority.
(6) Wear a cheap watch, cheap clothes, cheap shoes (except maybe leather jacket if you like to show off, but prepare for someone to try & steal it). Look "Po" and nobody will jump you.
(7) If you want to buy H, be prepared to show track marks or have an EXTREMELY good excuse for the dealer. If you want to buy crack, carbon smudge your hands so they're filthy, including under fingernails and stuff.
( 8 ) If you get stuck somewhere w/no transportation home, find an all night deli, coffee shop, library, or just a motel with guard standing outside & chat with the fellow until it gets light. Try not to walk totally empty streets in bad areas alone at 2:30AM, LOL... but if you must, see #3.
(9) If you are threatened (in a showoffy way, not jumped), chances are you're being bluffed... it's like one of those rituals monkeys perform to establish dominance. One time someone did this to me, and I pulled out my knife (only time I ever broke rule #2), picked my teeth with it for a few minutes, then put it away. The fellow apologized profusely for insulting me! LOL!
Cheers...