View 1-sample-es6-generator.js
function *foo(x) {
const y = 2 * (yield (x + 1));
const z = yield (y / 3);
return (x + y + z);
}
var it = foo( 5 );
// note: not sending anything into `next()` here
console.log(it.next()); // { value:6, done:false }
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