rurabe | 3 years ago | on: Show HN: Noya – A new kind of design tool
rurabe's comments
rurabe | 3 years ago | on: Understanding the N + 1 queries problem
rurabe | 3 years ago | on: Understanding the N + 1 queries problem
With AR queries you can do the same and make it linear in ruby (and then the computer doesn't really care if your sql is nested)
last_three_posts = Post.limit(3).order(created_at: :desc)
@posts = Comment.where(post_id: last_three_posts)rurabe | 3 years ago | on: Understanding the N + 1 queries problem
If you can count in the database itself it's a big win. Although no doubt your solution is cleaner code.
rurabe | 3 years ago | on: Understanding the N + 1 queries problem
(Also I think the above sql needs to be tweaked since you need the votes count grouped by comment not by post)
A one to many relationship in pure SQL is an awkward fit with a Rails app as it requires serializing (at least) the many as json. Then there's this weird conceptual gotcha where one resource is an AR instance and another is a pure hash.
I'd probably make a scope and association to help out here:
class Comment
scope :with_vote_count, ->{ joins(:votes).select('comments.*').select('count(votes.*) as vote_count') }
end
class Post
has_many :comments
has_many :comments_with_vote_counts, ->{ with_vote_counts }, class_name: 'Comment'
end
# in controller
@posts = Post.includes(:comments_with_vote_counts).limit(3).order(:created_at: :desc)
# in view/serializer, posts and comments are both AR instances
@posts.each do |post|
post.comments.each do |comment|
comment.vote_count # => Integer
end
end
This should give you 2 queries, one to load the posts, then one to load the comments and vote counts for the relevant posts. Controller stays nice and slim and the complexity is delegated to sql via the join scope, without any other dependencies.* edited for HN code block syntax
rurabe | 4 years ago | on: Defensive tactics from the modern history of urban warfare
Ukraine gets the Donbas back in return for international recognition of Crimea as Russian territory.
Fanciful, I know. And questionable whether Article 8 would hold up. But advantages:
1. End to the conflict 2. Security guarantees for all of Europe 3. Repurposing of NATO from anti Russia alliance to anti China alliance, ie pivot to Asia
rurabe | 4 years ago | on: Defensive tactics from the modern history of urban warfare
Russia is on the offensive when viewing this conflict in isolation. Zoom out to geopolitics and it is very much on the defensive.
They are locked in this conflict and if they cannot achieve their goals they will escalate. They also own the most nuclear weapons of any country on earth.
This is what the Art of War says when it says not to put enemies in a corner.
This is also a very realpolitik take on this. It goes without saying that all of this is a humanitarian disaster.
rurabe | 4 years ago | on: Defensive tactics from the modern history of urban warfare
Sorry to say, autocrats do not withdraw from a conflict like this regardless of attrition. Their power is their legitimacy and defeat is a threat to both their rule and probably their life. I mean look at how much flak Biden took withdrawing from Afghanistan despite being able to say that it was a horrible idea and someone else's fault.
This is a little different from Afghanistan and Iraq though, Russia's security concerns are valid and probably ameliorated by Ukraine as a failed state (as opposed to a NATO aligned state) so conquering and pacifying the country is not necessary.
The only real humanitarian solution is a diplomatic solution. I wonder if written guarantees that Ukraine and Georgia will never join NATO would be enough now honestly.
rurabe | 4 years ago | on: H3: Hexagonal hierarchical geospatial indexing system
rurabe | 4 years ago | on: U.S. Supreme Court revives LinkedIn bid to shield personal data
As far as I know, there's no reason it couldn't be "Log in to see this profile".
I believe the injunction bars LinkedIn from blocking hiQ specifically from accessing the publicly available information (which again is public by LinkedIn's choice). They made a point to draw a distinction between the public stuff and stuff behind a login/password.
rurabe | 4 years ago | on: U.S. Supreme Court revives LinkedIn bid to shield personal data
The only reason the data is public is for marketing purposes, to sign up more users.
rurabe | 4 years ago | on: U.S. Supreme Court revives LinkedIn bid to shield personal data
The same 9th circuit who held last year that LinkedIn could not block hiQ from scraping public data, just got asked to reconsider the same case, except now there is additional precedent that SCOTUS says if you had permission to access the computer then it's not a violation of the CFAA (even if you are a shady corrupt cop).
Hard to see this turning out any other way than the 9th circuit reaffirming their decision (or even strengthening it) and then it's up to LinkedIn to try SCOTUS again
rurabe | 4 years ago | on: Don't let social media think for you
rurabe | 4 years ago | on: Replit used legal threats to kill my open-source project
rurabe | 4 years ago | on: Replit used legal threats to kill my open-source project
rurabe | 4 years ago | on: Replit used legal threats to kill my open-source project
i actually agree that corporations have too much power versus individuals in society. but it's a bit much to jump into the gorilla exhibit and then write a clickbait post about whether it was unethical.
rurabe | 4 years ago | on: Replit used legal threats to kill my open-source project
im not saying any of this is illegal. just weird to copy your previous employer's tech stack, open source it, and try to play the victim and clickbait HN.
rurabe | 4 years ago | on: Replit used legal threats to kill my open-source project
ianal but absent some nda seems like it's probably legal for him to do it.
it just seems like kind of a dick move. i could mentor new engineers, wait until someone told me about a really cool idea, then steal it from them and build it myself. there's no law against it, it's just is kind of a dick move and seems kind of wrong.
as noted above, ceo is acting like a dick as well. but i think the way this dude is trying to play the victim through clickbaiting HN is a bit much. just my opinion.
rurabe | 4 years ago | on: Replit used legal threats to kill my open-source project
this case: build literally anything else except for the thing that he paid you to learn how it works.
rurabe | 4 years ago | on: Replit used legal threats to kill my open-source project
either you believe that people should act ethically even if that means forgoing actions that they are legally allowed to make. if you believe that, isn't it wrong to build a free, open source competitor using all the knowledge you just got from working inside a company?
or:
you believe that business is the law of the jungle, and everyone is free to do whatever they can get away with legally. in which case why is it a problem for amasad to get lawyers involved?
it seems this dude's victimization relies on holding amasad to a higher standard of ethics than he holds himself. maybe he should because he has more money and power. or maybe not?