Skip to content

Instantly share code, notes, and snippets.

@dodecaphonic
dodecaphonic / Gemfile
Created April 2, 2014 13:26
Exploring QuickCheck in Ruby via Rantly
source "https://rubygems.org"
gem "minitest"
gem "rantly", github: "hayeah/rantly"
require "rgeo"
WGS84 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
WGS84_UTM = "+proj=utm +zone=22 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
x0, y0 = -48.10311146131618, -15.894902327065926
x1, y1 = -48.103022948419394, -15.894858472899413
mercator = RGeo::Geographic.simple_mercator_factory
geographic = RGeo::Geographic.projected_factory(projection_proj4: WGS84)
@dodecaphonic
dodecaphonic / gist:946254
Created April 28, 2011 12:29
Function set sequences to max in Postgres (instead of writing the same piece of code in ruby again and again)
Taken from http://stackoverflow.com/questions/244243/how-to-reset-postgres-primary-key-sequence-when-it-falls-out-of-sync.
--drop function IF EXISTS reset_sequence (text,text) RESTRICT;
CREATE OR REPLACE FUNCTION "reset_sequence" (tablename text,columnname text) RETURNS bigint --"pg_catalog"."void"
AS
$body$
DECLARE seqname character varying;
c integer;
BEGIN
select tablename || '_' || columnname || '_seq' into seqname;
@dodecaphonic
dodecaphonic / gist:1092282
Created July 19, 2011 13:18
Como fica o fetchImage
it ("should set an image source into a tile", function() {
spyOn(tileProvider, 'fetchImage').andCallFake(function(tile) {
tile.image.src = 'http://localhost/fakeImage.jpg';
});
tileProvider.loadTile(tile);
waitsFor(function() {
return tile.state == ProjectViewer.Tile.State.ERROR;
}, 2000);
@dodecaphonic
dodecaphonic / gist:2988116
Created June 25, 2012 11:40
Setup pós instalação
#!/bin/sh
# Based off of Dropbox, copies all necessary files to their right places and
# puts machine up to speed in no time. To add the cherry on top, it clones
# my emacs config from github and lets me finally do work.
#
# Vitor Peres <dodecaphonic@gmail.com>
CONFIG_ROOT=$HOME/Dropbox/dotfiles
PLATFORM=$(uname)
@dodecaphonic
dodecaphonic / gist:3516110
Created August 29, 2012 17:45
ruby-mode-hook com Electric
(add-hook 'ruby-mode-hook
(lambda()
(add-hook 'local-write-file-hooks
'(lambda()
(save-excursion
(untabify (point-min) (point-max))
(delete-trailing-whitespace))))
(set (make-local-variable 'indent-tabs-mode) 'nil)
(set (make-local-variable 'tab-width) 2)
(imenu-add-to-menubar "IMENU")
@dodecaphonic
dodecaphonic / proposta.md
Created October 17, 2012 14:48
Teste de Desenvolvimento para Candidatos da PRODEC

Proposta

Você deverá criar um pequeno sistema georreferenciado para visualização e cadastramento de ocorrências policiais. Estas deverão ser categorizadas conforme indicação abaixo e receberão iconografia que permita ao Usuário distinguir visualmente sua natureza.

Interface Principal

A visão inicial do sistema oferecerá dois painéis: à direita, um mapa da cidade do Rio de Janeiro em nível de zoom que abranja todo o município; à esquerda, à guisa de sidebar, uma lista de ocorrências pertinentes à área de visualização atual.

À medida que o Usuário navegar pela interface de mapa, a lista à esquerda será atualizada para conter apenas as ocorrências na nova área de visualização (isto é, se mais próximo da escala mínima, um número menor de ocorrências surgirá; se mais afastado, maior.) Estas deverão ser ordenadas por sua data e hora de registro.

@dodecaphonic
dodecaphonic / gist:4026343
Created November 6, 2012 17:55
RGeo, calc zone
def self.calculate_offset(point, normal, distance)
utm = utm_factory.point(point.x, point.y).projection
lon, lat = RGeo::CoordSys::Proj4.transform_coords(proj4_utm, proj4_geo,
utm.x + distance * normal.x,
utm.y + distance * normal.y)
new_pos = factory.point(lon, lat)
(point - Vertex.new(x: new_pos.x, y: new_pos.y)).length
end
@dodecaphonic
dodecaphonic / gist:4203226
Created December 4, 2012 12:18
Drawing on canvas and getting an URI
class Smile.Utils.MarkImageDrawer
constructor: (@mark, @canvas) ->
@margin = 4
@backgroundColor = '#338e07'
@foregroundColor = '#fff'
@width = 40
@height = 60
# Public: Draws a Mark in the buffer.
#
class MiopicAPI
def do_something_with(foo_id, bar_id)
foo = Foo.find(foo_id)
bar = Bar.find(bar_id)
# ...
end
end
# Refactoring 1