Search Results

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

Page 106/237 | < Previous Page | 102 103 104 105 106 107 108 109 110 111 112 113  | Next Page >

  • Lock thread using somthing other than a object

    - by Scott Chamberlain
    when using a lock does the thing you are locking on have to be a object. For example is this legal static DateTime NextCleanup = DateTime.Now; const TimeSpan CleanupInterval = new TimeSpan(1, 0, 0); private static void DoCleanup() { lock ((object)NextCleanup) { if (NextCleanup < DateTime.Now) { NextCleanup = DateTime.Now.Add(CleanupInterval); System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(cleanupThread)); } } return; } EDIT-- From reading SLaks' responce I know the above code would be not valid but would this be? static MyClass myClass = new MyClass(); private static void DoCleanup() { lock (myClass) { // } return; }

    Read the article

  • To trigger everytime with .click()?

    - by Dejan.S
    I tried to have a .click() on a <a> to find out it wont trigger every time I click, what it suppose to do is open a dialog. That is not the only problem I would need to pass a value to my jquery to. I just cant figure this one out. I need it to be a <a> because it's gone be in a dropdown menu. Do you got any suggestions? this is the code I use so far $(document).ready(function() { $('a').click(function() { var first = "<iframe style='width: 100%; height: 100%;' src='" + need to put value here + "'</iframe>'"; $('.iframe').html(first); $('#dialog').dialog({ bgiframe: true, modal: true, height: 600, width: 1000 }); }); }); thanks guys

    Read the article

  • What is the best practice when coding math class/functions ?

    - by Isaac Clarke
    Introductory note : I voluntarily chose a wide subject. You know that quote about learning a cat to fish, that's it. I don't need an answer to my question, I need an explanation and advice. I know you guys are good at this ;) Hi guys, I'm currently implementing some algorithms into an existing program. Long story short, I created a new class, "Adder". An Adder is a member of another class representing the physical object actually doing the calculus , which calls adder.calc() with its parameters (merely a list of objects to do the maths on). To do these maths, I need some parameters, which do not exist outside of the class (but can be set, see below). They're neither config parameters nor members of other classes. These parameters are D1 and D2, distances, and three arrays of fixed size : alpha, beta, delta. I know some of you are more comfortable reading code than reading text so here you go : class Adder { public: Adder(); virtual Adder::~Adder(); void set( float d1, float d2 ); void set( float d1, float d2, int alpha[N_MAX], int beta[N_MAX], int delta[N_MAX] ); // Snipped prototypes float calc( List& ... ); // ... inline float get_d1() { return d1_ ;}; inline float get_d2() { return d2_ ;}; private: float d1_; float d2_; int alpha_[N_MAX]; // A #define N_MAX is done elsewhere int beta_[N_MAX]; int delta_[N_MAX]; }; Since this object is used as a member of another class, it is declared in a *.h : private: Adder adder_; By doing that, I couldn't initialize the arrays (alpha/beta/delta) directly in the constructor ( int T[3] = { 1, 2, 3 }; ), without having to iterate throughout the three arrays. I thought of putting them in static const, but I don't think that's the proper way of solving such problems. My second guess was to use the constructor to initialize the arrays Adder::Adder() { int alpha[N_MAX] = { 0, -60, -120, 180, 120, 60 }; int beta[N_MAX] = { 0, 0, 0, 0, 0, 0 }; int delta[N_MAX] = { 0, 0, 180, 180, 180, 0 }; set( 2.5, 0, alpha, beta, delta ); } void Adder::set( float d1, float d2 ) { if (d1 > 0) d1_ = d1; if (d2 > 0) d2_ = d2; } void Adder::set( float d1, float d2, int alpha[N_MAX], int beta[N_MAX], int delta[N_MAX] ) { set( d1, d2 ); for (int i = 0; i < N_MAX; ++i) { alpha_[i] = alpha[i]; beta_[i] = beta[i]; delta_[i] = delta[i]; } } My question is : Would it be better to use another function - init() - which would initialize arrays ? Or is there a better way of doing that ? My bonus question is : Did you see some mistakes or bad practice along the way ?

    Read the article

  • Manually setting object's position or have the object do it all?

    - by N. Lucas
    I'm stuck thinking about the best way to go about setting a line segment's position, I have a class Line(length, angle, previous) being called from a class Polygon.. Right now I have: public function Line(length:Number, angle:Number, previous:Line = null) { if (previous != null) { this.x = previous.end.x; this.y = previous.end.y; } /**/ } Now, is this the best practice or should I be doing: Polygon.addLine(length:Number, angle:Number):void { var previous = _line[_line.length - 1]; // Array containing all Lines var line:Line = new Line(length, angle, previous); line.x = previous.end.x; line.y = previous.end.y; /**/ }

    Read the article

  • Use of properties vs backing-field inside owner class

    - by whatispunk
    I love auto-implemented properties in C# but lately there's been this elephant standing in my cubicle and I don't know what to do with him. If I use auto-implemented properties (hereafter "aip") then I no longer have a private backing field to use internally. This is fine because the aip has no side-effects. But what if later on I need to add some extra processing in the get or set? Now I need to create a backing-field so I can expand my getters and setters. This is fine for external code using the class, because they won't notice the difference. But now all of the internal references to the aip are going to invoke these side-effects when they access the property. Now all internal access to the once aip must be refactored to use the backing-field. So my question is, what do most of you do? Do you use auto-implemented properties or do you prefer to always use a backing-field? What do you think about properties with side-effects?

    Read the article

  • How can I determine/use $(this) in js callback script

    - by Rabbott
    I am using Rails and jQuery, making an ajax call initiated by clicking a link. I setup my application.js file to look like the one proposed here and it works great. The problem I'm having is how can I use $(this) in my say.. update.js.erb file to represent the link I clicked? I don't want to have to assign an ID to every one, then recompile that id in the callback script.. EDIT To give a simple example of something similar to what I'm trying to do (and much easier to explain): If a user clicks on a link, that deletes that element from a list, the controller would handle the callback, and the callback (which is in question here) would delete the element I clicked on, so in the callback delete.js.erb would just say $(this).fadeOut(); This is why I want to use $(this) so that I dont have to assign an ID to every element (which would be the end of the world, just more verbose markup) application.js jQuery.ajaxSetup({ 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript,application/javascript,text/html")} }) function _ajax_request(url, data, callback, type, method) { if (jQuery.isFunction(data)) { callback = data; data = {}; } return jQuery.ajax({ type: method, url: url, data: data, success: callback, dataType: type }); } jQuery.extend({ put: function(url, data, callback, type) { return _ajax_request(url, data, callback, type, 'PUT'); }, delete_: function(url, data, callback, type) { return _ajax_request(url, data, callback, type, 'DELETE'); } }); jQuery.fn.submitWithAjax = function() { this.unbind('submit', false); this.submit(function() { $.post(this.action, $(this).serialize(), null, "script"); return false; }) return this; }; // Send data via get if <acronym title="JavaScript">JS</acronym> enabled jQuery.fn.getWithAjax = function() { this.unbind('click', false); this.click(function() { $.get($(this).attr("href"), $(this).serialize(), null, "script"); return false; }) return this; }; // Send data via Post if <acronym title="JavaScript">JS</acronym> enabled jQuery.fn.postWithAjax = function() { this.unbind('click', false); this.click(function() { $.post($(this).attr("href"), $(this).serialize(), null, "script"); return false; }) return this; }; jQuery.fn.putWithAjax = function() { this.unbind('click', false); this.click(function() { $.put($(this).attr("href"), $(this).serialize(), null, "script"); return false; }) return this; }; jQuery.fn.deleteWithAjax = function() { this.removeAttr('onclick'); this.unbind('click', false); this.click(function() { $.delete_($(this).attr("href"), $(this).serialize(), null, "script"); return false; }) return this; }; // This will "ajaxify" the links function ajaxLinks(){ $('.ajaxForm').submitWithAjax(); $('a.get').getWithAjax(); $('a.post').postWithAjax(); $('a.put').putWithAjax(); $('a.delete').deleteWithAjax(); } show.html.erb <%= link_to 'Link Title', article_path(a, :sentiment => Article::Sentiment['Neutral']), :class => 'put' %> The combination of the two things will call update.js.erb in rails, the code in that file is used as the callback of the ajax ($.put in this case) update.js.erb // user feedback $("#notice").html('<%= flash[:notice] %>'); // update the background color $(this OR e.target).attr("color", "red");

    Read the article

  • How to expose a constructor variable(sic!) as read-only?

    - by Malax
    Hi StackOverflow! I have this rather simple question about Scala. Given that i have to following class definition: class Foo(var bar: Int) The code which is able to construct an instance of Foo must be able to pass the initial value for bar. But if I define bar as var the User is also able to change its value at runtime which is not what I want. The User should only be able to read bar. bar itself is modified internally so a val is not an option. I think I might be getting an answer very soon as this question is so simple. :-) Cheers, Malax

    Read the article

  • Is this 2D array initialization a bad idea?

    - by Brendan Long
    I have something I need a 2D array for, but for better cache performance, I'd rather have it actually be a normal array. Here's the idea I had but I don't know if it's a terrible idea: const int XWIDTH = 10, YWIDTH = 10; int main(){ int * tempInts = new int[XWIDTH * YWIDTH]; int ** ints = new int*[XWIDTH]; for(int i=0; i<XWIDTH; i++){ ints[i] = &tempInts[i*YWIDTH]; } // do things with ints delete[] ints[0]; delete[] ints; return 0; } So the idea is that instead of newing a bunch of arrays (and having them placed in different places in memory), I just point to an array I made all at once. The reason for the delete[] (int*) ints; is because I'm actually doing this in a class and it would save [trivial amounts of] memory to not save the original pointer. Just wondering if there's any reasons this is a horrible idea. Or if there's an easier/better way. The goal is to be able to access the array as ints[x][y] rather than ints[x*YWIDTH+y].

    Read the article

  • Correct structure and way of website versioning

    - by Saif Bechan
    Recently I use GIT to version my website. It makes it all really easy to see how my project develops and I always have save backups on different places on the web. Now my main question is if it is recommended to version your whole root of the website. I have a basic structure that looks something like this: /httpdocs /config /media /application index.php .htaccess 1) Should I use the /httpdocs folder to version, or should I use the content of the folder. 2) Is it recommended to version the media folder. In the media version I have several images for the overall layout, and some other images for the website. These imagas can be quite large. I work on these images from time to time and so they change. I hardly never need the old image again, so is this not just taking up precious storage space. I would highly appreciate just some basic recommendation on this topic.

    Read the article

  • MapReduce programming system in java-actionscript

    - by eco_bach
    Just finished reading ch23 in the excellent 'Beautiful Code' http://oreilly.com/catalog/9780596510046 on Distributed Programming with MapReduce. I understand that MapReduce is a programming system designed for large-scale data processing problems, but I have a hard time getting my head around the basic examples given and how I might apply them in real world situations. Can someone give a simple example of MapReduce implemented using either java, javascript or actionscript?

    Read the article

  • How to synchronize static method in java.

    - by Summer_More_More_Tea
    Hi there: I come up with this question when implementing singleton pattern in Java. Even though the example listed blow is not my real code, yet very similar to the original one. public class ConnectionFactory{ private static ConnectionFactory instance; public static synchronized ConnectionFactory getInstance(){ if( instance == null ){ instance = new ConnectionFactory(); } return instance; } private ConnectionFactory(){ // private constructor implementation } } Because I'm not quite sure about the behavior of a static synchronized method, I get some suggestion from google -- do not have (or as less as possible) multiple static synchronized methods in the same class. I guess when implementing static synchronized method, a lock belongs to Class object is used so that multiple static synchronized methods may degrade performance of the system. Am I right? or JVM use other mechanism to implement static synchronized method? What's the best practice if I have to implement multiple static synchronized methods in a class? Thank you all! Kind regards!

    Read the article

  • highlite text parts with jquery, best practice

    - by helle
    Hey guys, i have a list of items containig names. then i have a eventlistener, which ckecks for keypress event. if the user types i.g. an A all names starting with an A should be viewed with the A bold. so all starting As should be bold. what is the best way using jquery to highlite only a part of a string? thanks for your help

    Read the article

  • Whats the best semantic default/starting layout for html5?

    - by John Isaacks
    I am a little confused on how the new tags should go. Is this correct: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title></title> </head> <body> <section> <header> <nav></nav> </header> <section> </section> <footer> </footer> <section> </body> </html> Or should one of the sections be an <article>? What should be the starting layout?

    Read the article

  • Should checkins be small steps or complete features?

    - by Caspin
    Two of version controls uses seem to dictate different checkin styles. distibution centric: changesets will generally reflect a complete feature. In general these checkins will be larger. This style is more user/maintainer friendly. rollback centric: changesets will be individual small steps so the history can function like an incredibly powerful undo. In general these checkins will be smaller. This style is more developer friendly. I like to use my version control as really powerful undo while while I banging away at some stubborn code/bug. In this way I'm not afraid to make drastic changes just to try out a possible solution. However, this seems to give me a fragmented file history with lots of "well that didn't work" checkins. If instead I try to have my changeset reflect complete features I loose the use of my version control software for experimentation. However, it is much easier for user/maintainers to figure out how the code is evolving. Which has great advantages for code reviews, managing multiple branches, etc. So what's a developer to do? checkin small steps or complete features?

    Read the article

  • Application Engineering and Number of Users

    - by Kramii
    Apart from performance concerns, should web-based applications be built differently according to the number of (concurrent) users? If so, what are the main differences for (say) 4, 40, 400 and 4000 users? I'm particularly interested in how logging, error handling, design patterns etc. would be be used according to the number of concurrent users.

    Read the article

  • What is the difference between a private and public funtion?

    - by Kyle
    I am a new programmer, and I started in C and am now starting to enjoy JavaScript and a tiny bit of PHP more. Lately I've heard the terms 'private' and 'public' functions a lot. Could anybody give an explanation of the both and how they are of use to a programmer? And I'm probably totally wrong here... but is a (function(){}) in javascript a private function?

    Read the article

  • What real life bad habits has programming given you? [closed]

    - by Jacob T. Nielsen
    Programming has given me a lot of bad habits and it continues to give me more everyday. But I have also gotten some bad habits from the mindset that I have put myself in. There simply are some things that are deeply rooted in my nature, though some of them I wish I could get rid of. A few: Looking for polymorphism, inheritance and patterns in all of God's creations. Explaining the size of something in pixels and colors in hex code. Using code related abstract terms in everyday conversations. How have you been damaged?

    Read the article

  • Does OOP make sense for small scripts?

    - by Fabian
    I mostly write small scripts in python, about 50 - 250 lines of code. I usually don't use any objects, just straightforward procedural programming. I know OOP basics and I have used object in other programming languages before, but for small scripts I don't see how objects would improve them. But maybe that is just my limited experience with OOP. Am I missing something by not trying harder to use objects, or does OOP just not make a lot of sense for small scripts?

    Read the article

  • How do I create a safe local development environment?

    - by docgnome
    I'm currently doing web development with another developer on a centralized development server. In the past this has worked alright, as we have two separate projects we are working on and rarely conflict. Now, however, we are adding a third (possible) developer into the mix. This is clearly going to create problems with other developers changes affecting my work and vice versa. To solve this problem, I'm thinking the best solution would be to create a virtual machine to distribute between the developers for local use. The problem I have is when it comes to the database. Given that we all develop on laptops, simply keeping a local copy of the live data is plain stupid. I've considered sanitizing the data, but I can't really figure out how to replace the real data, with data that would be representative of what people actually enter with out repeating the same information over and over again, e.g. everyone's address becomes 123 Testing Lane, Test Town, WA, 99999 or something. Is this really something to be concerned about? Are there tools to help with this sort of thing? I'm using MySQL. Ideally, if I sanitized the db it should be done from a script that I can run regularly. If I do this I'd also need a way to reduce the size of the db itself. (I figure I could select all the records created after x and whack them and all the records in corresponding tables out so that isn't really a big deal.) The second solution I've thought of is to encrypt the hard drive of the vm, but I'm unsure of how practical this is in terms of speed and also in the event of a lost/stolen laptop. If I do this, should the vm hard drive file itself be encrypted or should it be encrypted in the vm? (I'm assuming the latter as it would be portable and doesn't require the devs to have any sort of encryption capability on their OS of choice.) The third is to create a copy of the database for each developer on our development server that they are then responsible to keep the schema in sync with the canonical db by means of migration scripts or what have you. This solution seems to be the simplest but doesn't really scale as more developers are added. How do you deal with this problem?

    Read the article

  • How to Inserting message into View that depends on session value. ASP.NET MVC. Best practice

    - by Andrew Florko
    User have to populate multistep questionnaire web-forms and step messages depend on the option chosen by user at the very beginning. Messages are stored in web.config file. I use asp.net mvc project, strong typed views and keep business logic separated from controller in static class. I don't want to make business logic dependency on web.config. Well, I have to insert message into view that depends on session value. There are at least 2 options how to implement this: View model has property that is populated in controller/businessLogic and rendered in view like <%: Model.HelpMessage1 %>. I have to pass web.config values from controller to businessLogic that makes business logic methods signature too complex. I don't want to make configuration source abstract (in order to let business logic read configuration values from its methods directly) also. Create static helper class that is called from view like <%: ViewHelper.HelpMessage1(Model.Option1) %>. But in this case logic what to show seems to be separated into two classes: business logic & viewHelper. What will you suggest? Thank you in advance!

    Read the article

  • How to insert an n:m-relationship with technical primary keys generated by a sequence?

    - by bitschnau
    Let's say I have two tables with several fields and in every table there is a primary key which is a technical id generated by a database sequence: table1 table2 ------------- ------------- field11 <pk> field21 <pk> field12 field22 field11 and field21 are generated by sequences. Also there is a n:m-relationship between table1 und table2, designed in table3: table3 ------------- field11 <fk> field21 <fk> The ids in table1 und table2 are generated during the insert statement: INSERT INTO table1 VALUES (table1_seq1.NEXTVAL, ... INSERT INTO table2 VALUES (table2_seq1.NEXTVAL, ... Therefore I don't know the primary key of the added row in the data-access-layer of my program, because the generation of the pk happens completely in the database. What's the best practice to update table3 now? How can I gain access to the primary key of the rows I just inserted?

    Read the article

  • How to handle recurring execution?

    - by ShaneC
    I am trying to validate the solution I came up for what I think is a fairly typical problem. I have a service running and every 10 minutes it should do something. I've ended up with the following: private bool isRunning = true; public void Execute() { while(isRunning) { if(isRunning) { DoSomething(); m_AutoResetEvent.WaitOne(new Timespan(0, 10, 0)); } } } public void Stop() { isRunning = false; m_AutoResetEvent.Set(); } The immediate potential problems I can see is that I'm not doing any sort of locking around the isRunning modification in Stop() which gets called by another thread but I'm not sure I really need to? The worst that I think could happen is that it runs one extra cycle. Beyond that are there any obvious problems with this code? Is there a better way to solve this problem that I'm unaware of?

    Read the article

  • PHP explode and set to empty string the missing pieces

    - by Marco Demaio
    What's the best way to accomplish the following. I have strings in this format: $s1 = "name1|type1"; //(pipe is the separator) $s2 = "name2|type2"; $s3 = "name3"; //(in some of them type can be missing) Let's assume namen/typen are strings and they can not contain a pipe. Since I need to exctract the name/type separetly, I do: $temp = explode($s1, '|'); $name = $temp[0]; $type = ( isset($temp[1]) ? $temp[1] : '' ); Is there an easier (smarter whatever faster) way to do this without having to do isset($temp[1]) or count($temp). Thanks!

    Read the article

< Previous Page | 102 103 104 105 106 107 108 109 110 111 112 113  | Next Page >