A Noble Circle is free for PI Day. Hope you enjoy it. It is best played with sound on, and with a loved one. https://itunes.apple.com/pl/app/a-noble-circle/id977865620?mt=8
#introductions Hi all, my name is Rodrigo and I've been developing with Ruby for 4 years now.
Lately I've been using Hanami at work and in some personal projects, but I really want to get back to develop some stuff with Rails again.
A script to run tests changed since master, pretty handy when checking PRs:
test_runner = File.exists?("Gemfile") ? "bundle exec " : ""
test_runner += if File.exists?("config/application.rb")
"rails test"
elsif File.directory?("spec")
"rspec"
elsif File.directory?("test")
"ruby -Itest"
else
"ruby"
end
changed_test_files = `git log --name-only --pretty=oneline --full-index master..HEAD`.split.select { |f| f =~ /\Atest|spec/ }
exec "#{test_runner} #{changed_test_files.join(' ')}"
really interesting article about how to log: https://apenwarr.ca/log/20190216
blast from the past: https://github.com/judofyr/tipi/blob/master/examples/hello.rb
in 2014 I wrote a Ruby REST API system which had:
- a router that was based on a graph-structure: e.g. you say that "/users/:id" returns a User resource, and then you define the other actions available on a User resource
- strict types on input/output of actions
- usage of a `state` variable that is passed around internally to communicate across resources
this is like 80% of the GraphQL ideas
Derivation representation using binary subtree sets (by Elizabeth Scott, Adrian Johnstone, L.Thomas van Binsbergen): https://www.sciencedirect.com/science/article/pii/S0167642318302302
always interesting to see a new Scott/Johnstone paper! going to have to see if I can use some of these techniques in my own experiments. /cc @jamey
Starting to write up some blog posts on generally useful programming topics. Partially to try to solidify my own knowledge - it's tough to write about a subject you only have a fuzzy understanding of. Hopefully it will be useful to someone else down the line as well!
First one is a #regex intro, feedback welcome:
@jamey I should probably write something proper about it. it might be hard to understand if you're not in my head
@jamey it's neat how Seq/Alt/Rep/Eps are "dissolved" due to #each_pair and the only thing that matters while matching are terminal matchers (Char) and rule calls/returns.
@jamey here we go: https://gist.github.com/judofyr/80bd41893985f49b7550294b295d3afe
should be able to recognize CFG with left-recursion, hopefully in O(n^3) time. there's a benchmark there for the ambiguous "n+n+n+"-grammar, and that seems to fit best in O(n^2) actually
How ERB uses `Binding` objects:
class DiyErb
def initialize(template)
@template = template
end
def result(binding)
@template.gsub(/<%=(.+?)%>/) do
binding.eval($1)
end
end
end
https://blog.appsignal.com/2019/01/08/ruby-magic-bindings-and-lexical-scope.html
I’d love to see better examples of using `#tap`, but I’ve mostly seen it used to refactor this:
metadata = {}
metadata[:id] = user.id if user
metadata
That’s explicit. It creates a hash, adds a value if a condition is true, then returns the hash.
With `#tap`, the code is more difficult to read, and requires the next person to know what `#tap` does (“yields x to the block, and then returns x.”). 🤷♀️
{}.tap do |metadata|
metadata[:id] = user.id if user
end
Ruby snippet to print a line of code and its result:
```
def debug(&block)
puts block.source.strip
result = http://block.call
puts "# => #{result}"
result
end
debug { 1 + 2 }
```
and I've finally released Tubby 1.0: https://github.com/judofyr/tubby
RubyGems 3 released! https://blog.rubygems.org/2018/12/19/3.0.0-released.html
looks like Ruby 2.6 on Christmas is landing with RubyGems 3 and Bundler 2
Exciting!
nice: Ruby on Ice - https://rubyonice.com