magic

How does browser know when to prompt user to save password?

This is related to the question I asked here: http://stackoverflow.com/questions/2382329/how-can-i-get-browser-to-prompt-to-save-password This is the problem: I CAN'T get my browser to prompt me to save the password for the site I'm developing. (I'm talking about the bar that appears sometimes when you submit a form on Firefox, that say...

How does NSValue do its magic?

I have an MVC application. The model has a property that is a struct NSSize. It is writable like this: - (void)setSize:(NSSize)aSize; The view sets this NSSize using key-value-coding. However, you can not key-value-code a struct, so I wrapped it in an NSValue-object like this: [theView setValue:[NSValue valueWithSize:mySize] ...

RSpec: in-depth differences between before(:all) and before(:each)

Ok, so I've ran into a very strange issue, directly connected with before blocks. I'm doing a integration testing via Watir and RSpec. For a simple test to check if user can perform a login I'm creating a 'user' record in the db by means of factory_girl. So I put the following code: before(:each) do @user = Factory(:user) end if "s...

Python: Getting the attribute name that the created object will be given

Before I ask this, do note: I want this for debugging purposes. I know that this is going to be some bad black magic, but I want to use it just during debugging so I could identify my objects more easily. It's like this. I have some object from class A that creates a few B instances as attributes: class A(object): def __init__(self...

Using php's magic methods outside a class

Is it possible to use PHP magic methods (specifically __get()) outside a defined class? I'm wanting to use it in a configuration file for quick loading. The configuration file has a single array, $config, with many keys. Therefore, I'd like to override __get() to return the key in the array. ...

Is MarshalByRefObject special?

.NET has a thing called remoting where you can pass objects around between separate appdomains or even physical machines. I don't fully understand how the magic is done, hence this question. In remoting there are two base ways of passing objects around - either they can be serialized (converted to a bunch of bytes and the rebuilt at the...

Is correct name enough to make it happen?

Guys, I've just dipped in to limits.h by MS. I tried to check what's the return type for max() fnc and to my surprise I see something like this: // TEMPLATE CLASS numeric_limits template<class _Ty> class numeric_limits : public _Num_base { // numeric limits for arbitrary type _Ty (say little or nothing) public: sta...

Take input through Buttons in java

I understand that the title might not be descriptive enough, but I'm making a magic square game in Java and basically, I'm trying to replicate user input as found in the sudoku game here: http://www.websudoku.com/. What I have is a n x n grid of Buttons (not JButton) as the board and what I want the user to be able to do is when the use...

What is the magic behind perl read() function and buffer which is not a ref ?

I do not get to understand how the Perl read($buf) function is able to modify the content of the $buf variable. $buf is not a reference, so the parameter is given by copy (from my c/c++ knowledge). So how come the $buf variable is modified in the caller ? Is it a tie variable or something ? The C documentation about setbuf is also quit...

How do I make a defaultdict safe for unexpecting clients?

Several times (even several in a row) I've been bitten by the defaultdict bug: forgetting that something is actually a defaultdict and treating it like a regular dictionary. d = defaultdict(list) ... try: v = d["key"] except KeyError: print "Sorry, no dice!" For those who have been bitten too, the problem is evident: when d has ...

Magic Methods in Python

Howdy, I'm kind of new to Python and I wonder if there is a way to create something like the magic methods in PHP (http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods) My aim is to ease the access of child classes in my model. I basically have a parent class that has n child classes. These class...

consolidating class members in PHP

I recently came across an article by Matthew Weier O'Phinney (ZF project lead) that contains sample code similar to this: class User { protected $_data = array( 'username' => null, 'email' => null, 'fullname' => '', 'role' => 'guest', ); /* ... */ } Notice how what would traditionall...

Make Bluetooth on Android 2.1 discoverable indefinitely

Hello all. I'm working on a research project which involves Bluetooth and the Android OS. I need to make Bluetooth discoverable indefinitely in order for the project to continue. The Problem: Android limits discoverability to 300 seconds. I cannot ask the user every 300 seconds to turn discoverability back on as my application is d...

this code is supposed to fail but it works, why?

Folks I think I will throw all my modest C lore away. Look at this code please: int main( int argc, char ** argv, char ** envp ) { int aa; srand(time(NULL)); int Num=rand()%20; int Vetor[Num]; for (aa=0; aa<Num; aa++) { Vetor[aa]=rand()%40; printf("Vetor [%d] = %d\n",aa,Vetor[aa]); } } I would think that this should th...

applescript and magic mouse

I want to applescript the scrolling behaviour of my magic mouse so I can toggle it on and off with a key press. Trouble is, I'm a designer not a developer, so don't have a clue where to even start. I've experimented with Script Editor and Automator and got nowhere. Can someone help or best of all, just write the script for me? I can't be...

Rails -> do something with "updated_at" like "set_primary_key" for the id

have a legacy table with a field "LastModifiedDate", and I want to use that column as my "updated_at" column. Is there any way to tell Rails to use that field? Or, let me rephrase. :) ... How can I tell Rails to use that field? :) Thanks! ...

How do I choose a good magic number for my file format?

Hi, I am designing a binary file format from scratch, and I would like to include some magic bytes at the beginning so that it can be identified easily. How do I go about choosing which bytes? I am not aware of any central registry of magic numbers, so is it just a matter of picking something fairly random that isn't already identified ...

Why does VIM have its own regex syntax?

Why do you have to make your regex "very magic" so that you don't have to escape your capture quotes? And if you set your environment to very magic, you are non-standard and may have compliance issues. I am just wondering why vim uses a different regex syntax than say, perl? ...

PHP - Zend say avoid Magic Methods?

I was reading this page - http://www.hm2k.com/posts/50-php-optimisation-tips-revisited And one of the recommendations was to avoid using Magic Methods, cited from a Zend Performance PDF which gives no reason for its recommendation to avoid them. After some Google searching (and winding up here to an unrelated question) I wondered if an...

django magic: context passed to template

Hi, There is something i don't get in django template system. I have a FileField in my model called myfile. If i pass an instance of my model to a template, i can access file.size (this is an example). Form where this variable 'size' come from?? it's not part of the FileField class as far as i know. A small test: def save(self): s...