621 karma · joined Jan 11, 2018 (8y ago) · 450 submissions
comment 5y ago · link · parent
assertEquals(0, add(0,0))
assertEquals(1, add(0,1))
assertEquals(2, add(1,1))
assertEquals(8, add(3,5))
assertEquals(-3, add(2,-5))
PS: This kind of proves why a test is a lot less useful than the algorithm. Try figuring out how to implement "add" from the above test.comment 5y ago · link · parent
When you first picked a door, there was a 33% chance it was right, and a 67% chance one of the other two doors was right.
Once the other door got opened, it is still a 67% chance that the other two doors is right, but you now know which one of those two it would be - the one which wasn’t opened.
comment 5y ago · link · parent
I find this answer on quora to the question of why Turing machines are a good model to be insightful: https://qr.ae/pGGCmq
comment 5y ago · link · parent
Good things to compare to are:
- spicy food
- stinky foods (eg cheese)
- coffee
All of the above are acquired tastes. I could barely eat spicy before, now I love it. Stinky cheese makes we want to vomit, but others enjoy it. I only drink decaf, yet periodically enjoy a black coffee, something which seemed absurd when I was younger.
To me alcohol is just one more flavor option. I wouldn’t want it banned just because other people can’t control themselves.
comment 5y ago · link · parent
There’s a bunch of ways to do this, but I’ll just leave this one trick here.
Instead of:
List<Integer> x = new ArrayList<Integer>();
write this: List<Integer> x = new ArrayList<Integer>(){};
Now you’ll be able to ask at runtime and determine it is a subclass of List<Integer>.comment 5y ago · link · parent
Eg instead of this:
ON (customer_order_items.meal_item_id = meal_items.id
OR employee_markouts.meal_item_id = meal_items.id
)
Do this: ON meal_items.id = COALESCE( employee_markouts.meal_item_id, customer_order_items.meal_item_id )
The latter can optimize properly. Probably still slower than the UNION, but would be more in line with expected performance. It might be more useful too in certain cases, such as if building a view.comment 5y ago · link · parent
(Note when I say linear performance, I mean the join predicate is executed a linear amount of times, but the initial sort/hash operation was probably more like O(n log n))
comment 5y ago · link · parent
comment 5y ago · link · parent
I did this too until very recently as well. Finally got around to just setting up a docker image serving data from ~/Sites. I think it was the switch to an unexpected php version which convinced me.
I've just taken a look through /etc/ for anything else I may have configured which got lost. Doesn't seem much I touched myself, but seeing lots of files like /etc/shells~orig and /etc/syslog.conf~previous which are odd.
comment 5y ago · link · parent
Applying regex's only really count as "parsing" when you are matching against an entire document. Searching is not parsing. Same argument applies if you apply grep to an html doc - I wonder why there's no posts about "you can't parse HTML with grep". I apply grep all the time to source code...
comment 5y ago · link · parent
The next step is to get a CDN to proxy both www.example.com and tracker.example.com and promise to be independent, or for the ad company to operate the proxy themselves.
comment 5y ago · link · parent
comment 5y ago · link · parent
Store this object in a table and load it in the function.
Storing it in a Table and accessing the elements by selecting from the Table. This can be a heavy overhead.
While I can’t don’t know for sure how much overhead that is versus launching into tcl, I do avoid creating temporary tables in performance-sensitive code.comment 5y ago · link · parent
A new mime type doesn’t really help because the parser doesn’t check the mime type, it assumes the programmer did that. I’m not against making a new mime type or specification, but there are already so many and making more doesn’t seem to help. Yes it would be nice if PHP and Python implement the logic for ignoring trailing commas the same way, but 99% of the time that isn’t all that important. Yes there will be cases where it matters and bugs are introduced, but since there already significant differences between JSON parsers I don’t see these kinds of things as making it much worse.
comment 5y ago · link · parent
As a case in point, the python parser breaks the JSON spec already with regards to Infinity/NaN, but then has flags to configure this. See https://docs.python.org/3/library/json.html#module-json
> The RFC does not permit the representation of infinite or NaN number values. Despite that, by default, this module accepts and outputs Infinity, -Infinity, and NaN as if they were valid JSON number literal values:
comment 5y ago · link · parent
If the box fan is bigger and 4x as noisy, it's not a valid comparison for many situations. Instead should compare fans which are similar sizes and operating at similar noise levels.
I have a Dyson fan and a box fan (not air purifiers), and the Dyson fan is significantly quieter, smaller (same height but about half as wide), while having a similar power (not exactly sure which one is stronger).