internals

Why doesn't PHP's Autoload feature work in CLI mode?

♀尐吖头ヾ 提交于 2019-12-04 03:08:49
问题 This is more for my own personal edification than anything else but, this is something that has always bothered me: Why specifically can't PHP perform "autoloading" while in CLI mode? I've been reading this disclaimer for years, but I've never read anything that touches on why: http://php.net/manual/en/language.oop5.autoload.php: Note: Autoloading is not available if using PHP in CLI interactive mode. Does anyone know what is preventing PHP, as a language, from autoloading while working in

I'm trying to understand Microsoft's DoubleUtil.AreClose() code that I reflected over

霸气de小男生 提交于 2019-12-03 20:42:56
问题 If you reflect over WindowsBase.dll > MS.Internal.DoubleUtil.AreClose(...) you'll get the following code: public static bool AreClose(double value1, double value2) { if (value1 == value2) { return true; } double num2 = ((Math.Abs(value1) + Math.Abs(value2)) + 10.0) * 2.2204460492503131E-16; double num = value1 - value2; return ((-num2 < num) && (num2 > num)); } I'm trying to understand two different things: Where did they come up with the formula for num2? I guess I just don't understand the

How does RVM detect when you've changed directories?

做~自己de王妃 提交于 2019-12-03 18:47:19
问题 One thing that RVM can do is notice when you've changed directories, look for an .rvmrc , and change your current Ruby version and gemset according to that file's contents. It makes this change as soon as you change into that directory and outputs a message accordingly. How does it detect a change in the current working directory? I can imagine an extremely crude way of doing this: run a daemon that runs as the current user and keeps checking the results of pwd . But I'm sure that's not what

LIst Comprehensions: References to the Components

こ雲淡風輕ζ 提交于 2019-12-03 12:52:01
In sum: I need to write a List Comprehension in which i refer to list that is being created by the List Comprehension. This might not be something you need to do every day, but i don't think it's unusual either. Maybe there's no answer here--still, please don't tell me i ought to use a for loop. That might be correct, but it's not helpful. The reason is the problem domain: this line of code is part of an ETL module, so performance is relevant, and so is the need to avoid creating a temporary container--hence my wish to code this step in a L/C. If a for loop would work for me here, i would just

What Ruby technique does Rails use to make my controller methods render views?

走远了吗. 提交于 2019-12-03 11:38:16
Just curious if anybody knows what Ruby technique is used to accomplish the following in the Rails framework. If I don't write, say, an index method on a Rails controller, Rails will still render the index view file if the URL matches that route. That makes sense, because my controller inherits from a parent class, which must have its own index method. However, if I do define an index method, and only tell it to set an instance variable, it still renders the appropriate view. For example: def index @weasels = Weasel.all # If I omit this line, Rails renders the index anyway. # If this behavior

Does erlang implement record copy-and-modify in any clever way?

守給你的承諾、 提交于 2019-12-03 08:29:16
given: -record(foo, {a, b, c}). I do something like this: Thing = #foo{a={1,2}, b={3,4}, c={5,6}}, Thing1 = Thing#foo{a={7,8}}. From a semantic view, Thing and Thing1 are unique entities. However, from a language implementation standpoint, making a full copy of Thing to generate Thing1 would be intensely wasteful. For example, if the record were a megabyte in size and I made a thousand "copies," each modifying a couple of bytes, I've just burned a gigabyte. If the internal structure kept track of a representation of the parent structure and each derivative marked up that parent in a way that

Redirect ConfigurationManager to Another File

社会主义新天地 提交于 2019-12-03 08:05:47
I am looking to redirect the standard .Net ConfigurationManager class to another file; entirely . The path is determined at runtime so I can't use configSource or such (this is not a duplicate question - I have looked at the others). I am essentially trying to duplicate what ASP.Net is doing behind the covers. Thus not only my classes should read from the new config file, but also any standard .Net stuff (the one I am specifically trying to get to work is the system.codeDom element). I have cracked open Reflector and started looking at how ASP.Net does it - it's pretty hairy and completely

Spring transaction internals

左心房为你撑大大i 提交于 2019-12-03 07:50:47
问题 The situation is as follows: Method1 has four database update methods in it. The Method1 is annotated using the Spring transaction management semantics. Method2 has a database read method in it and it is invoked after Method1 has finished executing all its database updates. Method2 is also annotated using the Spring transaction semantics. There's a web request that comes in, the controller intercepts the request and invokes method1 and then method2. A transaction is wrapped around the web

How does scanf() work inside the OS?

删除回忆录丶 提交于 2019-12-03 06:58:23
I've been wondering how scanf()/printf() actually works in the hardware and OS levels. Where does the data flow and what exactly is the OS doing around these times? What calls does the OS make? And so on... David Claridge scanf() and printf() are functions in libc (the C standard library), and they call the read() and write() operating system syscalls respectively, talking to the file descriptors stdin and stdout respectively (fscanf and fprintf allow you to specify the file stream you want to read/write from). Calls to read() and write() (and all syscalls) result in a 'context switch' out of

Where did the text segment get its name?

陌路散爱 提交于 2019-12-03 06:57:11
问题 Traditional assembler, and higher level compilers work with several memory segments , according to intended use. Hence, there is a data segment, a stack segment, a bss, and text segment. The text segment is also called the code segment. Text segment? For machine code ? I have asked all the old-timers I could find, how something as unreadable as machine code came to be know as the "text segment". Every one of them agreed that, that was really what it was called, but none of them seemed to be