View project.rb
class Project < ActiveRecord::Base
has_many :time_entries
has_many :unbilled_time_entries, -> { unbilled }, class_name: 'TimeEntry'
end
View project.rb
class Project < ActiveRecord::Base
has_many :time_entries
has_many :unbilled_time_entries, -> { unbilled }, class_name: 'TimeEntry'
end
View focus.py
#!/usr/bin/python
try:
from AppKit import NSWorkspace
except ImportError:
print "Can't import AppKit -- maybe you're running python from brew?"
print "Try running with Apple's /usr/bin/python instead."
exit(1)
from datetime import datetime
View yada.rb
client_name = ''
if @invoice.client_company_name.present?
client_name = @invoice.client_company_name.gsub(' ', ' ').gsub(/[^0-9A-z\-]/, '_').gsub('__', '_')
elsif @invoice.client_name.present?
client_name = @invoice.client_name.gsub(' ', ' ').gsub(/[^0-9A-z\-]/, '_').gsub('__', '_')
elsif @invoice.client_email.present?
client_name = @invoice.client_email.gsub(' ', ' ').gsub(/[^0-9A-z@.\-]/, '_').gsub('__', '_')
end
contractor_name = @invoice.contractor_name.gsub(' ', ' ').gsub(/[^0-9A-z\-]/, '_').gsub('__', '_')
View inner_functions.rb
def dragon(name)
-> (size) {
-> (element) {
"#{name} is a #{size} dragon that breathes #{element}!"
}
}
end
puts dragon("Karo").("large").("ice")
View run_changed_tests.sh
git diff --stat | grep spec | awk '{print $1}' ORS=' ' | xargs rspec
View srt.rb
#!/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
View guruce-api.md

“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

View lazy_benchmark.rb
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
View configure-apache.txt
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!