Show more
Holm :ruby: boosted

Me: How do I work with currency?

Ruby: Just use BigDecimal.

JS: Deal with floating point math edge cases on every operation you do, forever.

Holm :ruby: boosted

A Noble Circle is free for PI Day. Hope you enjoy it. It is best played with sound on, and with a loved one. itunes.apple.com/pl/app/a-nobl

Holm :ruby: boosted

Hey all! So who’s going to RailsConf this year?

Holm :ruby: boosted

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.

Holm :ruby: boosted
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

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!

Show more
Ruby.social

A Mastodon instance for Rubyists & friends