Skip to content

Instantly share code, notes, and snippets.

View tiagopog's full-sized avatar

Tiago Guedes tiagopog

View GitHub Profile
@tiagopog
tiagopog / avatar.rb
Created April 9, 2015 14:53
Avatar concern.
# rails g paperclip {{model_name}} avatar && rake db:migrate
module Avatar
extend ActiveSupport::Concern
included do
avatar_options = WMR::Constants::AVATAR_OPTIONS
if Rails.env.production?
avatar_options.merge!(WMR::Constants::S3_CREDENTIALS)
end
@tiagopog
tiagopog / test.rb
Created April 25, 2015 18:40
Parallelism with Ruby
require 'benchmark'
require 'parallel'
def expensive_calculation(letter)
letter *= 1_000_000_000
puts letter[rand(0..999_999_999)]
end
Benchmark.bm do |x|
x.report("With Parallel: \n", in_thread: 3) do
@tiagopog
tiagopog / sample_0.rb
Last active August 29, 2015 14:21
Ruby - Metaprogramming
# Each object in Ruby also has its own metaclass,
# a Class that can have methods, but is only attached to the object itself.
matz = Object.new
def matz.speak
"Place your burden to machine's shoulders"
end
# What's going on here is that we're adding the speak method to matz's
@tiagopog
tiagopog / class.js
Created May 19, 2015 03:58
JavaScript ES6
// Old way...
function Person(name) {
this._name = name;
};
Person.prototype.getName = function() {
return this._name;
};
person = new Person('Foo');
@tiagopog
tiagopog / linguagens_programação.md
Last active August 29, 2015 14:21
Linguagens de Programação

Pilha de linguagens pretendida para os próximos dois anos (ordem de relevância):

  • Ruby
  • Execução: interpretada (script);
  • Paradigma: orientada a objetos;
  • Tipagem: dinâmica/forte;
  • Motivação: diversão, produtividade, prototipação e aspectos gerais.
  • Go
    • Execução: compilada;
  • Paradigma: multi-paradigma;
@tiagopog
tiagopog / nginx.conf
Created June 16, 2015 23:11
Localhost's NGINX config file.
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
@tiagopog
tiagopog / celluloid.rb
Last active August 29, 2015 14:23
Some concurrency samples in Ruby.
require "./lib/mailer"
require "benchmark"
require "celluloid"
class MailWorker
include Celluloid
def send_email(id)
Mailer.deliver do
from "eki_#{id}@eqbalq.com"
@tiagopog
tiagopog / memory_profiler.rb
Created July 12, 2015 15:20
Ruby - Memory profile test
require 'memory_profiler'
report = MemoryProfiler.report do
a = 0
b = 1
1_000.times do |e|
c = a + b
a = b
b = c
puts c # Check how large is the allocation of memory for String
@tiagopog
tiagopog / TipCalculator.swift
Created July 26, 2015 06:18
First Swift code o/
class TipCalculator {
let total: Double
let taxPct: Double
let subtotal: Double
// Class constructor:
init(total: Double, taxPct: Double) {
// Here we need to use "self" so the compiler will not get confused about the variables with the same name:
self.total = total
self.taxPct = taxPct
@tiagopog
tiagopog / class_hierarchy.swift
Last active August 29, 2015 14:26
Swift - Class definition and hierarchy
class NamedShape {
var numberOfSides = 0
var name: String
init(name: String) {
self.name = name
}
func simpleDescription() -> String {
return "A shape with \(numberOfSides) sides."