Search Results

Search found 3096 results on 124 pages for 'scope creep'.

Page 19/124 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • Lexical and dynamic scoping in Mathematica: Local variables with Module, With, and Block

    - by dreeves
    The following code returns 14 as you'd expect: Block[{expr}, expr = 2 z; f[z_] = expr; f[7]] But if you change that Block to a Module then it returns 2*z. It seems to not matter what other variables besides expr you localize. I thought I understood Module, Block, and With in Mathematica but I can't explain the difference in behavior between Module and Block in this example. Related resources: Tutorial on Modularity and the Naming of Things from the Mathematica documentation Excerpt from a book by Paul R. Wellin, Richard J. Gaylord, and Samuel N. Kamin Explanation from Dave Withoff on the Mathematica newsgroup

    Read the article

  • CDI SessionScoped Bean instance remains unchanged when login with different user

    - by Jason Yang
    I've been looking for the workaround of this problem for rather plenty of time and no result, so I ask question here. Simply speaking, I'm using a CDI SessionScoped Bean User in my project to manage user information and display them on jsf pages. Also container-managed j_security_check is used to resolve authentication issue. Everything is fine if first logout with session.invalidate() and then login in the same browser tab with a different user. But when I tried to directly login (through login.jsf) with a new user without logout beforehand, I found the user information remaining unchanged. I debugged and found the User bean, as well as the HttpSession instance, always remaining the same if login with different users in the same browser, as long as session.invalidate() not invoked. But oddly, the session id did modified, and I've both checked in Java code and Firebug. org.apache.catalina.session.StandardSessionFacade@5d7b4092 StandardSession[c69a71d19f369d08b5dddbea2ef0] attrName = org.jboss.weld.context.conversation.ConversationIdGenerator : attrValue=org.jboss.weld.context.conversation.ConversationIdGenerator@583c9dd8 attrName = org.jboss.weld.context.ConversationContext.conversations : attrValue = {} attrName = org.jboss.weld.context.http.HttpSessionContext#org.jboss.weld.bean-Discipline-ManagedBean-class com.netease.qa.discipline.profile.User : attrValue = Bean: Managed Bean [class com.netease.qa.discipline.profile.User] with qualifiers [@Any @Default @Named]; Instance: com.netease.qa.discipline.profile.User@c497c7c; CreationalContext: org.jboss.weld.context.CreationalContextImpl@739efd29 attrName = javax.faces.request.charset : attrValue = UTF-8 org.apache.catalina.session.StandardSessionFacade@5d7b4092 StandardSession[c6ab4b0c51ee0a649ef696faef75] attrName = org.jboss.weld.context.conversation.ConversationIdGenerator : attrValue = org.jboss.weld.context.conversation.ConversationIdGenerator@583c9dd8 attrName = com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap : attrValue = {-4968076393130137442={-7694826198761889564=[Ljava.lang.Object;@43ff5d6c}} attrName = org.jboss.weld.context.ConversationContext.conversations : attrValue = {} attrName = org.jboss.weld.context.http.HttpSessionContext#org.jboss.weld.bean-Discipline-ManagedBean-class com.netease.qa.discipline.profile.User : attrValue = Bean: Managed Bean [class com.netease.qa.discipline.profile.User] with qualifiers [@Any @Default @Named]; Instance: com.netease.qa.discipline.profile.User@c497c7c; CreationalContext: org.jboss.weld.context.CreationalContextImpl@739efd29 attrName = javax.faces.request.charset : attrValue = UTF-8 Above block contains two successive logins and their Session info. We can see that the instance(1st row) the same while session id(2nd row) different. Seems that session object is reused to contain different session id and CDI framework manages session bean life cycle in accordance with the session object only(?). I'm wondering whether there could be only one server-side session object within the same browser unless invalidated? Since I'm adopting j_security_check I fancy intercepting it and invalidating old session is not so easy. So is it possible to accomplish the goal without altering the CDI+JSF+j_security_check design that one can relogin with different account in the same or different tab within the same browser? Really look forward for your response. More info: Glassfish v3.1 is my appserver.

    Read the article

  • R: disentangling scopes

    - by rescdsk
    Hi, Right now, in my R project, I have functions1.R with doFoo() and doBar(), functions2.R with other functions, and main.R with the main program in it, which first does source('functions1.R'); source('functions2.R'), and then calls the other functions. I've been starting the program from the R GUI in Mac OS X, with source('main.R'). This is fine the first time, but after that, the variables that were defined the first time through the program are defined for the second time functions*.R are sourced, and so the functions get a whole bunch of extra variables defined. I don't want that! I want an "undefined variable" error when my function uses a variable it shouldn't! Twice this has given me very late nights of debugging! So how do other people deal with this sort of problem? Is there something like source(), but that makes an independent namespace that doesn't fall through to the main one? Making a package seems like one solution, but it seems like a big pain in the butt compared to e.g. Python, where a source file is automatically a separate namespace. Any tips? Thank you!

    Read the article

  • rails named_scope ignores eager loading

    - by Craig
    Two models (Rails 2.3.8): User; username & disabled properties; User has_one :profile Profile; full_name & hidden properties I am trying to create a named_scope that eliminate the disabled=1 and hidden=1 User-Profiles. The User model is usually used in conjunction with the Profile model, so I attempt to eager-load the Profile model (:include = :profile). I created a named_scope on the User model called 'visible': named_scope :visible, { :joins => "INNER JOIN profiles ON users.id=profiles.user_id", :conditions => ["users.disabled = ? AND profiles.hidden = ?", false, false] } I've noticed that when I use the named_scope in a query, the eager-loading instruction is ignored. Variation 1 - User model only: # UserController @users = User.find(:all) # User's Index view <% for user in @users %> <p><%= user.username %></p> <% end %> # generates a single query: SELECT * FROM `users` Variation 2 - use Profile model in view; lazy load Profile model # UserController @users = User.find(:all) # User's Index view <% for user in @users %> <p><%= user.username %></p> <p><%= user.profile.full_name %></p> <% end %> # generates multiple queries: SELECT * FROM `profiles` WHERE (`profiles`.user_id = 1) ORDER BY full_name ASC LIMIT 1 SHOW FIELDS FROM `profiles` SELECT * FROM `profiles` WHERE (`profiles`.user_id = 2) ORDER BY full_name ASC LIMIT 1 SELECT * FROM `profiles` WHERE (`profiles`.user_id = 3) ORDER BY full_name ASC LIMIT 1 SELECT * FROM `profiles` WHERE (`profiles`.user_id = 4) ORDER BY full_name ASC LIMIT 1 SELECT * FROM `profiles` WHERE (`profiles`.user_id = 5) ORDER BY full_name ASC LIMIT 1 SELECT * FROM `profiles` WHERE (`profiles`.user_id = 6) ORDER BY full_name ASC LIMIT 1 Variation 3 - eager load Profile model # UserController @users = User.find(:all, :include => :profile) #view; no changes # two queries SELECT * FROM `users` SELECT `profiles`.* FROM `profiles` WHERE (`profiles`.user_id IN (1,2,3,4,5,6)) Variation 4 - use name_scope, including eager-loading instruction #UserConroller @users = User.visible(:include => :profile) #view; no changes # generates multiple queries SELECT `users`.* FROM `users` INNER JOIN profiles ON users.id=profiles.user_id WHERE (users.disabled = 0 AND profiles.hidden = 0) SELECT * FROM `profiles` WHERE (`profiles`.user_id = 1) ORDER BY full_name ASC LIMIT 1 SELECT * FROM `profiles` WHERE (`profiles`.user_id = 2) ORDER BY full_name ASC LIMIT 1 SELECT * FROM `profiles` WHERE (`profiles`.user_id = 3) ORDER BY full_name ASC LIMIT 1 SELECT * FROM `profiles` WHERE (`profiles`.user_id = 4) ORDER BY full_name ASC LIMIT 1 Variation 4 does return the correct number of records, but also appears to be ignoring the eager-loading instruction. Is this an issue with cross-model named scopes? Perhaps I'm not using it correctly. Is this sort of situation handled better by Rails 3?

    Read the article

  • Scoping inside Javascript anonymous functions

    - by DCD
    I am trying to make a function return data from an ajax call that I can then use. The issue is the function itself is called by many objects, e.g.: function ajax_submit (obj) { var id = $(obj).attr('id'); var message = escape ($("#"+id+" .s_post").val ()); var submit_string = "action=post_message&message="+message; $.ajax({ type: "POST", url: document.location, data: submit_string, success: function(html, obj) { alert (html); } }); return false; } Which means that inside the anonymous 'success' function I have no way of knowing what the calling obj (or id) actually are. The only way I can think of doing it is to attach id to document but that just seems a bit too crude. Is there another way of doing this?

    Read the article

  • MySql scoping problem with correlated subqueries

    - by Rolf
    Hi, I'm having this Mysql query, It works: SELECT nom ,prenom ,(SELECT GROUP_CONCAT(category_en) FROM (SELECT DISTINCT category_en FROM categories c WHERE id IN (SELECT DISTINCT category_id FROM m3allems_to_categories m2c WHERE m3allem_id = 37) ) cS ) categories ,(SELECT GROUP_CONCAT(area_en) FROM (SELECT DISTINCT area_en FROM areas c WHERE id IN (SELECT DISTINCT area_id FROM m3allems_to_areas m2a WHERE m3allem_id = 37) ) aSq ) areas FROM m3allems m WHERE m.id = 37 The result is: nom prenom categories areas Man Multi Carpentry,Paint,Walls Beirut,Baalbak,Saida It works correclty, but only when i hardcode into the query the id that I want (37). I want it to work for all entries in the m3allem table, so I try this: SELECT nom ,prenom ,(SELECT GROUP_CONCAT(category_en) FROM (SELECT DISTINCT category_en FROM categories c WHERE id IN (SELECT DISTINCT category_id FROM m3allems_to_categories m2c WHERE m3allem_id = m.id) ) cS ) categories ,(SELECT GROUP_CONCAT(area_en) FROM (SELECT DISTINCT area_en FROM areas c WHERE id IN (SELECT DISTINCT area_id FROM m3allems_to_areas m2a WHERE m3allem_id = m.id) ) aSq ) areas FROM m3allems m And I get an error: Unknown column 'm.id' in 'where clause' Why? From the MySql manual: 13.2.8.7. Correlated Subqueries [...] Scoping rule: MySQL evaluates from inside to outside. So... do this not work when the subquery is in a SELECT section? I did not read anything about that. Does anyone know? What should I do? It took me a long time to build this query... I know it's a monster query but it gets what I want in a single query, and I am so close to getting it to work! Can anyone help?

    Read the article

  • Declaring local variables in assembly

    - by dcmoebius
    Is it possible to allocate locally-scoped memory in assembly? For example, consider the following (completely contrived) situation: I have two macros, one of which is dependent on the other. The first is: minimum MACRO dest, num1, num2 ; Finds the minimum of two unsigned numbers, stores the result in dest And the second is: tripMin MACRO dest, num1, num2, num3 ; Finds the minimum of three unsigned numbers, stores the result in dest minimum firstMin, num1, num2 minimum secondMin, num2, num3 minimum dest, firstMin, secondMin (I know that this isn't a realistic example for a variety of reasons, but bear with me.) Assuming that all the registers are otherwise occupied, is there any way to declare firstMin and secondMin locally within the macro? Or am I just better off freeing a register by pushing its value onto the stack and popping it back when I'm done?

    Read the article

  • Global variable life in Javascript - destroyed on a reload?

    - by Paul Nathan
    (I am learning Javascript) Problem: A page I am working on has 2 views, a data entry view with a textbox and a data rendering view. There is a a href src="currentpage#" link that switches between the 2 views. In order to transmit data from view to view, the javascript parses it from the current HTML and pushes it into the correct form for the other view. This is ugly and I want to refactor it out, ideally into some sort of global where it can be neatly rendered down into the view on command (I'm refactoring the code base to a point where I can AJAX it from a server). However, I am not certain about scoping rules and variable life in JS.

    Read the article

  • named_scope or find_by_sql?

    - by keruilin
    I have three models: User Award Trophy The associations are: User has many awards Trophy has many awards Award belongs to user Award belongs to trophy User has many trophies through awards Therefore, user_id is a fk in awards, and trophy_id is a fk in awards. In the Trophy model, which is an STI model, there's a trophy_type column. I want to return a list of users who have been awarded a specific trophy -- (trophy_type = 'GoldTrophy'). Users can be awarded the same trophy more than once. (I don't want distinct results.) Can I use a named_scope? How about chaining them? Or do I need to use find_by_sql? Either way, how would I code it?

    Read the article

  • scoping problem in recursive closure

    - by wiso
    why this work: def function1(): a = 10 def function2(): print a function2() but this not: def function1(): a = 10 def function2(): print a a -= 1 if a>0: function2() function2() error: UnboundLocalError: local variable 'a' referenced before assignment

    Read the article

  • Using StructureMap, how do you explicitly trigger the reinstantiation of a object with InstanceScope

    - by Mark Rogers
    I have an integration test harness where I want to teardown and then re-instantiate some of the singleton-scoped objects I've registered with StructureMap, after and before each test. This way I can simulate the actual run time environment, but not have the singleton's state being passed from one test to another. Maybe this isn't a great way to do an integration test, but I'm running out of alternative solutions (read open to any advice). So can an object with InstanceScope.Singleton, be re-instantiated? What's the best way to do re-instantiate a singleton-scoped object with StructureMap?

    Read the article

  • javascript scoping in for loop

    - by user121196
    consider the following javascript code, console.log always prints "focus 1" where 2 is the input length. how should I rewrite the code to prints the looping variable i correctly for (var i = 0; i < inputs.length; i++) { var curIndex = i; inputs[i].addListener('focus', function(thisfield, evt){ console.log('focus '+curIndex); }); }

    Read the article

  • executing named_scoped only when there are present params

    - by Luca Romagnoli
    Hi have a model like this: class EventDate < ActiveRecord::Base belongs_to :event named_scope :named, lambda { | name | { :joins => { :event => :core}, :conditions => ["name like ?", "%#{ name }%"] }} named_scope :date_range, lambda { | start, length | { :conditions => ["day >= ? AND day <= ?", start, date + (length || 30) ] }} it works correctly if i launch name = "ba" start = Date.today EventDate.named(name).date_range(start , start + 2) But if the name or the start is nil i don't want execute the named_scope like name = nil EventDate.named(name).date_range(start , start + 2) Is possible to set a condition inner the named_scope ? thanks

    Read the article

  • Nested asynchronous calls do not seem to execute as expected

    - by Kristof Van Landschoot
    While trying out jQuery, I have a question that is probably a newbie mistake, but I cannot seem to find the solution. This is the code: $.get("index.html", function() { var i = 0; for (; i < 3; i++) { var lDiv = document.createElement('div'); lDiv.id = 'body-' + i; document.getElementById('body').appendChild(lDiv); $.get('index.html', function(data) { lDiv.innerHTML = "<p>Hello World " + i + "</p>"; }); } }); The output seems to be <div id='body-0'></div> <div id='body-1'></div> <div id='body-2'> <p>Hello World 3</p> </div> I expected the lDiv.innerHTML= code to be executed for each i, but apparently it is only executed for the last i? What am I overlooking?

    Read the article

  • Redeclared javascript global variable overrides old value in IE

    - by Yousuf Haider
    (creating a separate question after comments on this: http://stackoverflow.com/questions/2634410/javascript-redeclared-global-variable-overrides-old-value) I am creating a globally scoped variable using the square bracket notation and assigning it a value inside an external js file. In another js file I declare a var with the same name as the one I just created above. Note I am not assigning a value. Since this is a redeclaration of the same variable the old value should not be overriden as described here: http://www.w3schools.com/js/js_variables.asp Create 2 javascript files with the following content : Script1 //create global variable with square bracket notation window['y'] = 'old'; Script2 //redeclaration of the same variable var y; if (!y) y = 'new'; alert(y); //shows New instead of Old in IE Include these 2 files in your html file <html> <head></head> <body> <script type="text/javascript" src="my.js"></script> <script type="text/javascript" src="my2.js"></script> </body> </html> Opening this page in Firefox and Chrome alerts 'old' which is the expected behavior. However in IE 8 the page will actually alert 'new' Any ideas on why this happens on IE ?

    Read the article

  • How transform this find_by_sql to named_scope?

    - by keruilin
    How can I possibly turn into named_scope? def self.hero_badge_awardees return User.find_by_sql("select users.*, awards.*, badges.badge_type from users, awards, badges where awards.user_id = users.id and badges.id = awards.badge_id and badges.badge_type = 'HeroBadge'") end

    Read the article

  • pthread and child process data sharing in C

    - by mustafabattal
    hi everyone, my question is somewhat conceptual, how is parent process' data shared with child process created by a "fork()" call or with a thread created by "pthread_create()" for example, are global variables directly passed into child process and if so, does modification on that variable made by child process effect value of it in parent process? i appreciate partial and complete answers in advance, if i'm missing any existing resource, i'm sorry, i've done some search on google but couldn't find good results thanks again for your time and answers

    Read the article

  • In Objective C, is there a way to call reference a typdef enum from another class?

    - by Adrian Harris Crowne
    It is my understanding that typedef enums are globally scoped, but if I created an enum outside of the @interface of RandomViewController.h, I can't figure out how to access it from OtherViewController.m. Is there a way to do this? So... "RandomViewController.h" #import <UIKit/UIKit.h> typedef enum { EnumOne, EnumTwo }EnumType; @interface RandomViewController : UIViewController { } and then... "OtherViewController.m" -(void) checkArray{ BOOL inArray = [randomViewController checkArray:(EnumType)EnumOne]; }

    Read the article

  • How to filter results by multiple fields?

    - by hadees
    I am working on a survey application in ruby on rails and on the results page I want to let users filter the answers by a bunch of demographic questions I asked at the start of the survey. For example I asked users what their gender and career was. So I was thinking of having dropdowns for gender and career. Both dropdowns would default to all but if a user selected female and marketer then my results page would so only answers from female marketers. I think the right way of doing this is to use named_scopes where I have a named_scope for every one of my demographic questions, in this example gender and career, which would take in a sanitized value from the dropdown to use at the conditional but i'm unsure on how to dynamically create the named_scope chain since I have like 5 demographic questions and presumably some of them are going to be set to all.

    Read the article

  • PHP: prevent invocation of method X from from context != Y

    - by sunwukung
    This is a tricky one. I am "emulating" ZF Bootstrapping (surface appearance). Don't ask me why, call it academic interest. So I have a Bootstrap Abstract with a method "run" that iterates over itself to locate any methods prefixed with "init". The application looks for a user defined class which extends this class, in which the user can define any number of methods in this way. However, I want to prevent the user from being able to execute the "run" command of it's parent class, while still exposing the same command for the client code. Anyone got any thoughts/advice/guidance? regards SWK

    Read the article

  • Global and local variables in my script

    - by Acorn
    I'm starting out learning javascript, and tried to write a little script that would make a grid of divs on a page. Here's the script: var tileWidth=50; var tileHeight=100; var leftPos=10; var topPos=10; var columns=10; var rows=10; var spacing=5; $('document').ready(function() { placeTiles(); }); function makeRow() { for (var i=0; i<columns; i++) { $('#canvas').append('<div class="tile" style="left:' + leftPos + 'px;top:' + topPos + 'px;"></div>'); var leftPos = leftPos + tileWidth + spacing; } } function placeTiles() { for (var i=0; i<rows; i++) { makeRow(); var topPos = topPos + tileHeight + spacing; } } At the moment, 100 <div>s get created, all with a top position of 10px and a left position of undefined (for the first <div> in the row) or NaN. What should I be doing differently? Why can't makerow() see my global leftPos variable (and all the other variables for that matter)? Thanks.

    Read the article

  • Accessing ViewController's variables from UIActionSheet delegate

    - by VansFannel
    Hello. I have the following code: @implementation SendMapViewController NSMutableArray *emails; At this method I create emails array and I add some NSStrings: - (BOOL) peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson: (ABRecordRef)person { ABMultiValueRef emailInfo = ABRecordCopyValue(person, kABPersonEmailProperty); NSUInteger emailCount = ABMultiValueGetCount(emailInfo); if (emailCount > 1) { UIActionSheet *emailsAlert = [[UIActionSheet alloc] initWithTitle:@"Select an email" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; emails = [NSMutableArray arrayWithCapacity: emailCount]; for (NSUInteger i = 0; i < emailCount; i++) { NSString *emailFromContact = (NSString *)ABMultiValueCopyValueAtIndex(emailInfo, i); [emails addObject: emailFromContact]; [emailsAlert addButtonWithTitle:emailFromContact]; [emailFromContact release]; } [emailsAlert addButtonWithTitle:@"Cancel"]; [emailsAlert showInView:self.view]; [emailsAlert release]; } else { ... } CFRelease(emailInfo); [self dismissModalViewControllerAnimated:YES]; return NO; } As you can see in code, if there are more than one email I show and UIActionSheet. When user clicks on a button representing and email, I want to execute the following code: - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if ([emails count] >= buttonIndex) { NSString *contactEmail = (NSString *)[emails objectAtIndex:buttonIndex]; ... } } But emails array hasn't got any email. What I'm doing wrong? I'm developing for iPhone.

    Read the article

  • functions inside or outside jquery document ready

    - by Hans
    Up until now I just put all my jQuery goodness inside the $(document).ready() function, including simple functions used in certain user interactions. But functions that don´t require the DOM document to be loaded or are only called afterwards anyway, can be placed outside the $(document).ready() as well. Consider for example a very simple validation function such as: function hexvalidate(color) { // Validates 3-digit or 6-digit hex color codes var reg = /^(#)?([0-9a-fA-F]{3})([0-9a-fA-F]{3})?$/; return reg.test(color); } The function is only called from within the $(document).ready() function though. What is best practice (syntax, speed); placing such a function inside or outside the jquery document ready function?

    Read the article

  • PHP: friend classes and ungreedy caller function/class

    - by avetis.kazarian
    Is there any way to get the caller function with something else than debug_backtrace()? I'm looking for a less greedy way to simulate scopes like friend or internal. Let's say I have a class A and a class B. Until now, I've been using debug_backtrace(), which is too greedy (IMHO). I thought of something like this: <?php class A { public function __construct(B $callerObj) {} } class B { public function someMethod() { $obj = new A($this); } } ?> It might be OK if you want to limit it to one specific class, but let's say I have 300 classes, and I want to limit it to 25 of them? One way could be using an interface to aggregate: public function __construct(CallerInterface $callerObj) But it's still an ugly code. Moreover, you can't use that trick with static classes. Have any better idea?

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >