A city, county or city and county may appropriate funds and may do all acts necessary to assume and carry out or continue any program, or part thereof, which is operated by any other public agency, private person or corporation and whereby federal funds have been granted to such public agency, private person or corporation for purposes of health, education, welfare, public safety, law enforcement activities which have not been preempted by state law, prevention or reduction of crime, rehabilitation of persons convicted of crime or juvenile offenders, or public works or community improvements, where the federal funds for such programs are to be terminated or substantially
reduced by the federal government; provided however, that no such program shall be operated pursuant to this section for a period exceeding two years. A city, county or city and county may perform any act or service authorized by this section by means of a contract with an independent contractor. The independent contractor may be a public agency, private person or corporation.
The board of supervisors or city council may appropriate funds for such programs and may do all acts necessary to continue the program in action.