This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* NÃO USE ESTE SCRIPT SOBRE ARQUIVOS UTF-8! VOCẼ PERDERÁ TUDO. | |
* | |
* Não use este arquivo sem fazer Backup dos arquivos antes. | |
* | |
* Alterações necessárias: | |
* - verificar se o arquivo atual é ISO-8859-1 realmente. | |
* - verificar se é um arquivo de texto (transformar imagens vai inutilizá-las | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calcDist($lat_A, $long_A, $lat_B, $long_B) { | |
$distance = sin(deg2rad($lat_A)) | |
* sin(deg2rad($lat_B)) | |
+ cos(deg2rad($lat_A)) | |
* cos(deg2rad($lat_B)) | |
* cos(deg2rad($long_A - $long_B)); | |
$distance = (rad2deg(acos($distance))) * 69.09; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
event_handler.js adds a layer for setting variables in Javascript | |
and calling a callback whenever it is changed. | |
You won't need to call a function manually to update your view. | |
This method makes it easy to separated view-logic from business-logic | |
at Javascript level, and let things run automatically. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this doesn't work | |
"INSERT INTO table1 (field1) VALUE( (SELECT field1 FROM table1 LIMIT 1)+1 )" | |
# "You can't specify target table 'table1' for update in FROM clause" | |
# but this works | |
"INSERT INTO table1 (field1) VALUE( (SELECT field1 FROM (SELECT field1 FROM table1 LIMIT 1))+1 )" | |
# the FROM statement becomes just a repetition of the subquery. | |
# Thus, MySQL creates the temporary table with no problem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Omniscient is a gem that automatically dumps a MySQL database in a remote server, | |
# copies the dumped file to localhost via scp and imports it, overwriting the local | |
# database (or table). | |
# It'll be very useful for those that are developing using more than one machine and | |
# don't want to dump and clone data manually. | |
# Setup a new host machine | |
$ omniscient add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mini_magick' | |
suffix = "cached_" | |
sleep_between_process = 0.3 | |
sizes = ["x142","x200"] | |
# loop through files | |
Dir.glob("[^cache]*").each { |e| | |
image_path = File.expand_path(e) | |
image = MiniMagick::Image.open(image_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# No ActiveRecord, Client has_one ClientProfile | |
# | |
# ClientProfile tem um campo chamado Twitter. Como é um varchar | |
# e um usuário pode ter 2 contas no Twitter, salvo os dados no | |
# formato "usuario;usuario2;usuario3" neste campo. O problema abaixo gira em torno | |
# do processamento desta string e como testar isto usando os princípios SOLID que | |
# você abordou na sua palestra na RubyConf. | |
# | |
# O split(";") era feito no model, o qual tirei para fora (classe ClientService abaixo). | |
# O problema é: como vou testar com mock se o argumento injetado precisa ser ActiveRecord? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you've been in a medium to large project, you know how painful | |
# it becomes to maintain your domain logic in ActiveRecord files. | |
# | |
# Later you extract classes to lib/, so now you have a) domain logic | |
# classes and b) persistence objects (ActiveRecord). This means you | |
# started using the DataMapper pattern. | |
# | |
# Below is the draft for a gem to implement DataMapper pattern in Ruby. | |
# The Unit of Work pattern stands as an observer - whenever the domain | |
# object changes, the UoW saves its attributes to the database. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module IVarInterceptor | |
def self.included(klass) | |
def klass.new(*args, &block) | |
super.extend IVarInterceptor | |
end | |
end | |
def self.extended(object) | |
object.singleton_class.class_eval do | |
original_methods = instance_methods.each_with_object({}) do |method_name, hash| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#inside RSpec.configure | |
config.before :all do | |
SunspotTest.stub | |
end | |
config.before(:all, search: true) do | |
SunspotTest.setup_solr | |
Sunspot.remove_all! | |
Sunspot.commit |
OlderNewer