isValidCpf = (cpf) ->
  if !cpf
    return false
  cpf = cpf.replace(/\D/g,'')
  if cpf.length != 11
    return false
  soma = 0
  resto = 0
  invalidos = [
    "00000000000",
    "11111111111",
    "22222222222",
    "33333333333",
    "44444444444",
    "55555555555",
    "66666666666",
    "77777777777",
    "88888888888",
    "99999999999",
  ]
  if cpf in invalidos
    return false
  for i in [1...10]  by 1
    soma = soma + parseInt(cpf.substring(i-1, i)) * (11 - i)
  resto = (soma * 10) % 11
  if resto == 10 || resto == 11
    resto = 0
  if resto != parseInt(cpf.substring(9, 10))
    return false
  soma = 0
  for i in [1...11]  by 1
    soma = soma + parseInt(cpf.substring(i-1, i)) * (12 - i);
  resto = (soma * 10) % 11
  if resto == 10 || resto == 11
    resto = 0
  if resto != parseInt(cpf.substring(10, 11))
    return false
  return true