Holm :ruby: boosted

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(' ')}"

Holm :ruby: boosted

does anyone know *why* Kernel module exist? why isn't the methods just defined directly on Object?

blast from the past: github.com/judofyr/tipi/blob/m

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): sciencedirect.com/science/arti

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

Holm :ruby: boosted

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 intro, feedback welcome:

edsaav.com/regular-expressions

@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 and the only thing that matters while matching are terminal matchers (Char) and rule calls/returns.

@jamey here we go: gist.github.com/judofyr/80bd41

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

$ du -sh .
13M

oh. this was a neat repo.

$ yarn
$ du -sh .
1.2G

oh…

Holm :ruby: boosted

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

blog.appsignal.com/2019/01/08/

Holm :ruby: boosted

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

Holm :ruby: boosted

Ruby snippet to print a line of code and its result:

```
def debug(&block)
puts block.source.strip
result = block.call
puts "# => #{result}"
result
end

debug { 1 + 2 }
```

Holm :ruby: boosted

Looking to learn from everyone here this year. Hope I get to interact with all of you. Please reach out to me if you want to talk about Ruby, Ruby On Rails, Web Development, and/or Coding Challenges, or anything really 😀

Holm :ruby: boosted

RubyGems 3 released! blog.rubygems.org/2018/12/19/3

looks like Ruby 2.6 on Christmas is landing with RubyGems 3 and Bundler 2

Exciting!

Holm :ruby: boosted

I *love* reinventing the wheel.

Some of my articles explain how to build your own GenServer in Elixir or how to compare images in plain Ruby, and I’ve built minimal clones of libraries like RSpec and Spring in the past to understand and teach how they work.

While you shouldn’t rely on a hand-rolled HTTP server or a naïve reimplementation of an ancient OTP construct in production, taking software apart and rebuilding it is the best way I know to understand what’s happening under the hood.

Holm :ruby: boosted

Hi, everyone!
Does anyone know of any company that is hiring remote junior developers? I have more than one year of experience in backend and I am looking for new opportunities.

I will appreciate all your RT! 🙌 :mastodon:

Holm :ruby: boosted

Random Ruby performance tip: if you are using anything more complicated than strings/symbols for hash keys, you may want to consider caching their hash values (override the Object#hash method to do so).

Show more
Ruby.social

A Mastodon instance for Rubyists & friends