Skip to content

Instantly share code, notes, and snippets.

View fidelisrafael's full-sized avatar
🏠
Working from home

Rafael Fidelis fidelisrafael

🏠
Working from home
  • https://web.archive.org/web/20221024062310/http://www.fidelis.work/
  • Brasil
  • 14:11 (UTC -03:00)
View GitHub Profile
@fidelisrafael
fidelisrafael / paypal.js
Created February 9, 2014 05:37
Paypal profile address autocomplete example (only runs from paypal website)
var paypalAddressClient = (function() {
"use strict" ;
var SERVICE_URL = 'https://www.paypal.com/br/cgi-bin/webscr?cmd=_prefilladdress&countryCode={{#country}}&zipcode={{#zip_code}}'
var httpClient = new XMLHttpRequest();
httpClient.onreadystatechange = function() {
if(this.status == 200 && this.readyState == httpClient.DONE) {
var response = this.responseText,
json_response = response.slice(response.indexOf("{")),
response_object = JSON.parse(json_response);
@fidelisrafael
fidelisrafael / mustache_data_test.rb
Last active August 29, 2015 13:56
Mustache and inline template test
require 'mustache'
class MustacheTest
def self.init
template = DATA.read
puts Mustache.render(template, name: "User Name", email: 'user@email.com', subject: 'Contact', area: 'Marketing', question_type: '1', message: 'Hi there, i need some support (...)', date: Time.now.strftime("%d/%m/%Y %T"), ip: '127.0.0.1', origin: File.expand_path(__FILE__) )
end
end
at_exit { MustacheTest.init }
@fidelisrafael
fidelisrafael / sp_coordinates.rb
Created February 9, 2014 05:48
São Paulo city coordinates for applications tests :)
SP_COORDINATES = [
[-23.5362800,-46.6764790], # Perdizes
[-23.5386997,-46.6745478],
[-23.5409620,-46.6736037],
[-23.5436570,-46.6704065],
[-23.5464110,-46.6745264],
[-23.5471302,-46.6717029], # Av. Sumaré
[-23.5444353,-46.6765952],
[-23.5506316,-46.6774321],
[-23.5549590,-46.6676259],
var runOptimized = function() {
"use strict";
function getPrimes(){
var primeCount, primes, obj;
primeCount = 0;
primes = new Array(100000);
obj = {};
obj.getPrimeCount = function() { return primeCount; };
obj.getPrime = function(i) { return primes[i]; };
obj.addPrime = function(p) { primes[primeCount]=p; primeCount+=1; };
---
- :cod_uf: '52'
:uf: Goiás
:city_id: '00050'
:city: Abadia de Goiás
:sigla_uf: GO
:city_code: '5200050'
- :cod_uf: '31'
:uf: Minas Gerais
:city_id: '00104'
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: root
password:
host: localhost
development:
<<: *default
@fidelisrafael
fidelisrafael / dls.rb
Created August 30, 2015 16:02
Simple DSL
module MyCusthomMethods
def after(action_name, &block)
puts "(before) after action #{action_name}"
instance_eval(&block)
puts "(after) after action #{action_name}"
end
def deploy!
@fidelisrafael
fidelisrafael / has_and_belongs_to_many.rb
Last active September 2, 2015 12:40
Course x Discipline
# course.rb
# rails g model course title:string
class Course < ActiveRecord::Base
has_and_belongs_to_many :disciplines
scope :programming, -> {
where("title LIKE ?", '%Programming%')
}
end
@fidelisrafael
fidelisrafael / rspec_model_testing_template.rb
Last active September 16, 2015 19:47 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@fidelisrafael
fidelisrafael / happy_programmers_day
Created September 12, 2012 14:41
Happy Programmer's Day!
// Ruby
[72, 97, 112, 112, 121, 32, 80, 114, 111, 103, 114, 97, 109, 109, 101, 114, 39, 115, 32, 68, 97, 121, 33].map(&:chr).join
// php
join(array_map("chr" , array(72, 97, 112, 112, 121, 32, 80, 114, 111, 103, 114, 97, 109, 109, 101, 114, 39, 115, 32, 68, 97, 121, 33)));
// JS
String.fromCharCode(72, 97, 112, 112, 121, 32, 80, 114, 111, 103, 114, 97, 109, 109, 101, 114, 39, 115, 32, 68, 97, 121, 33);
// C++