Skip to content

Instantly share code, notes, and snippets.

@pvleite
pvleite / validacaoIE
Created March 9, 2015 12:04
Validação de Inscrição Estadual por estado
{
"RS": {
"estado": "RIO GRANDE DO SUL",
"validacao": "###-#######"
},
"SC": {
"estado": "SANTA CATARINA",
"validacao": "###.###.###"
},
"PR": {
@caarlos0
caarlos0 / elections.rb
Last active June 4, 2016 13:00
My Ruby script to list the top-3 president candidates in Brazilian 2014 elections. Updated with second round data as well. http://carlosbecker.com/posts/elections/
require 'net/http'
require 'uri'
require 'json'
uri = URI('http://divulga.tse.jus.br/2014/divulgacao/oficial/143/dadosdivweb/br/br-0001-e001431-w.js')
class String; def percent_of(n) "#{(self.to_f / n.to_f * 100.0).round(2)}%"; end; end
begin
data = JSON(Net::HTTP.get_response(uri).body)
system('clear')
puts "\n\n----\n#{data['ht']} - #{data['ea'].percent_of(data['e'])} dos votos apurados\n----"
data['cand'].take(3).each do |candidate|
@yashuarc
yashuarc / enable_cors_on_cakephp.php
Last active October 28, 2024 19:32
Enabling CORS on CakePHP
public function beforeFilter() {
parent::beforeFilter();
$this->response->header('Access-Control-Allow-Origin','*');
$this->response->header('Access-Control-Allow-Methods','*');
$this->response->header('Access-Control-Allow-Headers','X-Requested-With');
$this->response->header('Access-Control-Allow-Headers','Content-Type, x-xsrf-token');
$this->response->header('Access-Control-Max-Age','172800');
}