Search Results

Search found 5915 results on 237 pages for 'practices'.

Page 115/237 | < Previous Page | 111 112 113 114 115 116 117 118 119 120 121 122  | Next Page >

  • jquery: How to deal with 'this' in ajax callbacks

    - by Svish
    I currently have code similar to this for a form: $('#some-form') .submit(function() { // Make sure we are not already busy if($(this).data('busy')) return false; $(this).data('busy', true); // Do post $.post("some/url", $(this).serialize(), function(data) { if(data.success) // Success is a boolean I set in the result on the server { // Deal with data } else { // Display error } $('#some-form') .removeData('busy'); }); return false; }); My issue is that I would like to somehow remove the need for knowing the form id in the post callback. In the end where I remove the busy data from the form, I'd like to somehow not have that hard coded. Is there any way I can do this? Is there a way I can hand whatever is in this to the post callback function? Since I know the id right now, I can get around it by doing what I have done, but I'd like to know how to not be dependant on knowing the id, since often I don't have an id. (For example if I have a link in each row in a table and all the rows have the same click handler.

    Read the article

  • Java: Inputting text from a file using split

    - by 00PS
    I am inputting an adjacency list for a graph. There are three columns of data (vertex, destination, edge) separated by a single space. Here is my implementation so far: FileStream in = new FileStream("input1.txt"); Scanner s = new Scanner(in); String buffer; String [] line = null; while (s.hasNext()) { buffer = s.nextLine(); line = buffer.split("\\s+"); g.add(line[0]); System.out.println("Added vertex " + line[0] + "."); g.addEdge(line[0], line[1], Integer.parseInt(line[2])); System.out.println("Added edge from " + line[0] + " to " + line[1] + " with a weight of " + Integer.parseInt(line[2]) + "."); } System.out.println("Size of graph = " + g.size()); Here is the output: Added vertex a. Added edge from a to b with a weight of 9. Exception in thread "main" java.lang.NullPointerException at structure5.GraphListDirected.addEdge(GraphListDirected.java:93) at Driver.main(Driver.java:28) I was under the impression that line = buffer.split("\\s+"); would return a 2 dimensional array of Strings to the variable line. It seemed to work the first time but not the second. Any thoughts? I would also like some feedback on my implementation of this problem. Is there a better way? Anything to help out a novice! :)

    Read the article

  • Double use of variables?

    - by Vaccano
    I have read that a variable should never do more than one thing. Overloading a variable to do more than one thing is bad. Because of that I end up writing code like this: (With the customerFound variable) bool customerFound = false; Customer foundCustomer = null; if (currentCustomer.IsLoaded) { if (customerIDToFind = currentCustomer.ID) { foundCustomer = currentCustomer; customerFound = true; } } else { foreach (Customer customer in allCustomers) { if (customerIDToFind = customer.ID) { foundCustomer = customer; customerFound = true; } } } if (customerFound) { // Do something } But deep down inside, I sometimes want to write my code like this: (Without the foundCustomer variable) Customer foundCustomer = null; if (currentCustomer.IsLoaded) { if (customerIDToFind = currentCustomer.ID) { foundCustomer = currentCustomer; } } else { foreach (Customer customer in allCustomers) { if (customerIDToFind = customer.ID) { foundCustomer = customer; } } } if (foundCustomer != null) { // Do something } Does this secret desires make me an evil programmer? (i.e. is the second case really bad coding practice?)

    Read the article

  • When should I implement IDisposeable?

    - by Bobby
    What is the best practice for when to implement IDisposeable? Is the best rule of thumb to implement it if you have one managed object in the class, or does it depend if the object was created in the class or just passed in? Should I also do it for classes with no managed objects at all?

    Read the article

  • Static method,new thread performance question

    - by ylazez
    Hey guys i just have two questions about two methods used in many controllers/servlets in my app: 1-what is the difference between calling a static method in a util class or a non static method (like methods dealing with dates i.e getting current time,converting between timezones), which is better ? 2-what is the difference between calling a method(contain too many logic like sending emails) in the controller directly or running this method in a different thread ?

    Read the article

  • Why is 'using namespace std;' considered a bad practice in C++?

    - by Mana
    Okay, sorry for the simplistic question, but this has been bugging me ever since I finished high school C++ last year. I've been told by others on numerous occasions that my teacher was wrong in saying that we should have "using namespace std;" in our programs, and that std::cout and std::cin are more proper. However, they would always be vague as to why this is a bad practice. So, I'm asking now: Why is "using namespace std;" considered bad? Is it really that inefficient, or risk declaring ambiguous vars(variables that share the same name as a function in std namespace) that much? Or does this impact program performance noticeably as you get into writing larger applications? I'm sorry if this is something I should have googled to solve; I figured it would be nice to have this question on here regardless in case anyone else was wondering.

    Read the article

  • Tags php improving database speed and user experience

    - by Doodle
    How did stackOverFlow, excuse me if it wasn't the first implementation of this system. Decide what its initial tags where? I want to provide users with the best experience on my site and am implementing a tags system. I don't care about search engines or any of that. I just care about my users. Does any one have any advice about things that have failed or succeeded when they allowed users to tag things? Does any one know some good resources about the methodologies of user tagging? Does any one know some good resources about implementing a tags system from a programming perspective, database structures, theories, etc ? I'll give my check to who ever I feel points me in the best direction on the subject.

    Read the article

  • Java Interfaces Methodology: Should every class implement an interface?

    - by Amir Rachum
    I've been programming in Java for a few courses in the University and I have the following question: Is it methodologically accepted that every class should implement an interface? Is it considered bad practice not to do so? Can you describe a situation where it's not a good idea to use interfaces? Edit: Personally, I like the notion of using Interfaces for everything as a methodology and habit, even if it's not clearly beneficial. Eclipse automatically created a class file with all the methods, so it doesn't waste any time anyway.

    Read the article

  • Could this be considered a well-written class (am I using OOP correctly)?

    - by Ben Dauphinee
    I have been learning OOP principals on my own for a while, and taken a few cracks at writing classes. What I really need to know now is if I am actually using what I have learned correctly, or if I could improve as far as OOP is concerned. I have chopped a massive portion of code out of a class that I have been working on for a while now, and pasted it here. To all you skilled and knowledgeable programmers here I ask: Am I doing it wrong? class acl extends genericAPI{ // -- Copied from genericAPI class protected final function sanityCheck($what, $check, $vars){ switch($check){ case 'set': if(isset($vars[$what])){return(1);}else{return(0);} break; } } // --------------------------------- protected $db = null; protected $dataQuery = null; public function __construct(Zend_Db_Adapter_Abstract $db, $config = array()){ $this->db = $db; if(!empty($config)){$this->config = $config;} } protected function _buildQuery($selectType = null, $vars = array()){ // Removed switches for simplicity sake $this->dataQuery = $this->db->select( )->from( $this->config['table_users'], array('tf' => '(CASE WHEN count(*) > 0 THEN 1 ELSE 0 END)') )->where( $this->config['uidcol'] . ' = ?', $vars['uid'] ); } protected function _sanityRun_acl($sanitycheck, &$vars){ switch($sanitycheck){ case 'uid_set': if(!$this->sanityCheck('uid', 'set', $vars)){ throw new Exception(ERR_ACL_NOUID); } $vars['uid'] = settype($vars['uid'], 'integer'); break; } } private function user($action = null, $vars = array()){ switch($action){ case 'exists': $this->_sanityRun_acl('uid_set', $vars); $this->_buildQuery('user_exists_idcheck', $vars); return($this->db->fetchOne($this->dataQuery->__toString())); break; } } public function user_exists($uid){ return($this->user('exists', array('uid' => $uid))); } } $return = $acl_test->user_exists(1);

    Read the article

  • Best practice to detect iPhone app only access for web services?

    - by Gaius Parx
    I am developing an iPhone app together with web services. The iPhone app will use GET or POST to retrieve data from the web services such as http://www.myserver.com/api/top10songs.json to get data for top ten songs for example. There is no user account and password for the iPhone app. What is the best practice to ensure that only my iPhone app have access to the web API http://www.myserver.com/api/top10songs.json? iPhone SDK's UIDevice uniqueueIdentifier is not sufficient as anyone can fake the device id as parameter making the API call using wget, curl or web browsers. The web services API will not be published. The data of the web services is not secret and private, I just want to prevent abuse as there are also API to write some data to the server such as usage log.

    Read the article

  • database design - empty fields

    - by imanc
    Hey, I am currently debating an issue with a guy on my dev team. He believes that empty fields are bad news. For instance, if we have a customer details table that stores data for customers from different countries, and each country has a slightly different address configuration - plus 1-2 extra fields, e.g. French customer details may also store details for entry code, and floor/level plus title fields (madamme, etc.). South Africa would have a security number. And so on. Given that we're talking about minor variances my idea is to put all of the fields into the table and use what is needed on each form. My colleague believes we should have a separate table with extra data. E.g. customer_info_fr. But this seams to totally defeat the purpose of a combined table in the first place. His argument is that empty fields / columns is bad - but I'm struggling to find justification in terms of database design principles for or against this argument and preferred solutions. Another option is a separate mini EAV table that stores extra data with parent_id, key, val fields. Or to serialise extra data into an extra_data column in the main customer_data table. I think I am confused because what I'm discussing is not covered by 3NF which is what I would typically use as a reference for how to structure data. So my question specifically: - if you have slight variances in data for each record (1-2 different fields for instance) what is the best way to proceed?

    Read the article

  • MySQL indexes - what are the best practises?

    - by Haroldo
    I've been using indexes on my mysql databases for a while now but never properly learnt about them. Generally I put an index on any fields that i will be searching or selecting using a WHERE clause but sometimes it doesn't seem so black and white. What are the best practises for mysql indexes? example situations/dilemas: If a table has six columns and all of them are searchable, should i index all of them or none of them? . What are the negetive performance impacts of indexing? . If i have a VARCHAR 2500 column which is searchable from parts of my site, should i index it?

    Read the article

  • When to use basic types (Integer, String), and when to write a new class?

    - by belgarat
    Stackoverflow users: A lot of things can be represented in programs by using the basic types, or we can create a new class for it. Example: A social security number can be a number, string or its own object. (Other common examples: Phone numbers, names, zip codes, user id, order id and other id's.) My question is: When should the basic types be used, and when should we write ourselves a new class? I see that when you need to add behavior, you'll want to create a class (example, social security number parsing, validation, formatting, etc). But is this the only criteria? I have come across cases where many of these things are represented as java Integers and/or Strings. We loose the benefit of type-checking, and I have often seen bugs caused by parameters being mixed in calls to function(Intever, Integer, Integer, Integer). On the other hand, some programmers are opposed to over-designing by creating classes for "eveything". Obviously, the answer is "it depends". But, what do you think, and what do you normally do?

    Read the article

  • android thread management onPause

    - by Kwan Cheng
    I have a class that extends the Thread class and has its run method implemented as so. public void run(){ while(!terminate){ if(paused){ Thread.yield(); }else{ accummulator++; } } } This thread is spawned from the onCreate method. When my UI is hidden (when the Home key is pressed) my onPause method will set the paused flag to true and yield the tread. However in the DDMS I still see the uTime of the thread accumulate and its state as "running". So my question is. What is the proper way to stop the thread so that it does not use up CPU time?

    Read the article

  • Rails: Pass association object to the View

    - by Fedyashev Nikita
    Model Item belongs_to User. In my controller I have code like this: @items = Item.find(:all) I need to have a corresponding User models for each item in my View templates. it works in controller(but not in View template): @items.each { |item| item.user } But manual looping just to build associations for View template kinda smells. How can I do this not in a creepy way?

    Read the article

  • group by country with ActiveRecords in Rails

    - by Adnan
    Hello, I have a table with users: name | country | .. | UK | .. | US | .. | US | .. | UK | .. | FR | .. | FR | .. | UK | .. | UK | .. | DE | .. | DE | .. | UK | .. | CA | . . What is the most efficient way with ActiveRecords to get the list of countries in my view and for each country how many users are from, so: US 123 UK 54 DE 33 . . .

    Read the article

  • how to get started with TopCoder to update/develop algorithm skills ?

    - by KaluSingh Gabbar
    at workplace, the work I do is hardly near to challenging and doing that I think I might be loosing the skills to look at a completely new problem and think about different ideas to solve it. A friend suggested TopCoder.com to me, but looking at the overwhelming number of problems I can not decide how to get started? what I want is to sharpen my techniques ( not particular language or framework ).

    Read the article

  • slowing down a loop in a recursive function

    - by eco_bach
    I have a difficult problem with a recursive function. Essentially I need to 'slow down' a for loop within a function that repeatedly calls itself(the function); Is this possible, or do I need to somehow extract the recursive nature of the function? function callRecursiveFuncAgain(ob:Object):void{ //do recursive stuff; for (var i:int = 0; i < 4; i++) { _nextObj=foo callRecursiveFuncAgain(_nextObj); } }

    Read the article

  • Is there a case for parameterising using Abstract classes rather than Interfaces?

    - by Chris
    I'm currently developing a component based API that is heavily stateful. The top level components implement around a dozen interfaces each. The stock top-level components therefore sit ontop of a stack of Abstract implementations which in turn contain multiple mixin implementations and implement multiple mixin interfaces. So far, so good (I hope). The problem is that the base functionality is extremely complex to implement (1,000s of lines in 5 layers of base classes) and therefore I do not wish for component writers to implement the interfaces themselves but rather to extend my base classes (where all the boiler plate code is already written). If the API therefore accepts interfaces rather than references to the Abstract implementation that I wish for component writers to extends, then I have a risk that the implementer will not perform the validation that is both required and assumed by other areas of code. Therefore, my question is, is it sometimes valid to paramerise API methods using an abstract implementation reference rather than a reference to the interface(s) that it implements? Do you have an example of a well-designed API that uses this technique or am I trying to talk myself into bad-practice?

    Read the article

  • Identifying a class which is extending an abstract class

    - by Simon A. Eugster
    Good Evening, I'm doing a major refactoring of http://wiki2xhtml.sourceforge.net/ to finally get better overview and maintainability. (I started the project when I decided to start programming, so – you get it, right? ;)) At the moment I wonder how to solve the problem I'll describe now: Every file will be put through several parsers (like one for links, one for tables, one for images, etc.): public class WikiLinks extends WikiTask { ... } public class WikiTables extends WikiTask { ... } The files will then be parsed about this way: public void parse() { if (!parse) return; WikiTask task = new WikiLinks(); do { task.parse(this); } while ((task = task.nextTask()) != null); } Sometimes I may want to use no parser at all (for files that only need to be copied), or only a chosen one (e.g. for testing purposes). So before running task.parse() I need to check whether this certain parser is actually necessary/desired. (Perhaps via Blacklist or Whitelist.) What would you suggest for comparing? An ID for each WikiTask (how to do?)? Comparing the task Object itself against a new instance of a WikiTask (overhead)?

    Read the article

  • The standard map/associative-array structure to use in flash actionscript 3?

    - by tstyle
    I'm relatively new to flash, and is confused about what I should use to store and retrieve key value pairs. After some googling I've found various map-like things to choose from: 1) Use a Object: var map:Object = new Object(); map["key"] = "value"; The problem is that it seems to lack some very basic features. For example to even get the size of map I'd have to write a util method. 2) Use a Dictionary What does this standard library class provide over the simple object? It seems silly for it to exist if it's functionally identical to Object. 3) Go download some custom HashMap/HashTable implementation from the web. I've used a lot of modern languages, and this is the first time I haven't been able to find a library implementation of an associative array within 5 minutes. So I'd like to get some best-practice advice from an experienced flash developer. Thanks!

    Read the article

  • Asynchronous SQL Operations

    - by Paul Hatcherian
    I've got a problem I'm not sure how best to solve. I have an application which updates a database in response to ad hoc requests. One request in particular is quite common. The request is an update that by itself is quite simple, but has some complex preconditions. For this request the business layer first requests a set of data from the data layer. The business logic layer evaluated the data from the database and parameters from the request, from this the action to be performed is determined, and the request's response message(s) are created. The business layer now executes the actual update command that is the purpose of the request. This last step is the problem, this command is dependent on the state of the database, which might have changed since the business logic ran. Locking down the data read in this operation across several round-trips to the database doesn't seem like a good idea either. Is there a 'best-practice' way to accomplish something like this? Thanks!

    Read the article

  • Forward a call to a webservice to another webservice?

    - by Luhmann
    If I have an https webservice behind a firewall on a machine (A) that I cannot access, but access to a machine on the same network (B), from where I can call the webservice on machine A. What is the best way of talking with the webservice on machine A, from the outside via machine B (that I access via VPN)? I can obviously create a service with a matching interface on machine B, and call the methods on the webservice on machine A, and return the result. But I fear for the overhead. Is there another way? Can i somehow forward the request?

    Read the article

  • where should I do the calculating stuff,PHP or Mysql?

    - by SpawnCxy
    I've been doing a lot of calculating stuff nowadays.Usually I prefer to do this job in PHP rather than Mysql though I know PHP is not good at this cuz I thought mysql may be worse.But I found some performance problem :some pages were loaded so slowly that 30 seconds' timelimit is not enough for them!So I wonder which is the better practice to do the calculations,and any princles for that?Suggestions would be appreciated.

    Read the article

< Previous Page | 111 112 113 114 115 116 117 118 119 120 121 122  | Next Page >