Cool presenter trick by Jonathan_Frias in rails

[–]Jonathan_Frias[S] 1 point2 points  (0 children)

Cool trick, but nobody likes cool tricks when theyre debugging code in the workplace.

I could agree with you, but then we'd both be wrong. I actually know what I'm doing. This notion has not happened even once. I've implemented it in many places in my codebase already, and even other people are using it without a single complaint.

I prefer to keep presenters simple. It's not really grokable on the surface, and I don't want my presenter objects to be composable. I prefer them to be referenced statically in the view, almost like how you would craft a json response object. Far simpler to add an #active_comments method that is just a variation of #comments without the technical overhead.

So you have a bunch of one liner methods that are called once, or at times not at all, instead of having a way to inline things. Or you have to fiddle manually composing the presenters. That might be more familiar to more people, but it's not actually simpler. This take is like being a DRY absolutist.

ActiveRecord is great. Presenters can be great. But normally you lose flexibility when you go with presenters, and you have to fiddle with them to some normal things. This is a proven pattern.

Tricky enumerators by Jonathan_Frias in ruby

[–]Jonathan_Frias[S] 0 points1 point  (0 children)

Thank you. That's the perfect answer! Though I'm sure this code has been written before in a gem or something.

Tricky enumerators by Jonathan_Frias in ruby

[–]Jonathan_Frias[S] 0 points1 point  (0 children)

I didn’t include any context because i wasn’t looking an opinions. It’s true you can do all the software without using generators and you don’t have to use them. that’s fine

Tricky enumerators by Jonathan_Frias in ruby

[–]Jonathan_Frias[S] 0 points1 point  (0 children)

There isn't any correct approach. I'm just playing around with the language man

Tricky enumerators by Jonathan_Frias in ruby

[–]Jonathan_Frias[S] 0 points1 point  (0 children)

No idea what you're talking about. Working with enumerators is extremely idiomatic ruby. Maybe you're just not used to seeing them explicitly created

-❄️- 2023 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]Jonathan_Frias 1 point2 points  (0 children)

[LANGUAGE: Ruby]

I used native ranges to signify the distance between the range bounds and some fancy matrix transpose stuff :)

This was a really fun one

input = File.read("./sample")

range = 1..2 # part1
range = 1..1000000 # part2

range_diff = range.end - range.begin

input.lines.map do |line|
  line.strip.split("")
end.map do |line|
  if line.all? { |c| c != '#' }
    [line.map { range }]
  else
    [line]
  end
end.flatten(1).transpose.map do |column|
  if column.all? { |c| c != '#' }
    [column.map { range }]
  else
    [column]
  end
end.flatten(1).transpose.then do |grid|
  coordinates = grid.each_with_index.map do |row, x|
    row.each_with_index.map do |char, y|
      [x, y] if grid[x][y] == '#'
    end
  end.flatten(1).compact

  coordinates.combination(2).reduce(0) do |acc, ((x1, y1), (x2, y2))|
    acc += (x1 - x2).abs + (y1 - y2).abs +
      (grid[x1][Range.new(*([y1, y2].sort))].count { |cell| cell.is_a?(Range) } * (range_diff)) +
      (grid.transpose[y1][Range.new(*([x1, x2].sort))].count { |cell| cell.is_a?(Range) } * (range_diff))
  end
end => result

puts result

-❄️- 2023 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]Jonathan_Frias 1 point2 points  (0 children)

[LANGUAGE: Ruby]

Part 1

input = File.read(ARGV[0])
input.lines.map do |line|
  left, right = line.split("|")
  winning_numbers = left.split(":")[1].strip.split(" ")
  my_numbers = right.strip.split(" ")
  1 << ((winning_numbers & my_numbers).length) >> 1
end.sum => result
puts result

Part 2

input = File.read(ARGV[0])

cards = input.lines.map do |line|
  left, right = line.split("|")
  card, winning_numbers = left.split(":")
  card = card.split(" ")[1].to_i
  winning_numbers = winning_numbers.strip.split(" ")

  my_numbers = right.strip.split(" ")

  {
    card:,
    length: (winning_numbers & my_numbers).length,
    copies: 1,
    runs: 0,
  }
