Skip to content

Instantly share code, notes, and snippets.

View romuloceccon's full-sized avatar

Rômulo Ceccon romuloceccon

  • Frankfurt am Main, Deutschland
View GitHub Profile
@romuloceccon
romuloceccon / get_resultados_brim.rb
Created April 13, 2011 13:17
Gera um YAML com os resultados do Ironman Brasil (2008, 2009 e 2010)
require 'net/http'
require 'nokogiri'
$eventos = { '2008' => '159', '2009' => '280', '2010' => '396' }
unless $eventos.keys.include?(ARGV[0])
STDERR.puts "Uso: #{$0} <#{$eventos.keys.sort.join('|')}>"
exit(2)
end
@romuloceccon
romuloceccon / yaml_to_html.rb
Created April 13, 2011 16:24
Converts a yaml to an html table
require 'yaml'
yaml = YAML.load(STDIN.read)
columns = yaml.values.first.keys.sort
puts "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
puts "<html lang=\"en-US\" xml:lang=\"en-US\" xmlns=\"http://www.w3.org/1999/xhtml\">"
puts " <head>"
puts " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"
# coding: utf-8
require 'rubygems'
require 'prawn'
require 'benchmark'
class Danfe
# Largura mínima da barra deve ser de 6 cm / 297 = 0,02 cm = 0,57 pt. A largura que usaremos
# será 0,70 pt = 0,025 cm = 7,33 cm / 297.
@romuloceccon
romuloceccon / rotate_prawn.rb
Created July 20, 2011 23:07
Rotation example with prawn
require 'rubygems'
require 'prawn'
$pdf = Prawn::Document.new(:page_size => 'A4')
$pdf.line_width = 0.3
def test_box(origin, angle)
$pdf.translate(*origin) do
$pdf.rotate(angle, :origin => [0, 0]) do
$pdf.stroke do
@romuloceccon
romuloceccon / ldiriterator.c
Created August 28, 2011 19:42
oo lua binding example
#define LUA_LIB
#include <windows.h>
#include "lua.h"
#include "lauxlib.h"
#include "ldiriterator.h"
typedef struct DirectoryIterator
{
HANDLE handle;
@romuloceccon
romuloceccon / maps.html
Created October 18, 2012 20:26
Google Maps Api lesson
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
module Astar
def sort_walking_neighbors(origin, routes)
result = []
routes.each_with_index do |r, i|
result += r.map do |p|
[i, p]
end
end
require 'net/http'
require 'uri'
require 'nokogiri'
require 'iconv'
require 'yaml'
uri = URI("http://urbs-web.curitiba.pr.gov.br/centro/conteudo_lista_linhas.asp?l='n'")
response = Net::HTTP.start(uri.host, uri.port) do |http|
http.get(uri.request_uri).body
@romuloceccon
romuloceccon / intersect.rb
Created October 25, 2012 21:43
Google maps javascript api path editor
x1, y1 = 1.0, 2.2
x2, y2 = 5.0, 3.3
x3, y3 = -10.0, -100.0
dx12 = x1 - x2
dy12 = y1 - y2
den = dx12 ** 2 + dy12 ** 2
x4 = (x3 * dx12 ** 2 - dy12 * (x1 * (y2 - y3) - x2 * (y1 - y3))) / den
y4 = (y3 * dy12 ** 2 - dx12 * (y1 * (x2 - x3) - y2 * (x1 - x3))) / den
@romuloceccon
romuloceccon / vector.rb
Created November 6, 2012 23:47
Finds the intersection point on a sphere between the line (x1,y1),(x2,y2) and the perpendicular line passing through (x3,y3), and compares the result with an approximated approach considering the sphere as an euclidean space
def rad(a)
a * Math::PI / 180.0
end
def deg(a)
a * 180.0 / Math::PI
end
class Vector