Skip to content

Instantly share code, notes, and snippets.

View filipebarcos's full-sized avatar

Filipe Costa filipebarcos

View GitHub Profile
module Bar
def self.method1
end
def method2
end
end
class Foo
include Bar
#in real life this is going until column 98
@my_variable = MyVeryLongClassName.method("three", "arguments", "method") || default_value_method
# or
@my_variable = MyVeryLongClassName.method("three", "arguments", "method")
@my_variable ||= default_value_method
# or
@my_variable = MyVeryLongClassName.method("three", "arguments", "method")
@filipebarcos
filipebarcos / das.rb
Created April 4, 2014 23:19
first piece of code with my new das keyboard
module ClassMethods
def self.method2
end
end
module InstanceMethods
def method1
end
end
require 'benchmark'
n = 1000000
Benchmark.bm(15) do |x|
x.report("assign single") { n.times do; c = 'a string'; end}
x.report("assign double") { n.times do; c = "a string"; end}
x.report("concat single") { n.times do; 'a string ' + 'b string'; end}
x.report("concat double") { n.times do; "a string " + "b string"; end}
end
@filipebarcos
filipebarcos / configure-apache.txt
Last active August 29, 2015 14:07
Quick-simple script to upgrade ruby version on a server using RVM and Phusion Passenger.
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /home/ubuntu/.rvm/gems/ruby-2.1.1/gems/passenger-4.0.57/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/ubuntu/.rvm/gems/ruby-2.1.1/gems/passenger-4.0.57
PassengerDefaultRuby /home/ubuntu/.rvm/gems/ruby-2.1.1/wrappers/ruby
</IfModule>
After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!
require 'benchmark/ips'
Benchmark.ips do |x|
x.report("with lazy") do
(1..1_000_000).lazy
.select(&:odd?)
.map(&:to_s)
.take(1000)
end
@filipebarcos
filipebarcos / guruce-api.md
Last active March 2, 2021 11:29
Palestra "NAS COXA" GURU-CE 15 (Apr 18th, 2015)

“APIs, you're doing it wrong!”

What is an API?

From Wikipedia, we have “a set of Routines, protocols and tools for building software applications”.

Web API

REST

Re presentation S tate T ransfer is a software architecture style consisting of guidelines and best practices for creating scalable web services. REST is a coordinated set of constraints applied to the design of components in a distributed hypermedia system...

RESTful

@filipebarcos
filipebarcos / srt.rb
Created February 5, 2016 11:47
Localize SRT files (pt-br). Rename all SRT files in nested folders to add `pt-br` in the end.
#!/usr/bin/env ruby
Dir.glob("#{Dir.pwd}/**/*.srt").each do |file|
newfile_name = file.sub(/\.srt$/, ".pt-br.srt")
File.rename(file, newfile_name)
end
git diff --stat | grep spec | awk '{print $1}' ORS=' ' | xargs rspec