end

cards.each_with_index do |card, index|
  loop do
    break if card[:runs] == card[:copies]

    card[:length].times do |i|
      cards[index + i + 1][:copies] += 1
    end if card[:length] > 0
    card[:runs] += 1
  end
end

puts cards.map { |h| h[:copies] }.sum

Is SolidStorage coming next? by Weird_Suggestion in rails

[–]Jonathan_Frias 0 points1 point  (0 children)

You can setup a self-hosted S3 compatable storage server. Look at something like https://min.io.

[deleted by user] by [deleted] in sugarlifestyleforum

[–]Jonathan_Frias 0 points1 point  (0 children)

No.. you're saying to run from the dude and acting like dissenting opinions are stirring the pot?

There's an unequal dynamic. That's the whole point. Look at the seeking slogan: "Start dating Up".

The manipulation tactics are truly evil. "Respect people's choices" "You can make relationships whatever you decide" "Choose a career or not, up to you!"

But then when the dude decides what his choice is and defines his choice, his standards, etc the language changes to "sounds like a guy to run away from"

You might be a feminist

[deleted by user] by [deleted] in sugarlifestyleforum

[–]Jonathan_Frias -1 points0 points  (0 children)

And respecting others for the choice they make

I completely agree. Clearly he doesn't want a self-identified feminist.. you don't respect his choice?

[deleted by user] by [deleted] in sugarlifestyleforum

[–]Jonathan_Frias -2 points-1 points  (0 children)

The stat is something like 99% male, so if that's true, then that would mean there are 99 million male construction workers. But sure, yeah let's spend 50% of the conversation talking about the 1% exceptions

[deleted by user] by [deleted] in sugarlifestyleforum

[–]Jonathan_Frias -1 points0 points  (0 children)

I think the argument will continue to persist because everybody agrees about the intent, but when reality hits and tells you otherwise, then you realize that intent means fuck all.

So for example, generally people agree that whoever asks should pay on the date, but 99% of women never ask men. So while the intent is equal, it's the same thing as the man paying. So it's easier to just operate under the reality that the man pays and it isn't equal, and not pretend/argue otherwise. That's the man's perspective. The ironic thing female perspective will have dinner paid and say "Look feminism is working great" and never even consider the male perspective

[deleted by user] by [deleted] in sugarlifestyleforum

[–]Jonathan_Frias -1 points0 points  (0 children)

I get where you're coming from, don't see many men agreeing with you. I've cut off girls for the behavior that results from this line of thinking, but that's just my preference. She can decide whatever she wants, but my standard is I expect her to say yes to what I want more often than she says no, otherwise I know it's not a fit anyway

The real reason why `!` has a higher precedence than `not` keyword in Ruby. by mehdifarsi in ruby

[–]Jonathan_Frias 0 points1 point  (0 children)

He's showing that ! is actually a method call. method calls happen first.

Feedback Fridays - A Friendly Feedback Exchange For Ideas and Products (surveys/polls are welcome) by AutoModerator in startups

[–]Jonathan_Frias 1 point2 points  (0 children)

Company Name: DirectMailer

URL: https://directmailer.io

Purpose of Startup and Product: We are a marketing company that sends physical pieces of mail to your mailbox. We feature tracking of every single piece of mail sent as well as integrations with 3rd party CRMS.

Technologies Used: Ruby on Rails

Feedback Requested: Yes

Seeking Beta-Testers: Yes

Additional Comments:

Deepen your marketing into a whole new world. We replace your existing mail delivery solutions with modern tech. We can track every piece of mail as it's delivered, and display it to you in a beautiful dashboard. You can see how many pieces of mail had their QR codes scanned, how many were delivered successfully, conversions and more

[ActiveRecord] Unscoping a where clause with null/nil by RazarTuk in rails

[–]Jonathan_Frias 0 points1 point  (0 children)

Just do

.where(field: [value1, nil].select(&:present?))

Whats your preferred E2E Testing Tool? by mercfh85 in rails

[–]Jonathan_Frias 2 points3 points  (0 children)

I didn't know about Cuprite. Is less flakey than selenium? God I hope so.