Dinesh Hyaunmikha (@dnes100) profile picture
Bhaktapur, Nepal
Joined October 2011
Photo by Dinesh Hyaunmikha (@dnes100)Photo by Dinesh Hyaunmikha (@dnes100)Photo by Dinesh Hyaunmikha (@dnes100)Photo by Dinesh Hyaunmikha (@dnes100)
Ruby gotcha: a=1, b=2, c=3 variables b and c assignments would be as expected, but a would be an array! b => 2 c => 3 a => [1, 2, 3] It turns out comma has height precedence than assignment and is evaluated as a = (1, b=2, c= 3) a = (1, 2, 3) a = 1,2,3 same as a = [1,2,3]
25
Testing timestamps accurately is tricky. `be_within` is a good solution to match within time range in #rspec #ruby #rubyonrails expect(user.created_at).to be_within(1.second).of Time.now
2
34
In #ruby, we can check class variables by: `MyClass.class_variable_get(:@@my_class_variable)` For instance variables: `MyInstance.instance_variable_get(:@ my_instance_variable)` Quite helpful in debugging classes without any getter methods.
1
11
The Prisoner's Dilemma Moral: "Be nice, forgiving but don't be a pushover" youtu.be/mScpHTIi-kM?si=M_dM… via @YouTube
13
Ever used "respond_to?" in #ruby? Did you know its 2nd param checks for private/protected methods? class Hello private def secret_method 'shhh' end end o = Hello.new o.respond_to?(:secret_method) # false o.respond_to?(:secret_method, true) # true
1
56
#rspec #ruby Faking and testing function calls at the same time: `expect(obj).to receive(:meth).with(arg).and_return(res)` `allow` does same thing except it doesn't raise error if method isn't called during test. `allow(obj).to receive(:meth).with(arg).and_return(res)`
1
1
42
#activerecord #rails Query for products with orders (P intersection O): Product.joins(:order_items) .distinct Products without any orders (P - O): Product.left_joins(:orders_items) .where(order_items: {id: nil}) .distinct No need to use subquery!
1
26
Much simpler in Rails 6.1: `Product.where.missing(:order_items)`
5
Hello @NCHLOfficial, All data in my connectips account including linked banks, favorite users, transaction history are lost! This poses a very serious question regarding stability/security of our critical data!
Changing text on mouse hover with just CSS! #tailwindcss hover + after + content content can access attributes with attr()
1
Hi @eSewaNepal , I tried several times to pay my electricity bill last month but all of them failed. Now I've to pay a fine! Could you look into this please. I'm sure there are others with same problem.
1
4