This is fun. I think that Emacs has the focus, so I type a bunch of control-N's to move the cursor down. Only it's Firefox that has the focus, so every control-N makes a new browser tab. Weeee!
I've got 20 years of using Emacs burnt into my brain. I don't have to think about what keys to press--I just think "let's move that block of code" and my fingers do stuff pretty much automatically.
Set the WABAC machine, Sherman. This question is about BASIC in general, and Microsoft's BASIC-80 in particular. Old school basic. With line numbers.
How do (or, rather, did) old-school BASIC interpreters handle FOR...NEXT loops when the loop body was not executed, and the NEXT statement appe...
:) I did those, too, at my first job. Well, sorta. My job was to program a minicomputer. I had a terminal with keyboard and CRT, the usual stuff. But my boss made me go down to the mainframe room and write a program on punch cards and submit it as a batch job.
When I asked him why, he said "Because this stuff is going away soon, and you need to be able to say you've used it. For bragging rights."
You remind me of the funniest thing I ever read about Mexican food in the U.S. A Canadian was visiting L.A., so went to two different restaurants to try the Mexican food. One night, she wen to a fancy restaurant and had authentic Mexican food served by Anglos. The next night, she went to Taco bell and fake Mexican food served by real Mexicans.
@Chris It's pretty normal in unix to restart processes by killing it and restarting it
Usually the actual job of stopping/starting/restarting a process isn't handled by the process itself, it's handled by the OS via something like init.d scripts
Hey guys, I am having some difficulty with writing my first Calculator script with Classes and Instance Methods. Can I describe the problem in here for assistance or do I need to make a formal question on SA?
RSpec is throwing me this error for all my mathematical functions, "wrong number of arguments (0 for 2)". It seems I am not using the in stance variables correctly?
@JonathanMusso You probably don't need accessors for x and y, since they are set by the constructor. It'd be a better class without the accessors, anyhow. Immutable objects are often easier to make correct.
@JonathanMusso See, you're ahead of the game. An immutable object is one which state cannot change after it's made. It has no method that will change any of its instance variables.
That's kind of a half-baked definition... but it's good enough to start with.
Yes, in two ways. The conventional way is that you don't define any methods that mutate the object's state. Another way, not commonly used, is to freeze an object. I don't know much about that way because I've seldom needed it.
@WayneConrad I am confused mate. In the previous article before this exercise it told me that the only way to initiate non hard-coded values into a new instance of a class was to create instance variables with the attr_accessor
You may use the different accessors to communicate your intent to someone reading your code, and make it easier to write classes which will work correctly no matter how their public API is called.
class Person
attr_accessor :age
...
end
Here, I can see that I may both read and write the ag...
^ an accessor is just a sort of macro that defines a reader method and a writer method for you.
(I'm not trying to brush you off with the link, so if that doesn't help, let me know.)
So why does it tell me I am not passing the required amount of arguments when I create the instance method with two parameters and the math is done with the instance variables?
I thought that by creating instance variables they can be used throughout multiple methods. I guess I am not accessing them correctly?
Ah. This is what someone mentioned to you earlier. Only #initialize needs parameters. The other methods do not. Remove the parameters from the other methods.
Im trying to replace a named scope with arel. But i got some trouble because im fairly new to rails and ruby. Is there a way to get a relation out of a Arel::SelectManager?
"Developers increasingly prefer spaces as they gain experience. Stack Overflow reputation correlates with a preference for spaces, too: users who have 10,000 rep or more prefer spaces to tabs at a ratio of 3 to 1."
Describe the Big O complexity of the following function as the array size grows:
def my_index(array, value)
low = 0
high = array.length - 1
while low <= high
mid = (low + high) / 2
if array[mid] > value
high = mid - 1
elsif array[mid] < value
low = mid + 1
else
return mid
end
end
nil
end
I thought, where I said "you picked an easy one"... what if you're thinking, "man, this stuff is hard." In that case, me saying how easy it is is thoughtless.
the question i was asked was this: An application logs an infinite amount of queries constantly write a function that can find the top hottest queries in the log file
@Nima The main thing, when you get that kind of question, is to think out loud. There's often a part of the question that's absurd, or some assumption that's not stated, and they want to know how you think about that kind of problem.
Yea... thinking out loud is key. They want to see you're analytical. I once got asked "How many tiny shampoo bottles are made in a year?" got caught off guard by that one hehe
@Jared That's a fun one. Assume that most tiny bottles are sold to travelers, so do a back-of-the-envelope calculation to estimate how many trips people take in a year.
@Nima For the log thing, I'd use a sliding window. You obviously can't keep track of all log entries forever. So you're going to, let's say, keep track of the last 10,000 of them.
I think it was limited to the US in the question. but yea... just had to think outloud of all the things that could impact it and how I was considering it
I'm going to use a bounded queue and a hash. The hash will keep track of counts. The bounded queue is what I use for the sliding window. Get new log entry, add it to the queue. If that pushes an entry off of the queue, decrement that entry's count (and remove it if now zero). Now increment the new entry's count in the hash.
Been home, took a nap. Now it's almost dinnertime.
I resolved the argument that the apipie-rails gem was having with a concern. I moved the concern from the app/controllers/concerns directory to the app/modules directory, and the circular dependency problem went away. I didn't change a single line of code. Go figure!
I left a README in the concerns directory to warn me, six months from now after I've forgotten all this, that putting a concern in the concerns directory might be bad.