Search Results

Search found 88709 results on 3549 pages for 'code efficiency'.

Page 43/3549 | < Previous Page | 39 40 41 42 43 44 45 46 47 48 49 50  | Next Page >

  • Is it ok to replace optimized code with readable code?

    - by Coder
    Sometimes you run into a situation where you have to extend/improve an existing code. You see that the old code is very lean, but it's also difficult to extend, and takes time to read. Is it a good idea to replace it with modern code? Some time ago I liked the lean approach, but now, it seems to me that it's better to sacrifice a lot of optimizations in favor of higher abstractions, better interfaces and more readable, extendable code. The compilers seem to be getting better as well, so things like struct abc = {} are silently turned into memsets, shared_ptrs are pretty much producing the same code as raw pointer twiddling, templates are working super good because they produce super lean code, and so on. But still, sometimes you see stack based arrays and old C functions with some obscure logic, and usually they are not on the critical path. Is it good idea to change such code if you have to touch a small piece of it either way?

    Read the article

  • Visit our Consolidated List of Mandatory Project Costing Code and Data Fixes

    - by SherryG-Oracle
    Projects Support has a published document with a consolidated listing of mandatory code and data fixes for Project Costing.  Generic Data Fix (GDF) patches are created by development to fix data issues caused by bugs/issues in the application code.  The GDF patches are released for download via My Oracle Support which are then referenced in My Oracle Support documents and by support to provide data fixes for known code fix issues.Consolidated root cause code fix and generic data fix patches will be superceded whenever any new version is created.  These patches fix a number of critical code and data issues identified in the Project Costing flow.This document contains a consolidated list of code and data fixes for Project Costing.  The note lists the following details: Note ID Component Type (code or data) Abstract Patch Visit DocID 1538822.1 today!

    Read the article

  • Do you actually write 'clean code'?

    - by ykombinator
    I have seen some programmers tweaking their code over and over again not only to make it 'work good', but also to make it 'look good'. IMO, 'clean code' is actually a compliment indicating your code is elegant, perfectly understandable and maintainable. And the difference comes out when you have to choose between an aesthetically appealing code vs. code that's stressful to look at. So, how many of you actually write 'clean code'? Is it a good practice? What are the other benefits or drawbacks of this? EDIT: I came across the term 'girl-code' here.

    Read the article

  • Increase efficiency of a loop with jQuery

    - by Pez Cuckow
    I have a game coded in jQuery where bots are moved around the screen. The below code is a loop that runs every 20ms, currently if you have over 15 bots you start to notice the browser lagging (simply because of all the advanced collision detection going on). Is there any way to reduce the lag, can I make it any more efficient? P.s. sorrry for just posting a block of code, I can't see a way to make my point clear enough without! $.playground().registerCallback(function(){ //Movement Loop if(!pause) { for (var i in bots) { //bots - color, dir, x, y, z, spawned?, spawnerid, prevd var self = $('#b' + i); var current = bots[i]; if(bots[i][5]==1) { var xspeed = 0, yspeed = 0; if(current[1]==0) { yspeed = -D_SPEED; } else if(current[1]==1) { xspeed = D_SPEED; } else if(current[1]==2) { yspeed = D_SPEED; } else if(current[1]==3) { xspeed = -D_SPEED; } var x = current[2] + xspeed; var y = current[3] + yspeed; var z = current[3] + 120; if(current[2]>0&&x>PLAYGROUND_WIDTH||current[2]<0&&x<-GRID_SIZE|| current[3]>0&&y>PLAYGROUND_HEIGHT||current[3]<0&&y<-GRID_SIZE) { remove_bot(i, self); } else { if(current[7]!=current[1]) { self.setAnimation(colors[current[0]][current[1]]); bots[i][7] = current[1]; } if(self.css({"left": ""+(x)+"px", "top": ""+(y)+"px", "z-index": z})) { bots[i][2] = x; bots[i][3] = y; bots[i][4] = z; bots[i][8]++; } } } } $("#debug").html(dump(arrows)); $(".bot").each(function(){ var b_id = $(this).attr("id").substr(1); var collision = false; var c_bot = bots[b_id]; var b_x = c_bot[2]; var b_y = c_bot[3]; var b_d = c_bot[1]; $(this).collision(".arrow,#arrows").each(function(){ //Many thanks to Selim Arsever for this fix! var a_id = $(this).attr("id").substr(1); var piece = arrows[a_id]; var a_v = piece[0]; if(a_v==1) { var a_x = piece[2]; var a_y = piece[3]; var d_x = b_x-a_x; var d_y = b_y-a_y; if(d_x>=4&&d_x<=5&&d_y>=1&&d_y<=2) { //bots - color, dir, x, y, z, spawned?, spawnerid, prevd bots[b_id][7] = c_bot[1]; bots[b_id][1] = piece[1]; collision = true; } } }); if(!collision) { $(this).collision(".wall,#level").each(function(){ var w_id = $(this).attr("id").substr(1); var piece = pieces[w_id]; var w_x = piece[1]; var w_y = piece[2]; d_x = b_x-w_x; d_y = b_y-w_y; if(b_d==0&&d_x>=4&&d_x<=5&&d_y>=27&&d_y<=28) { kill_bot(b_id); collision = true; } //4 // 33 if(b_d==1&&d_x>=-12&&d_x<=-11&&d_y>=21&&d_y<=22) { kill_bot(b_id); collision = true; } //-14 // 21 if(b_d==2&&d_x>=4&&d_x<=5&&d_y>=-9&&d_y<=-8) { kill_bot(b_id); collision = true; } //4 // -9 if(b_d==3&&d_x>=22&&d_x<=23&&d_y>=20&&d_y<=21) { kill_bot(b_id); collision = true; } //22 // 21 }); } if(!collision&&c_bot[8]>GRID_MOVE) { $(this).collision(".spawn,#level").each(function(){ var s_id = $(this).attr("id").substr(1); var piece = pieces[s_id]; var s_x = piece[1]; var s_y = piece[2]; d_x = b_x-s_x; d_y = b_y-s_y; if(b_d==0&&d_x>=4&&d_x<=5&&d_y>=19&&d_y<=20) { kill_bot(b_id); collision = true; } //4 // 33 if(b_d==1&&d_x>=-14&&d_x<=-13&&d_y>=11&&d_y<=12) { kill_bot(b_id); collision = true; } //-14 // 21 if(b_d==2&&d_x>=4&&d_x<=5&&d_y>=-11&&d_y<=-10) { kill_bot(b_id); collision = true; } //4 // -9 if(b_d==3&&d_x>=22&&d_x<=23&&d_y>=11&&d_y<=12) { kill_bot(b_id); collision = true; } //22 // 21*/ }); } if(!collision) { $(this).collision(".exit,#level").each(function(){ var e_id = $(this).attr("id").substr(1); var piece = pieces[e_id]; var e_x = piece[1]; var e_y = piece[2]; d_x = b_x-e_x; d_y = b_y-e_y; if(d_x>=4&&d_x<=5&&d_y>=1&&d_y<=2) { current_bots++; bots[b_id] = false; $("#current_bots").html(current_bots); $("#b" + b_id).setAnimation(exit[2], function(node){$(node).fadeOut(200)}); } }); } if(!collision) { $(this).collision(".bot,#level").each(function(){ var bd_id = $(this).attr("id").substr(1); if(bd_id!=b_id) { var piece = bots[bd_id]; var bd_x = piece[2]; var bd_y = piece[3]; d_x = b_x-bd_x; d_y = b_y-bd_y; if(d_x>=0&&d_x<=2&&d_y>=0&&d_y<=2) { kill_bot(b_id); kill_bot(bd_id); collision = true; } } }); } }); } }, REFRESH_RATE); Many thanks,

    Read the article

  • Increase efficiency of a loop with jQuery and GameQuery

    - by Pez Cuckow
    I have a game coded in jQuery where bots are moved around the screen. The below code is a loop that runs every 20ms, currently if you have over 15 bots you start to notice the browser lagging (simply because of all the advanced collision detection going on). Is there any way to reduce the lag, can I make it any more efficient? P.s. sorrry for just posting a block of code, I can't see a way to make my point clear enough without! $.playground().registerCallback(function(){ //Movement Loop if(!pause) { for (var i in bots) { //bots - color, dir, x, y, z, spawned?, spawnerid, prevd var self = $('#b' + i); var current = bots[i]; if(bots[i][5]==1) { var xspeed = 0, yspeed = 0; if(current[1]==0) { yspeed = -D_SPEED; } else if(current[1]==1) { xspeed = D_SPEED; } else if(current[1]==2) { yspeed = D_SPEED; } else if(current[1]==3) { xspeed = -D_SPEED; } var x = current[2] + xspeed; var y = current[3] + yspeed; var z = current[3] + 120; if(current[2]>0&&x>PLAYGROUND_WIDTH||current[2]<0&&x<-GRID_SIZE|| current[3]>0&&y>PLAYGROUND_HEIGHT||current[3]<0&&y<-GRID_SIZE) { remove_bot(i, self); } else { if(current[7]!=current[1]) { self.setAnimation(colors[current[0]][current[1]]); bots[i][7] = current[1]; } if(self.css({"left": ""+(x)+"px", "top": ""+(y)+"px", "z-index": z})) { bots[i][2] = x; bots[i][3] = y; bots[i][4] = z; bots[i][8]++; } } } } $("#debug").html(dump(arrows)); $(".bot").each(function(){ var b_id = $(this).attr("id").substr(1); var collision = false; var c_bot = bots[b_id]; var b_x = c_bot[2]; var b_y = c_bot[3]; var b_d = c_bot[1]; $(this).collision(".arrow,#arrows").each(function(){ //Many thanks to Selim Arsever for this fix! var a_id = $(this).attr("id").substr(1); var piece = arrows[a_id]; var a_v = piece[0]; if(a_v==1) { var a_x = piece[2]; var a_y = piece[3]; var d_x = b_x-a_x; var d_y = b_y-a_y; if(d_x>=4&&d_x<=5&&d_y>=1&&d_y<=2) { //bots - color, dir, x, y, z, spawned?, spawnerid, prevd bots[b_id][7] = c_bot[1]; bots[b_id][1] = piece[1]; collision = true; } } }); if(!collision) { $(this).collision(".wall,#level").each(function(){ var w_id = $(this).attr("id").substr(1); var piece = pieces[w_id]; var w_x = piece[1]; var w_y = piece[2]; d_x = b_x-w_x; d_y = b_y-w_y; if(b_d==0&&d_x>=4&&d_x<=5&&d_y>=27&&d_y<=28) { kill_bot(b_id); collision = true; } //4 // 33 if(b_d==1&&d_x>=-12&&d_x<=-11&&d_y>=21&&d_y<=22) { kill_bot(b_id); collision = true; } //-14 // 21 if(b_d==2&&d_x>=4&&d_x<=5&&d_y>=-9&&d_y<=-8) { kill_bot(b_id); collision = true; } //4 // -9 if(b_d==3&&d_x>=22&&d_x<=23&&d_y>=20&&d_y<=21) { kill_bot(b_id); collision = true; } //22 // 21 }); } if(!collision&&c_bot[8]>GRID_MOVE) { $(this).collision(".spawn,#level").each(function(){ var s_id = $(this).attr("id").substr(1); var piece = pieces[s_id]; var s_x = piece[1]; var s_y = piece[2]; d_x = b_x-s_x; d_y = b_y-s_y; if(b_d==0&&d_x>=4&&d_x<=5&&d_y>=19&&d_y<=20) { kill_bot(b_id); collision = true; } //4 // 33 if(b_d==1&&d_x>=-14&&d_x<=-13&&d_y>=11&&d_y<=12) { kill_bot(b_id); collision = true; } //-14 // 21 if(b_d==2&&d_x>=4&&d_x<=5&&d_y>=-11&&d_y<=-10) { kill_bot(b_id); collision = true; } //4 // -9 if(b_d==3&&d_x>=22&&d_x<=23&&d_y>=11&&d_y<=12) { kill_bot(b_id); collision = true; } //22 // 21*/ }); } if(!collision) { $(this).collision(".exit,#level").each(function(){ var e_id = $(this).attr("id").substr(1); var piece = pieces[e_id]; var e_x = piece[1]; var e_y = piece[2]; d_x = b_x-e_x; d_y = b_y-e_y; if(d_x>=4&&d_x<=5&&d_y>=1&&d_y<=2) { current_bots++; bots[b_id] = false; $("#current_bots").html(current_bots); $("#b" + b_id).setAnimation(exit[2], function(node){$(node).fadeOut(200)}); } }); } if(!collision) { $(this).collision(".bot,#level").each(function(){ var bd_id = $(this).attr("id").substr(1); if(bd_id!=b_id) { var piece = bots[bd_id]; var bd_x = piece[2]; var bd_y = piece[3]; d_x = b_x-bd_x; d_y = b_y-bd_y; if(d_x>=0&&d_x<=2&&d_y>=0&&d_y<=2) { kill_bot(b_id); kill_bot(bd_id); collision = true; } } }); } }); } }, REFRESH_RATE); Many thanks,

    Read the article

  • Selectively suppress XML Code Comments in C#?

    - by Mike Post
    We deliver a number of assemblies to external customers, but not all of the public APIs are officially supported. For example, due to less than optimal design choices sometimes a type must be publicly exposed from an assembly for the rest of our code to work, but we don't want customers to use that type. One part of communicating the lack of support is not provide any intellisense in the form of XML comments. Is there a way to selectively suppress XML comments? I'm looking for something other than ignoring warning 1591 since it's a long term maintenance issue. Example: I have an assembly with public classes A and B. A is officially supported and should have XML documentation. B is not intended for external use and should not be documented. I could turn on XML documentation and then suppress warning 1591. But when I later add the officially supported class C, I want the compiler to tell me that I've screwed up and failed to add the XML documentation. This wouldn't occur if I had suppressed 1591 at the project level. I suppose I could #pragma across entire classes, but it seems like there should be a better way to do this.

    Read the article

  • EclEmma JAVA Code coverage - Unable to coverage service layer of RESTful Webservice

    - by Radhika
    I am using EMMA eclipse plugin to generate code coverage reports. My application is a RESTFul webservice. Junits are written such that a client is created for the webservice and invoked with various inputs. However EMMA shows 0% coverage for the source folder. The test folder alone is covered. The application server(jetty server) is started using a main method. Report: Element Coverage Covered Instructions Total Instructions MyRestFulService 13.6% 900 11846 src 0.5% 49 10412 test 98% 1021 1434 Junit Test method: @Test public final void testAddFlow() throws Exception { Client c = Client.create(); WebResource webResource = c.resource(BASE_URI); // Sample files for Add String xhtmlDocument = null; Iterator iter = mapOfAddFiles.entrySet().iterator(); while (iter.hasNext()) { Map.Entry pairs = (Map.Entry) iter.next(); try { document = helper.readFile(requestPath + pairs.getKey()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } /* POST */ MultiPart multiPart = new MultiPart(); multiPart.bodyPart(.... ........... ClientResponse response = webResource.path("/add").type( MEDIATYPE_MULTIPART_MIXED).post(ClientResponse.class, multiPart); assertEquals("TESTING ADD FOR >>>>>>> " + pairs.getKey(), Status.OK, response.getClientResponseStatus()); } } } Invoked service method: @POST @Path("add") @Consumes("multipart/mixed") public Response add(MultiPart multiPart) throws Exception { Status status = null; List<BodyPart> bodyParts = null; bodyParts = multiPart.getBodyParts(); status = //call to business layer return Response.ok(status).build(); }

    Read the article

  • Metaprogramming - self explanatory code - tutorials, articles, books

    - by elena
    Hello everybody, I am looking into improving my programming skils (actually I try to do my best to suck less each year, as our Jeff Atwood put it), so I was thinking into reading stuff about metaprogramming and self explanatory code. I am looking for something like an idiot's guide to this (free books for download, online resources). Also I want more than your average wiki page and also something language agnostic or preferably with Java examples. Do you know of such resources that will allow to efficiently put all of it into practice (I know experience has a lot to say in all of this but i kind of want to build experience avoiding the flow bad decisions - experience - good decisions)? EDIT: Something of the likes of this example from the Pragmatic Programmer: ...implement a mini-language to control a simple drawing package... The language consists of single-letter commands. Some commands are followed by a single number. For example, the following input would draw a rectangle: P 2 # select pen 2 D # pen down W 2 # draw west 2cm N 1 # then north 1 E 2 # then east 2 S 1 # then back south U # pen up Thank you!

    Read the article

  • How can i shorten my code for various winform calls in MDI

    - by Shantanu Gupta
    I have a mdi where i have several line of code like the given below. Only chage is Form object which is being opened. So I want to all this work using only single function defination. When I tries to capture sender it gives me ToolStipMenuItem here. But I want its sender to be form name so that I can open its corresponding form. private void purchaseInvoiceToolStripMenuItem_Click(object sender, EventArgs e) { Forms.PurchaseInvoice purinv = new DigitalInvy.Forms.PurchaseInvoice(); purinv.Show(); } private void lederGroupsToolStripMenuItem_Click(object sender, EventArgs e) { Forms.LedgerGroup lgrp = new DigitalInvy.Forms.LedgerGroup(); lgrp.Show(); } private void voucherEntryToolStripMenuItem_Click(object sender, EventArgs e) { Forms.VoucherEntry ventry = new DigitalInvy.Forms.VoucherEntry(); ventry.Show(); } private void currencyToolStripMenuItem_Click(object sender, EventArgs e) { Forms.CurrencyMaster currency = new DigitalInvy.Forms.CurrencyMaster(); currency.Show(); } private void countryToolStripMenuItem_Click(object sender, EventArgs e) { Forms.CountryMaster country = new DigitalInvy.Forms.CountryMaster(); country.Show(); }

    Read the article

  • Code Golf: Quickly Build List of Keywords from Text, Including # of Instances

    - by Jonathan Sampson
    I've already worked out this solution for myself with PHP, but I'm curious how it could be done differently - better even. The two languages I'm primarily interested in are PHP and Javascript, but I'd be interested in seeing how quickly this could be done in any other major language today as well (mostly C#, Java, etc). Return only words with an occurrence greater than X Return only words with a length greater than Y Ignore common terms like "and, is, the, etc" Feel free to strip punctuation prior to processing (ie. "John's" becomes "John") Return results in a collection/array Extra Credit Keep Quoted Statements together, (ie. "They were 'too good to be true' apparently")Where 'too good to be true' would be the actual statement Extra-Extra Credit Can your script determine words that should be kept together based upon their frequency of being found together? This being done without knowing the words beforehand. Example: "The fruit fly is a great thing when it comes to medical research. Much study has been done on the fruit fly in the past, and has lead to many breakthroughs. In the future, the fruit fly will continue to be studied, but our methods may change." Clearly the word here is "fruit fly," which is easy for us to find. Can your search'n'scrape script determine this too? Source text: http://sampsonresume.com/labs/c.txt Answer Format It would be great to see the results of your code, output, in addition to how long the operation lasted.

    Read the article

  • Code Explanation (MPICH)

    - by user243680
    #include "mpi.h" #include <stdio.h> #include <math.h> double f(double a) { return (4.0 / (1.0 + a*a)); } void main(int argc, char *argv[]) { int done = 0, n, myid, numprocs,i; double PI25DT = 3.141592653589793238462643; double mypi, pi, h, sum, x; double startwtime, endwtime; int namelen; char processor_name[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); MPI_Get_processor_name(processor_name,&namelen); fprintf(stderr,"Process %d on %s\n", myid, processor_name); fflush(stderr); n = 0; while (!done) { if (myid == 0) { printf("Enter the number of intervals: (0 quits) ");fflush(stdout); scanf("%d",&n); startwtime = MPI_Wtime(); } MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); if (n == 0) done = 1; else { h = 1.0 / (double) n; sum = 0.0; for (i = myid + 1; i <= n; i += numprocs) { x = h * ((double)i - 0.5); sum += f(x); } mypi = h * sum; MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); if (myid == 0) { printf("pi is approximately %.16f, Error is %.16f\n", pi, fabs(pi - PI25DT)); endwtime = MPI_Wtime(); printf("wall clock time = %f\n", endwtime-startwtime); } } } MPI_Finalize(); } Can anyone explain me the above code what it does??I am in lab and my miss has asked me to explain and i dont know what it is.please help

    Read the article

  • Automatically install and launch a code-signed application from Safari

    - by Thomas Jung
    Is it possible and if so what are the steps necessary to package (or build) a Mac OS X application and code-sign it so that it can be downloaded with Safari and automatically launch? ... possibly after the user responds to some sort of dialog explaining that it is a signed application and the publisher has been verified. An example of the user experience I am trying to create is "installing Google Chrome for the first time on Windows", which is a 3-click, less-than-a-minute process. For the concerned among you: I am not trying to create a drive-by download. I am fine with some sort of intermittent user step approving the download. I just want to make the installation as quick and painless as possible and not require the user drag the app from a mounted DMG into the application folder. This may not 100% jibe with established Mac OS X user interaction guidelines, but it would work better for the not-power users. I only need the high-level steps or pointers to resources ... my google-fu was weak on this one.

    Read the article

  • Finding a 3rd party QWidget with injected code & QWidget::find(hwnd)

    - by David Menard
    Hey, I have a Qt Dll wich I inject into a third-party Application using windows detours library: if(!DetourCreateProcessWithDll( Path, NULL, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED, NULL, NULL, &si, &pi, "C:\\Program Files\\Microsoft Research\\Detours Express 2.1\\bin\\detoured.dll", "C:\\Users\\Dave\\Documents\\Visual Studio 2008\\Projects\\XOR\\Debug\\XOR.dll", NULL)) and then I set a system-wide hook to intercept window creation: HHOOK h_hook = ::SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, Status::getInstance()->getXORInstance(), 0); Where XOR is my programs name, and Status::getInstance() is a Singleton where I keep globals. In my CBTProc callback, I want to intercept all windows that are QWidgets: HWND hwnd= FindWindow(L"QWidget", NULL); which works well, since I get a corresponding HWND (I checked with Spy++) Then, I want to get a pointer to the QWidget, so I can use its functions: QWidget* q = QWidget::find(hwnd); but here's the problem, the returned pointer is always 0. Am I not injecting my code into the process properly? Or am I not using QWidget::find() as I should? Thanks, Dave EDIT:If i change the QWidget::find() function to an exported function of my DLL, after setting the hooks (so I can set and catch a breakpoint), QWidgetPrivate::mapper is NULL.

    Read the article

  • Code golf: combining multiple sorted lists into a single sorted list

    - by Alabaster Codify
    Implement an algorithm to merge an arbitrary number of sorted lists into one sorted list. The aim is to create the smallest working programme, in whatever language you like. For example: input: ((1, 4, 7), (2, 5, 8), (3, 6, 9)) output: (1, 2, 3, 4, 5, 6, 7, 8, 9) input: ((1, 10), (), (2, 5, 6, 7)) output: (1, 2, 5, 6, 7, 10) Note: solutions which concatenate the input lists then use a language-provided sort function are not in-keeping with the spirit of golf, and will not be accepted: sorted(sum(lists,[])) # cheating: out of bounds! Apart from anything else, your algorithm should be (but doesn't have to be) a lot faster! Clearly state the language, any foibles and the character count. Only include meaningful characters in the count, but feel free to add whitespace to the code for artistic / readability purposes. To keep things tidy, suggest improvement in comments or by editing answers where appropriate, rather than creating a new answer for each "revision". EDIT: if I was submitting this question again, I would expand on the "no language provided sort" rule to be "don't concatenate all the lists then sort the result". Existing entries which do concatenate-then-sort are actually very interesting and compact, so I won't retro-actively introduce a rule they break, but feel free to work to the more restrictive spec in new submissions. Inspired by http://stackoverflow.com/questions/464342/combining-two-sorted-lists-in-python

    Read the article

  • Where to post code for open source usage?

    - by Douglas
    I've been working for a few weeks now with the Google Maps API v3, and have done a good bit of development for the map I've been creating. Some of the things I've done have had to be done to add usability where there previously was not any, at least not that I could find online. Essentially, I made a list of what had to be done, searched all over the web for the ways to do what I needed, and found that some were not(at the time) possible(in the "grab an example off the web" sense). Thus, in my working on this map, I have created a number of very useful tools, which I would like to share with the development community. Is there anywhere I could use as a hub, apart from my portfolio ( http://dougglover.com ), to allow people to view and recycle my work? I know how hard it can be to need to do something, and be unable to find the solution elsewhere, and I don't think that if something has been done before, it should necessarily need to be written again and again. Hence open source code, right? Firstly, I was considering coming on here and asking a question, and then just answering it. Problem there is I assume that would just look like a big reputation grab. If not, please let me know and I'll go ahead and do that so people here can see it. Other suggestions appreciated. Some stuff I've made: A (new and improved) LatLng generator Works quicker, generates LatLng based on position of a draggable marker Allows searching for an address to place the marker on/near the desired location(much better than having to scroll to your location all the way from Siberia) Since it's a draggable marker, double-clicking zooms in, instead of creating a new LatLng marker like the one I was originally using The ability to create entirely custom "Smart Paths" Plot LatLng points on the map which connect to each other just like they do using the actual Google Maps Using Dijkstra's algorithm with Javascript, the routing is intelligent and always gives the shortest possible route, using the points provided Simple, easy to read multi-dimensional array system allows for easily adding new points to the grid Any suggestions, etc. appreciated.

    Read the article

  • Java: Efficiency of the readLine method of the BufferedReader and possible alternatives

    - by Luhar
    We are working to reduce the latency and increase the performance of a process written in Java that consumes data (xml strings) from a socket via the readLine() method of the BufferedReader class. The data is delimited by the end of line separater (\n), and each line can be of a variable length (6KBits - 32KBits). Our code looks like: Socket sock = connection; InputStream in = sock.getInputStream(); BufferedReader inputReader = new BufferedReader(new InputStreamReader(in)); ... do { String input = inputReader.readLine(); // Executor call to parse the input thread in a seperate thread }while(true) So I have a couple of questions: Will the inputReader.readLine() method return as soon as it hits the \n character or will it wait till the buffer is full? Is there a faster of picking up data from the socket than using a BufferedReader? What happens when the size of the input string is smaller than the size of the Socket's receive buffer? What happens when the size of the input string is bigger than the size of the Socket's receive buffer? I am getting to grips (slowly) with Java's IO libraries, so any pointers are much appreciated. Thank you!

    Read the article

  • What are Code Smells? What is the best way to correct them?

    - by Rob Cooper
    OK, so I know what a code smell is, and the Wikipedia Article is pretty clear in its definition: In computer programming, code smell is any symptom in the source code of a computer program that indicates something may be wrong. It generally indicates that the code should be refactored or the overall design should be reexamined. The term appears to have been coined by Kent Beck on WardsWiki. Usage of the term increased after it was featured in Refactoring. Improving the Design of Existing Code. I know it also provides a list of common code smells. But I thought it would be great if we could get clear list of not only what code smells there are, but also how to correct them. Some Rules Now, this is going to be a little subjective in that there are differences to languages, programming style etc. So lets lay down some ground rules: ** ONE SMELL PER ANSWER PLEASE! & ADVISE ON HOW TO CORRECT! ** See this answer for a good display of what this thread should be! DO NOT downmod if a smell doesn't apply to your language or development methodology We are all different. DO NOT just quickly smash in as many as you can think of Think about the smells you want to list and get a good idea down on how to work around. DO downmod answers that just look rushed For example "dupe code - remove dupe code". Let's makes it useful (e.g. Duplicate Code - Refactor into separate methods or even classes, use these links for help on these common.. etc. etc.). DO upmod answers that you would add yourself If you wish to expand, then answer with your thoughts linking to the original answer (if it's detailed) or comment if its a minor point. DO format your answers! Help others to be able to read it, use code snippets, headings and markup to make key points stand out!

    Read the article

  • EF4 Code First - Many to many relationship issue

    - by Yngve B. Nilsen
    Hi! I'm having some trouble with my EF Code First model when saving a relation to a many to many relationship. My Models: public class Event { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<Tag> Tags { get; set; } } public class Tag { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<Event> Events { get; set; } } In my controller, I map one or many TagViewModels into type of Tag, and send it down to my servicelayer for persistence. At this time by inspecting the entities the Tag has both Id and Name (The Id is a hidden field, and the name is a textbox in my view) The problem occurs when I now try to add the Tag to the Event. Let's take the following scenario: The Event is already in my database, and let's say it already has the related tags C#, ASP.NET If I now send the following list of tags to the servicelayer: ID Name 1 C# 2 ASP.NET 3 EF4 and add them by first fetching the Event from the DB, so that I have an actual Event from my DbContext, then I simply do myEvent.Tags.Add to add the tags.. Problem is that after SaveChanges() my DB now contains this set of tags: ID Name 1 C# 2 ASP.NET 3 EF4 4 C# 5 ASP.NET This, even though my Tags that I save has it's ID set when I save it (although I didn't fetch it from the DB)

    Read the article

  • Elegant code question: How to avoid creating unneeded object

    - by SeaDrive
    The root of my question is that the C# compiler is too smart. It detects a path via which an object could be undefined, so demands that I fill it. In the code, I look at the tables in a DataSet to see if there is one that I want. If not, I create a new one. I know that dtOut will always be assigned a value, but the the compiler is not happy unless it's assigned a value when declared. This is inelegant. How do I rewrite this in a more elegant way? System.Data.DataTable dtOut = new System.Data.DataTable(); . . // find table with tablename = grp // if none, create new table bool bTableFound = false; foreach (System.Data.DataTable d1 in dsOut.Tables) { string d1_name = d1.TableName; if (d1_name.Equals(grp)) { dtOut = d1; bTableFound = true; break; } } if (!bTableFound) dtOut = RptTable(grp);

    Read the article

  • Code Golf: Numeric Ranges

    - by SLaks
    Mods: Can you please make this Community Wiki? Challenge Compactify a long list of numbers by replacing consecutive runs with ranges. Example Input 1, 2, 3, 4, 7, 8, 10, 12, 13, 14, 15 Output: 1 - 4, 7, 8, 10, 12 - 15 Note that ranges of two numbers should be left as is. (7, 8; not 7 - 8) Rules You can accept a list of integers (or equivalent datatype) as a method parameter, from the commandline, or from standard in. (pick whichever option results in shorter code) You can output a list of strings by printing them, or by returning either a single string or set of strings. Reference Implementation (C#) IEnumerable<string> Sample(IList<int> input) { for (int i = 0; i < input.Count; ) { var start = input[i]; int size = 1; while (++i < input.Count && input[i] == start + size) size++; if (size == 1) yield return start.ToString(); else if (size == 2) { yield return start.ToString(); yield return (start + 1).ToString(); } else if (size > 2) yield return start + " - " + (start + size - 1); } }

    Read the article

  • Convert this code from C++ to C#

    - by Alhariri
    please any one convert this code from c++ to c# beacuse i dont know how to read from file in c++ please help me int DoEnDe(int c) { SDES S(key); int i,n; n=10; //Number of Rounds unsigned char ch; FILE *fp; FILE *ft; fp=fopen(tfname,"w"); ft=fopen(sfname,"r"); if (fp==NULL) { printf("\nTarget File not opened SORRY"); getch(); fclose(fp); return(0); } if (ft==NULL) { printf("\nSource File not opened SORRY"); getch(); fclose(ft); return(0); } while (fread(&ch,1,1,ft)==1) { S.OUTPUT=ch; for (i=0;i<n;i++) { if (c==1) S.DES_Encryption(S.OUTPUT); if (c==2) S.DES_Decryption(S.OUTPUT); } fwrite(&S.OUTPUT,1,1,fp); } printf("\nCompleted!!!!!"); getch(); fclose(fp); fclose(ft); return(1); }

    Read the article

  • Login fails when recreating database with Code First

    - by Mun
    I'm using ASP.NET Entity Framework's Code First to create my database from the model, and the login seems to fail when the database needs to be recreated after the model changes. In Global.asax, I've got the following: protected void Application_Start() { Database.SetInitializer(new DropCreateDatabaseIfModelChanges<EntriesContext>()); // ... } In my controller, I've got the following: public ActionResult Index() { // This is just to force the database to be created var context = new EntriesContext(); var all = (from e in context.Entries select e).ToList(); } When the database doesn't exist, it is created with no problems. However, when I make a change to the model, rebuild and refresh, I get the following error: Login failed for user 'sa'. My connection string looks like this: <add name="EntriesContext" connectionString="Server=(LOCAL);Database=MyDB;User Id=sa;Password=password" providerName="System.Data.SqlClient" /> The login definitely works as I can connect to the server and the database from Management Studio using these credentials. If I delete the database manually, everything works correctly and the database is recreated as expected with the schema reflecting the changes made to the model. It seems like either the password or access to the database is being lost. Is there something else I need to do to get this working?

    Read the article

  • Code Golf: Connecting the dots

    - by ChristopheD
    Description: The input are multiple lines (terminated by a newline) which describe a 'field'. There are 'numbers' scattered across this field: the numbers always start at 1 they follow the ordering of the natural numbers: every 'next number' is incremented with 1 every number is surrounded by (at least) one whitespace on it's left and right Task: Draw lines between these numbers in their natural order (1 -> 2 -> 3 -> ...N) with the following characteristics: replace a number with a '+' character for horizontal lines: use '-' for vertical lines: use '|' going left and down or right and up: / going left and up or right and down: \ Important note: When drawing lines of type 4 and 5 you can assume that : (given points to connect with coordinates x1, y1 and x2, y2) distance(x1,x2) == distance(y1,y2). Have a look at the examples to see where you should 'attach' the lines. It is important to follow the order in which the dots are connected (newer lines can be drawn over older lines). Sample input 1 9 10 8 7 6 5 11 13 12 3 4 14 15 16 1 2 Sample output 1 /+ / | / | +/ +--+ | +\ | \ | \+ /+ | / | /+-------------+/ +---+ / | +--+ | + | +--------------------------+ Sample input 2 4 2 3 5 6 1 8 7 Sample output 2 /+ / | / | / | /+------------------+/ +--------+\ / \ +/ +--------------------------------------+ Winner: shortest solution (by code count). Input can be read via command line.

    Read the article

  • asp.net mvc2 - controller for master page and code organization

    - by ile
    I've just finished my first ASP.NET MVC (2) CMS. Next step is to build website that will show data from CMS's database. This is website design: #1 (Red box) - displays article categories. ViewModel: public class CategoriesDisplay { public CategoriesDisplay() { } public int CategoryID { set; get; } public string CategoryTitle { set; get; } } #2 (Brown box) - displays last x articles; skips those from green box #3. Viewmodel: public class ArticleDisplay { public ArticleDisplay() { } public int CategoryID { set; get; } public string CategoryTitle { set; get; } public int ArticleID { set; get; } public string ArticleTitle { set; get; } public string URLArticleTitle { set; get; } public DateTime ArticleDate; public string ArticleContent { set; get; } } #3 (green box) - Displays last x articles. Uses the same ViewModel as brown box #2 #4 (blue box) - Displays list of upcoming events. Uses dataContext.Model.Event as ViewModel Boxes #1, #2 and #4 will repeat all over the site and they are part of Master Page. So, my question is: what is the best way to transfer this data from Model to Controller and finally to View pages? Should I make a controller for master page and ViewModel class that will wrap all this classes together OR Should I create partial Views for every of these boxes and make each of them inherit appropriate class (if it is even possible that it works this way?) OR Should I put this repeated code in all controllers and all additional data transfer via ViewData, which would be probably the worse way :) OR There is maybe a better and more simple way but I don't know/see it? Thanks in advance, Ile EDIT: If your answer is #1, then please explain how to make a controller for master page! EDIT 2: In this tutorial is described how to pass data to master page using abstract class: http://www.asp.net/LEARN/mvc/tutorial-13-cs.aspx In "Listing 5 – Controllers\MoviesController.cs", data is retrieved directly from database using LINQ, not from repository. So, I wonder if this is just in this tutorial, or there is some trick here and repository can't/shouldn't be used?

    Read the article

  • The Skyline Problem.

    - by zeroDivisible
    I just came across this little problem on UVA's Online Judge and thought, that it may be a good candidate for a little code-golf. The problem: You are to design a program to assist an architect in drawing the skyline of a city given the locations of the buildings in the city. To make the problem tractable, all buildings are rectangular in shape and they share a common bottom (the city they are built in is very flat). The city is also viewed as two-dimensional. A building is specified by an ordered triple (Li, Hi, Ri) where Li and Ri are left and right coordinates, respectively, of building i and Hi is the height of the building. In the diagram below buildings are shown on the left with triples (1,11,5), (2,6,7), (3,13,9), (12,7,16), (14,3,25), (19,18,22), (23,13,29), (24,4,28) and the skyline, shown on the right, is represented by the sequence: 1, 11, 3, 13, 9, 0, 12, 7, 16, 3, 19, 18, 22, 3, 23, 13, 29, 0 The output should consist of the vector that describes the skyline as shown in the example above. In the skyline vector (v1, v2, v3, ... vn) , the vi such that i is an even number represent a horizontal line (height). The vi such that i is an odd number represent a vertical line (x-coordinate). The skyline vector should represent the "path" taken, for example, by a bug starting at the minimum x-coordinate and traveling horizontally and vertically over all the lines that define the skyline. Thus the last entry in the skyline vector will be a 0. The coordinates must be separated by a blank space. If I will not count declaration of provided (test) buildings and including all spaces and tab characters, my solution, in Python, is 223 characters long. Here is the condensed version: B=[[1,11,5],[2,6,7],[3,13,9],[12,7,16],[14,3,25],[19,18,22],[23,13,29],[24,4,28]] # Solution. R=range v=[0 for e in R(max([y[2] for y in B])+1)] for b in B: for x in R(b[0], b[2]): if b[1]>v[x]: v[x]=b[1] p=1 k=0 for x in R(len(v)): V=v[x] if p and V==0: continue elif V!=k: p=0 print "%s %s" % (str(x), str(V)), k=V I think that I didn't made any mistake but if so - feel free to criticize me. EDIT I don't have much reputation, so I will pay only 100 for a bounty - I am curious, if anyone could try to solve this in less than .. lets say, 80 characters. Solution posted by cobbal is 101 characters long and currently it is the best one. ANOTHER EDIT I thought, that 80 characters is a sick limit for this kind of problem. cobbal, with his 46 character solution totaly amazed me - though I must admit, that I spent some time reading his explanation before I partially understood what he had written.

    Read the article

< Previous Page | 39 40 41 42 43 44 45 46 47 48 49 50  | Next Page >