A 45-year-old homeless man who stabbed his grandmother to death while stealing money for his cocaine habit will spend 23 years to life in state prison.