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
  • 22:50 (UTC -03:00)
View GitHub Profile
@fidelisrafael
fidelisrafael / hack.sh
Last active December 24, 2015 11:29 — forked from kulesa/hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#

Today, in Ruby, if I want to make a network request, I block

response = Net::HTTP.get("/post/1")

If I want to do multiple requests in parallel, I can use a thread per request

responses = ["/post/1", "/post/2"].map do |url|
@fidelisrafael
fidelisrafael / simple_benchmark.rb
Last active December 24, 2015 22:39
Simple benchmark (simple test from Rodrigo Alves : https://gist.github.com/rodrigoalvesvieira/6255267)
require 'benchmark'
Benchmark.bm(10) do |x|
x.report("Array#join") {
10000.times do
["'", ("a".."z").to_a.join("' , '"), "'"].join
end
}
x.report("String#<<") {
10000.times do
@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],
@fidelisrafael
fidelisrafael / app.js
Last active August 26, 2021 02:15
Easy way to export data to XLS format using Node.js
// clone this gist to a empty folder, the run:
// npm init (and follow steps)
// npm install express --save
// npm install swig --save
// node app.js and open http://localhost:3000
function App() {
var express = require('express');
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