Skip to content

Instantly share code, notes, and snippets.

@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 <[email protected]>
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
@dodecaphonic
dodecaphonic / delayable_mailer.rb
Last active December 16, 2015 20:49
A very-much-in-need-of-improvement way to replace DelayedJob with SuckerPunch for your application mailers.
class DelayableMailer < ActionMailer::Base
class QueueSetupError < StandardError; end
class << self
def queue(options)
@queue_name = options.fetch(:name)
@workers = options.fetch(:workers) { 2 }
setup_queue
end
require 'minitest/autorun'
TowEvent = Struct.new(:id, :license_plate, :category, :operator, :tow_car,
:entry_time, :address, :ordering)
class OrdersTowEvents
WEIGHTS = { truck: 100, car: 200, bike: 300 }
attr_reader :grouped_events
private :grouped_events