Search Results

Search found 91526 results on 3662 pages for 'clean code'.

Page 215/3662 | < Previous Page | 211 212 213 214 215 216 217 218 219 220 221 222  | Next Page >

  • Optimizing PHP code (trying to determine min/max/between case)

    - by Swizzh
    I know this code-bit does not conform very much to best coding practices, and was looking to improve it, any ideas? if ($query['date_min'] != _get_date_today()) $mode_min = true; if ($query['date_max'] != _get_date_today()) $mode_max = true; if ($mode_max && $mode_min) $mode = "between"; elseif ($mode_max && !$mode_min) $mode = "max"; elseif (!$mode_max && $mode_min) $mode = "min"; else return; if ($mode == "min" || $mode == "between") { $command_min = "A"; } if ($mode == "max" || $mode == "between") { $command_max = "B"; } if ($mode == "between") { $command = $command_min . " AND " . $command_max; } else { if ($mode == "min") $command = $command_min; if ($mode == "max") $command = $command_max; } echo $command;

    Read the article

  • Using a message class static method taking in an action to wrap Try/Catch

    - by Chris Marisic
    I have a Result object that lets me pass around a List of event messages and I can check whether an action was successful or not. I've realized I've written this code in alot of places Result result; try { //Do Something ... //New result is automatically a success for not having any errors in it result = new Result(); } catch (Exception exception) { //Extension method that returns a Result from the exception result = exception.ToResult(); } if(result.Success) .... What I'm considering is replacing this usage with public static Result CatchException(Action action) { try { action(); return new Result(); } catch (Exception exception) { return exception.ToResult(); } } And then use it like var result = Result.CatchException(() => _model.Save(something)); Does anyone feel there's anything wrong with this or that I'm trading reusability for obscurity?

    Read the article

  • Error with my JQuery code in IE but not Firefox

    - by Kaz Lee
    Guys, I have this code below which works in firefox and all others except in IE. Am I making a syntaxt error somewhere? Can't seem to find it and its driving me nuts. Any help is appreciated! <script> $(document).ready(function(){ $("label:contains('Number')").html("Register:"); $("input[type='textbox']").each(function(){ var name = $(this).attr('name'); // grab name of original /* create new visible input */ var html = '<input type="checkbox" class="NetscapeFix" size="4" maxlength="5" name="'+name+'" id="'+name+'" value="1" dir="rtl" />'; $(this).after(html).remove(); // add new, then remove original input }); }); </script> Thank you, Kaz

    Read the article

  • What is wrong with this c strdup code?

    - by bstullkid
    Consider this code: char *strs[] = { "string1", "string2", NULL }; char *ptr1 = NULL, *ptr2 = NULL, *tmp; short iter = 0; tmp = ptr1; while (iter < 2) { tmp = strdup(strs[iter]); tmp = ptr2; iter++; } printf("1: %s\n2: %s\n", ptr1, ptr2); I want this to output "string1\nstring2\n" however str1 and str2 remain null. What am I doing wrong?

    Read the article

  • Creating Wiki Pages through code or CAML

    - by Joe Capka
    We are trying to create a site definition that includes a wiki page. Basically we are trying to figure out how to replicate the same process that happens when a user chooses to create a new page in a blank site, and the system says something along the lines of: "In order to create wiki pages on this site, there must be a default wiki page library and site assets library. Would you like to create those document libraries now?" When the user chooses yes, the system provisions those libraries as well as a few "howto" wiki pages. If anyone knows how to trigger that roll-out though code or CAML, we would appreciate the help.

    Read the article

  • Partially parse C++ for a domain-specific language

    - by PierreBdR
    I would like to create a domain specific language as an augmented-C++ language. I will need mostly two types of contructs: Top-level constructs for specialized types or declarations In-code constructs, i.e. to add primitives to make functions calls or idiom easier The language will be used for scientific computing purposes, and will ultimately be translated into plain C++. C++ has been chosen as it seems to offer a good compromise between: ease of use, efficiency and availability of a wide range of libraries. A previous attempt using flex and bison failed due to the complexity of the C++ syntax. The existing parser can still fail on some constructs. So we want to start over, but on better bases. Do you know about similar projects? And if you attempted to do so, what tools would you use? What would be the main pitfalls? Would you have recommendations in term of syntax?

    Read the article

  • iPhone/iPad fatal error in C++ code produces no output in the log

    - by morgancodes
    I'm trying to move away from Objective-C to C++ for audio in my iPad programming, due to the a few reports I've heard of Objective-C selectors sometimes causing audio glitches. So I'm starting to use pure C++ files. When a fatal error happens in one of the C++ files, I get no output from the log. The app just crashes. For example, if I do this in my C++ file: env = new ADSR(); cout << "setting env to null\n"; env = NULL; env->setSustainLevel(1); cout << "called function on non-initialized env\n"; I get the following output: setting env to null After that, there's a method called on NULL, which apparently kills the app, but absolutely nothing to that effect is reported. What do I need to do to have useful information logged when there's an error in my C++ code?

    Read the article

  • HTML reuse, create template

    - by nanonerd
    After about a year doing Asp.net web forms, I stepped out (for the most part) from the .net world. I'm now working on a webapp that uses a lot of client side scripting and uses WebAPI for data access. I have a HTML section that allows note taking. I would like to make this HTML section into a template that I can reuse elsewhere on the site (e.g., insert this piece of HTML code into another web page). I'm a bit befuddled on how to go about this. Think of my problem as trying to create a "user control" in asp.net web forms ... only that I am not using web forms. Just good old fashioned HTML, CSS, Javascript, jquery, and knockout. Conceptually, I'd think that others have been in the same spot as myself. Can anyone elaborate a solution or at least provide some pointers? Thanks !

    Read the article

  • why am i getting an error SyntaxError : invalid syntax for this code

    - by eragon1189
    This is a code in python which calculates f (x) =? ((-1)*x)/(x*x+n*n) n from 1 to infinite.... correct to 0.0001, for the range 1 < x < 100 in steps of 0.1.But i am getting an syntax error,as i am new to programming in python... from scipy import * from matplotlib.pyplot import * x=arange(0.1,100,0.1) f=zeros(len(x)) s=-1 for n in range (1,10000): t=s*x/(x*x+n*n) f +=t s =-s if max(abs(t))< 1e-4 break for xx in c_[x,f]: print "%f %f" % (xx[0],xx[1])

    Read the article

  • Why does this code crash?

    - by user146780
    The following code causes a stack overflow but I don't see why... int _tmain(int argc, _TCHAR* argv[]) { cout << "start"; char bmp[1024][768][3]; for (int p = 0; p < 9000; ++p) { for(int i = 0; i < 1024; ++i) { for(int j = 0; j < 768; ++j) { bmp[i][j][0] = 20; } } } cout << "Stop"; return 0; } Thanks

    Read the article

  • How can I remove the head of a main function?

    - by Nathan McDavitt-Van Fleet
    I am trying to move some code from a seperate binary and have it inside my main program. Unfortunately I can't mimic the initialization variables for the main function. How can I create argc and argv by hand? Can someone give me some example assignments. since it looks like this: int main(int argc, char *argv[]) I figured I could assign them like this: int argc=1; char *argv[0]="Example"; But it doesn't work. Can anyone tell me how this might be done?

    Read the article

  • Converting table based layout into a div/css based one.

    - by nimo9367
    I'm supposed to rewrite the UI for a rather large web application. The thing is that the layout is completely based on tables and if I could somehow, semi automatically, convert the tables into divs it would save me a huge amount of time. What are the best practices when doing something like this? Is this a good idea at all? The application use layout files (containing something similar to helpers) that are parsed into html at runtime and the application itself also output html at specific places. So the work will consist of converting these helpers and the htmloutput code within the application.

    Read the article

  • [multiple issues] Customizing Xcode [fonts, code sense, and more]

    - by wwrob
    How can I make code completion case-sensitive? How can I make Ctrl-k kill the content of the line and the new line character? How can I make backspace always delete only one character, no matter what it is? Right now, it deletes spaces in chunks equal to my indent level. How to change the indentation style in file templates? I like to have the opening brace on its own line. How can I make the font aliased? EDIT: Issues 4 and 5 are solved. 1 through 3 are still open.

    Read the article

  • Sharing logic across different platforms

    - by Pranz
    Hello all, We have a business logic that works with the file systems on OS that we want to implement on both Linux and Windows platforms. The language we have selected is Python for Linux and C# for Windows. GUI is not a priority for now. We were looking for ways to abstract the business logic in a way that we dont have to repeat the business logic (ofcourse I understand since it is related to file system, some code will differ from platform to platform). Any ideas on how to implement it? Is C/C++ the only option. We dont want to use Java. Thanks, Pranz

    Read the article

  • Why did this code still work?

    - by bstullkid
    Some old code that I just came across: MLIST * new_mlist_link() { MLIST *new_link = (MLIST * ) malloc(sizeof(MLIST)); new_link->next = NULL; new_link->mapi = NULL; new_link->result = 0; } This was being called to build a linked list, however I noticed there is no statement: return new_link; Even without the return statement there, the list still got built properly. Why did this happen? EDT: Platform: Mandriva 2009 64bit Linux 2.6.24.7-server GCC 4.2.3-6mnb1

    Read the article

  • Game Objects Talking To Each Other

    - by PhilCK
    What is a good way of dealing with objects and having them talk to each other? Up until now all my games hobby/student have been small so this problem was generally solved in a rather ugly way, which lead to tight integration and circular dependencies. Which was fine for the size of projects I was doing. However my projects have been getting bigger in size and complexity and now I want to start re-using code, and making my head a simpler place. The main problem I have is generally along the lines of Player needs to know about the Map and so does the Enemy, this has usually descended into setting lots of pointers and having lots of dependencies, and this becomes a mess quickly. I have thought along the lines of a message style system. but I cant really see how this reduces the dependencies, as I would still be sending the pointers everywhere. Thanks. PS: I guess this has been discussed before, but I don't know what its called just the need I have.

    Read the article

  • Is there any way to view PHP code (the actual code not the compiled result) from a client machine?

    - by Columbo
    This may be a really stupid question...I started worrying last night that there might be someway to view PHP files on a server via a browser or someother means on a client machine. My worry is, I have an include file that contains the database username and password. If there were a way to put the address of this file in to a browser or some other system and see the code itself then it would be an issue for obvious reasons. Is this a legitimate concern? If so how do people go about preventing this?

    Read the article

  • Using 'ref code' related to the spinner option chosen

    - by user1508541
    I am trying to add a spinner function in a trial app which compares the frequency charts of earphones. I am trying to extract the info from " http://www.headphone.com/learning-center/build-a-graph.php " website. what I want to do is make the spinner work like the drop down list in the mentioned website. On further inspection what I found was that every dropdown element is provided with a unique code that is called when the particular element is selected. I need help in replicating the same in an android spinner.

    Read the article

  • change label text from a VB6 binary (not source code)

    - by Jun
    Hi, we have a VB6 binary executable that comes with no source code. And we need to change the label text for that VB6 application from "AAA" to "BBB". Is there any way or tools that can do that? The closest tool I can find right now is microsoft UISpy, it can read all the other elements but not the label. I hope there is a tool that can change the resource in the .exe so that the label "AAA" will read "BBB". Or is it possible to write a wrapper application, it will launch the .exe, examine the application screen for "AAA" and change that to "BBB"? Thank you for your help!

    Read the article

  • how to submit using link with my current code(php+jquery+ajax)

    - by ruslyrossi
    My current Code : <script type="text/javascript"> $(document).ready(function() { $('#form').ajaxForm( { target: '#preview', success: function() { $('#success_box').addClass('success') setTimeout(function() { $('#success_box').fadeOut('slow'); }, 3100); // <-- time in milliseconds } }); }); </script> <form action="controller/product_edit_update.php" method="post" id="form" name="form" > bla..bla.. <input type="submit" value="Save" /></form> but now i want to add submit link with <a href="" id="submit_with_link" >Save</a>

    Read the article

  • Display indented XML code within a HTML page

    - by Efrain
    I have a programmatically created HTML document on which I would like to show some XML-code, fully formatted with line breaks and tabulators. That is, it should look like if you drag an xml file without a xml-stylesheet directly onto your browser (most browsers do some kind of xml-rendering with some default style sheet). Now, I can of course escape all the characters (like <>, tab and newline) and do the indenting myself (using css styles, for example), but I was wondering whether I couldn't re-use some 'default' xml-stylesheet from somewhere. Preferrably also one that has some javascript node-folding, too. Do you know such a stylesheet/xslt? Or would you suggest another way to achieve this? I'm using C#. PS: I tried to use the XmlNotepad.DefaultSS.xslt from Microsoft's XmlNotepad, but I couldn't really get that working. :T

    Read the article

  • Find Javascript Code inside String

    - by Ph.E
    Greetings friends, I am developing a web application that will allow the customer to enter a personalized message, which will then be converted to HTML. Well, the problem is that I can not allow the insertion of Javascript code. So I need a method that filters the text, searching for and remove it. I think the regular expressions to solve my problem, but I'm having difficulty building. Some of his friends could help me, or has already developed something for this. Thank you.

    Read the article

  • How to start an android project with downloaded sample code

    - by yokyo
    Hi, I'm pretty new to android, and just finished setup my environment and reading some tutorials. Then I got sdk samples from the web. Okay, what I wanna ask you is that is there a way to start a sample as a project in the Eclipse? I mean like clicking a project file in c# or a solution file. Here is my folder which I unzipped the code, \android-sdk-windows\samples\android-8\NotePad There are three folders and one file in the folder, \res, \src, \tests, and AndroidManifest.xml Or, do I need to make a new android project and import (or add files? maybe) them? Thanks in advance, yokyo

    Read the article

  • ASP.NET equivalent of this PHP code

    - by moiz217
    Please provide asp.net equivalent of this php code. $ip = $_REQUEST['ip']?$_REQUEST['ip']:$_SERVER["REMOTE_ADDR"]; $client = new SoapClient(null, array( 'location' => "http://www.itistimed.com/soap/whois-city.php", 'uri' => "http://www.itistimed.com/soap/req")); $data = $client->ipToCountryCity($ip); var_dump($data); Will display something like: array(7) { ["status"]= int(1) ["status_text"]= string(7) "Success" ["country"]= string(2) "US" ["city"]= string(13) "Mountain View" ["state"]= string(2) "CA" ["zip"]= string(5) "94043" ["org"]= string(11) "Google Inc."} thanks.

    Read the article

  • Angularjs code/naming conventions

    - by Dalorzo
    Does anyone know if exists any official or most accepted reference for Angular naming conventions to use when we build our applications? Angular has a lot of different type of components such as filters, directives, services and so on. Wouldn't you agree that having a reference naming convention when we implement them in our applications will make sense? For example: If we need to create new filters how should we name them like [Something]Filter or filter[Something] or something else? And same applies for Controllers, Services, Directives and so on. Other things I wonder about is if variables/functions that belongs to the scope should have an special prefix or suffix. In some situations it may be useful to have a way to differentiate them from functions and other (none angular code).

    Read the article

< Previous Page | 211 212 213 214 215 216 217 218 219 220 221 222  | Next Page >