Search Results

Search found 20065 results on 803 pages for 'practice problems'.

Page 34/803 | < Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >

  • UISegmentedControl Best Practice

    - by Neal L
    Hi all, I'm trying to work out the "best" way to use a UISegmentedControl for an iPhone application. I've read a few posts here on stackoverflow and seen a few people's ideas, but I can't quite sort out the best way to do this. The posts I'm referring to are: http://stackoverflow.com/questions/1559794/changing-views-from-uisegmentedcontrol and http://stackoverflow.com/questions/1047114/how-do-i-use-a-uisegmentedcontrol-to-switch-views It would seem that the options are: Add each of the views in IB and lay them out on top of each other then show/hide them Create each of the subviews separately in IB, then create a container in the main view to populate with the subview that you need Set up one really tall or really wide UIView and animate it left/right or up/down depending on the selected segment Use a UITabBarController to swap out the subviews - seems silly For tables, reload the table and in cellForRowAtIndex and populate the table from different data sources or sections based on the segment option selected (not the case for my app) So which approach is best for subview/non-table approaches? Which is the easiest to implement? Could you share some sample code to the approach? Thanks!

    Read the article

  • Bad Practice requiring file within a model?

    - by Lee Marshall
    I have built an MVC php application and was wondering, if instead of having to write out a large amount of html and set the data, could I not just have all this html (with some php) in a separate file and just require it? For example: $test = '<div> Test content <div>More content</div> </div>'; $APP->Template->setData('test', $test, FALSE); Instead could I not just use: $test = require("includes/content.php"); $APP->Template->setData('test', $test, FALSE); Would this be considered as bad practise? It just seems that by requiring files, it can shorten the length of controllers. Would be good to get anybodies advice on this matter.

    Read the article

  • REST API Best practice: How to accept as input a list of parameter values

    - by whatupwilly
    Hi All, We are launching a new REST API and I wanted some community input on best practices around how we should have input parameters formatted: Right now, our API is very JSON-centric (only returns JSON). The debate of whether we want/need to return XML is a separate issue. As our API output is JSON centric, we have been going down a path where our inputs are a bit JSON centric and I've been thinking that may be convenient for some but weird in general. For example, to get a few product details where multiple products can be pulled at once we currently have: http://our.api.com/Product?id=["101404","7267261"] Should we simplify this as: http://our.api.com/Product?id=101404,7267261 Or is having JSON input handy? More of a pain? We may want to accept both styles but does that flexibility actually cause more confusion and head aches (maintainability, documentation, etc.)? A more complex case is when we want to offer more complex inputs. For example, if we want to allow multiple filters on search: http://our.api.com/Search?term=pumas&filters={"productType":["Clothing","Bags"],"color":["Black","Red"]} We don't necessarily want to put the filter types (e.g. productType and color) as request names like this: http://our.api.com/Search?term=pumas&productType=["Clothing","Bags"]&color=["Black","Red"] Because we wanted to group all filter input together. In the end, does this really matter? It may be likely that there are so many JSON utils out there that the input type just doesn't matter that much. I know our javascript clients making AJAX calls to the API may appreciate the JSON inputs to make their life easier. Thanks, Will

    Read the article

  • What's best practice to check if an object is part of a ManyToMany relationship in Django

    - by PhilGo20
    from an instance of Site with a ManyToMany relationship to Kiosk, i'd like to check if a Kiosk object is part of the relationship. I could do self.apps.get(id=app_id).exists() and check if True or self.apps.get(id=app_id) and catch the ObjectDoesNotExist error or self.apps.filter(id=app_id) and check if True If I have to catch a possible ObjectDoesNotExist error, I may as well use the second one I can do the second but doesnt seem super clean can use the third one but using filter on a unique ID seems wrong to me You can tell me to use whatever works and that'll be a valid answer ;-)

    Read the article

  • jQuery global variable best practice & options?

    - by Kris Krause
    Currently I am working on a legacy web page that uses a ton of javascript, jquery, microsoft client javascript, and other libraries. The bottom line - I cannot rewrite the entire page from scratch as the business cannot justify it. So... it is what it is. Anyway, I need to pollute (I really tried not too) the global namespace with a variable. There are the three options I was thinking - Just store/retrieve it using a normal javascript declaration - var x = 0; Utilize jQuery to store/retrieve the value in a DOM tag - $("body").data("x", 0); Utilize a hidden form field, and set/retrieve the value with jQuery - $("whatever").data("x", 0); What does everyone think? Is there a better way? I looked at the existing pile of code and I do not believe the variable can be scoped in a function.

    Read the article

  • JUnit Best Practice: Different Fixtures for each @Test

    - by Juri Glass
    Hi I understand that there are @Before and @BeforeClass, which are used to define fixtures for the @Test's. But what should I use if I need different fixtures for each @Test? Should I define the fixture in the @Test? Should I create a test class for each @Test? I am asking for the best practices here, since both solutions aren't clean in my opinion. With the first solution, I would test the initialization code. And with the second solution I would break the "one test class for each class" pattern.

    Read the article

  • Best practice stock management when payment of customer failed using SQL Server and ASP.NET

    - by Martijn B
    Hi there, I am currently building a webshop for my own where I want to increment the product-stock when the user fails to complete payment within 10 minutes after the customer placed the order. I want to gather information from this thread to make a design decision. I am using SQL Server 2008 and ASP.NET 3.5. Should I use a SQL Server Job who intervals check the orders which are not payed yet or are there better solutions to do this. Thanks in advance! Martijn

    Read the article

  • Trace PRISM / CAL events (best practice?)

    - by Christian
    Ok, this question is for people with either a deep knowledge of PRISM or some magic skills I just lack (yet). The Background is simple: Prism allows the declaration of events to which the user can subscribe or publish. In code this looks like this: _eventAggregator.GetEvent<LayoutChangedEvent>().Subscribe(UpdateUi, true); _eventAggregator.GetEvent<LayoutChangedEvent>().Publish("Some argument"); Now this is nice, especially because these events are strongly typed, and the declaration is a piece of cake: public class LayoutChangedEvent : CompositePresentationEvent<string> { } But now comes the hard part: I want to trace events in some way. I had the idea to subscribe using a lambda expression calling a simple log message. Worked perfectly in WPF, but in Silverlight there is some method access error (took me some time to figure out the reason).. If you want to see for yourself, try this in Silverlight: eA.GetEvent<VideoStartedEvent>().Subscribe(obj => TraceEvent(obj, "vSe", log)); If this would be possible, I would be happy, because I could easily trace all events using a single line to subscribe. But it does not... The alternative approach is writing a different functions for each event, and assign this function to the events. Why different functions? Well, I need to know WHICH event was published. If I use the same function for two different events I only get the payload as argument. I have now way to figure out which event caused the tracing message. I tried: using Reflection to get the causing event (not working) using a constructor in the event to enable each event to trace itself (not allowed) Any other ideas? Chris PS: Writing this text took me most likely longer than writing 20 functions for my 20 events, but I refuse to give up :-) I just had the idea to use postsharp, that would most likely work (although I am not sure, perhaps I end up having only information about the base class).. Tricky and so unimportant topic...

    Read the article

  • Best Practice for Uploading Many (2000+) Images to A Server

    - by bob
    Hello, I have a general question about this. When you have a gallery, sometimes people need to upload 1000's of images at once. Most likely, it would be done through a .zip file. What is the best way to go about uploading this sort of thing to a server. Many times, server have timeouts etc. that need to be accounted for. I am wondering what kinds of things should I be looking out for and what is the best way to handle a large amount of images being uploaded. I'm guessing that you would allow a user to upload a zip file (assuming the timeout does not effect you), and this zip file is uploaded to a specific directory, lets assume in this case a directory is created for each user in the system. You would then unzip the directory on the server and scan the user's folder for any directories containing .jpg or .png or .gif files (etc.) and then import them into a table accordingly. I'm guessing labeled by folder name. What kind of server side troubles could I run into? I'm aware that there may be many issues. Even general ideas would be could so I can then research further. Thanks! Also, I would be programming in Ruby on Rails but I think this question applies accross any language.

    Read the article

  • Multilingual support using gettext with codeigniter, best practice?

    - by tobefound
    I know how to create .po files and how to generate .mo files and then use them for translation on my Codeigniter powered site. However, I'm not quite sure on how to change language from the site GUI. I want to stick to codeigniter's default url calling schema: www.domain.com/controllername/method/param1/param2. Calling the server like this is a no-brainer: www.domain.com/controllername?lang=en Doing that for every controller using the default url schema, requires me to implement the same method in every controller, just to pass the lang parameter to the setlocale() function and then bind to my .po domain name. Feels awkward... ANy ideas how you guys work with gettext in codeigniter? And yes, I do want to work with gettext.

    Read the article

  • Best practice? iphone: sync data

    - by Andy Jacobs
    So i'm working on a project where there is data visualization. My ultimate goal is that i have a set of data shipped with the download of the iphone app. But i want it connected to a backend, that if the iphone has a connection with the internet. it can sync the changes from the backend. The syncing is no problem or the connection between the backend & the iphone. But what should i use as data storage on my iphone? what is the best way. my data is purely text and doesn't have to be secure. But it's main feature should be updating certain parts of data ( adding and deleting are not so important ) so what is the easiest (read: least time consuming development ) or the best way? sqlite? plist? ..?

    Read the article

  • What is the best practice for using lock within inherited classes

    - by JDMX
    I want to know if one class is inheriting from another, is it better to have the classes share a lock object that is defined at the base class or to have a lock object defined at each inheritance level. A very simple example of a lock object on each level of the class public class Foo { private object thisLock = new object(); private int ivalue; public int Value { get { lock( thisLock ) { return ivalue; } } set { lock( thisLock ) { ivalue= value; } } } } public class Foo2: Foo { private object thisLock2 = new object(); public int DoubleValue { get { lock( thisLock2 ) { return base.Value * 2; } } set { lock( thisLock2 ) { base.Value = value / 2; } } } } public class Foo6: Foo2 { private object thisLock6 = new object(); public int TripleDoubleValue { get { lock( thisLock6 ) { return base.DoubleValue * 3; } } set { lock( thisLock6 ) { base.DoubleValue = value / 3; } } } } A very simple example of a shared lock object public class Foo { protected object thisLock = new object(); private int ivalue; public int Value { get { lock( thisLock ) { return ivalue; } } set { lock( thisLock ) { ivalue= value; } } } } public class Foo2: Foo { public int DoubleValue { get { lock( thisLock ) { return base.Value * 2; } } set { lock( thisLock ) { base.Value = value / 2; } } } } public class Foo6: Foo2 { public int TripleDoubleValue { get { lock( thisLock ) { return base.DoubleValue * 3; } } set { lock( thisLock ) { base.DoubleValue = value / 3; } } } } Which example is the preferred way to manage locking within an inherited class?

    Read the article

  • Best practice for sharing code between OSX and IOS app

    - by Alberto
    I am creating an iOS version of an existing OSX app and am wondering what the best practices are for sharing code between the two. The code in question only depends on the foundation framework and the Sqlite dynamic library, so it should compile and run fine on both platforms. It seems to me there are three possible options: Create a single project with and OSX and an IOS targets, add source files to each target as appropriate. Create two separate projects for the OSX and IOS apps, put shared code in a common location in the workspace and add it as reference to both projects. Create three projects: OSX app, IOS app and a shared static library with an OSX and an IOS targets; add each library target to the respective application. Is there any reason one of the above approaches may be better than the other two? If not, option 2 seems to be the simplest by far.

    Read the article

  • Codechef practice question help needed - find trailing zeros in a factorial

    - by manugupt1
    I have been working on this for 24 hours now, trying to optimize it. The question is how to find the number of trailing zeroes in factorial of a number in range of 10000000 and 10 million test cases in about 8 secs. The code is as follows: #include<iostream> using namespace std; int count5(int a){ int b=0; for(int i=a;i>0;i=i/5){ if(i%15625==0){ b=b+6; i=i/15625; } if(i%3125==0){ b=b+5; i=i/3125; } if(i%625==0){ b=b+4; i=i/625; } if(i%125==0){ b=b+3; i=i/125; } if(i%25==0){ b=b+2; i=i/25; } if(i%5==0){ b++; } else break; } return b; } int main(){ int l; int n=0; cin>>l; //no of test cases taken as input int *T = new int[l]; for(int i=0;i<l;i++) cin>>T[i]; //nos taken as input for the same no of test cases for(int i=0;i<l;i++){ n=0; for(int j=5;j<=T[i];j=j+5){ n+=count5(j); //no of trailing zeroes calculted } cout<<n<<endl; //no for each trialing zero printed } delete []T; } Please help me by suggesting a new approach, or suggesting some modifications to this one.

    Read the article

  • Readability and IF-block brackets: best practice

    - by MasterPeter
    I am preparing a short tutorial for level 1 uni students learning JavaScript basics. The task is to validate a phone number. The number must not contain non-digits and must be 14 digits long or less. The following code excerpt is what I came up with and I would like to make it as readable as possible. if ( //set of rules for invalid phone number phoneNumber.length == 0 //empty || phoneNumber.length > 14 //too long || /\D/.test(phoneNumber) //contains non-digits ) { setMessageText(invalid); } else { setMessageText(valid); } A simple question I can not quite answer myself and would like to hear your opinions on: How to position the surrounding (outermost) brackets? It's hard to see the difference between a normal and a curly bracket. Do you usually put the last ) on the same line as the last condition? Do you keep the first opening ( on a line by itself? Do you wrap each individual sub-condition in brackets too? Do you align horizontally the first ( with the last ), or do you place the last ) in the same column as the if? Do you keep ) { on a separate line or you place the last ) on the same line with the last sub-condition and then place the opening { on a new line? Or do you just put the ) { on the same line as the last sub-condition? Community wiki. EDIT Please only post opinions regarding the usage and placement of brackets. The code needs not be re-factored. This is for people who have only been introduced to JavaScript a couple of weeks ago. I am not asking for opinions how to write the code so it's shorter or performs better. I would only like to know how do you place brackets around IF-conditions.

    Read the article

  • Best practice for viewflipper containing 10 linearlayouts?

    - by Brad Hein
    I'm embarking on a GUI Activity composed of a viewflipper, which I would like to contain 10 linearlayout layouts. Is it advisable to put all of my layouts into the same XML resource/layout file? If not, is there a more organized approach to coding a viewflipper with many layouts? Will having everything in the same file come at a significant performance cost?

    Read the article

  • Best practice for DAO pattern ?

    - by Tony
    I've seen a lot of codes use a service-dao pattern , I don't know the origin of this pattern . It force the front layer call service , then delegates some of the service task to dao. I want to ask : Does DAO layer do purely data access related task ? What about exception encapsulation ? Is there other pattern can be used to replace this ?

    Read the article

  • Import xml to database with high end performance and Audit log- A best Practice

    - by karthik
    Hi, I have to import big xml files to Ms SQL 2005 Database by using C# with high end Performance. Even if any record fails in middle, i have to take next record for process and failed record need to log for audit. I don't want to put insert query with in for loop. Could you please suggest a best way to do this. If I can use bulkcopy methods or Data Adapter update methods- Its very nice, But if any record fails, execution of that statement breaks and rolled back totally, right? Any alternatives and Best practices with example please..? Is Multi-threading works for me to improve performance..? Give me example please. Thanks Karthikeyan

    Read the article

  • Best Practice: Legitimate Cross-Site Scripting

    - by Ryan
    While cross-site scripting is generally regarded as negative, I've run into several situations where it's necessary. I was recently working within the confines of a very limiting content management system. I needed to include database code within the page, but the hosting server didn't have anything usable available. I set up a couple barebones scripts on my own server, originally thinking that I could use AJAX to import the contents of my scripts directly into the template of the CMS (thus retaining dynamic images, menu items, CSS, etc.). I was wrong. Due to the limitations of XMLHttpRequest objects, it's not possible to grab content from a different domain. So I thought "iFrame" - even though I'm not a fan of frames, I thought that I could create a frame that matched the width and height of the content, so that it would appear native. Again, I was blocked by cross-site scripting "protections." While I could indeed load a remote file into the iFrame, I couldn't execute JavaScript to modify its size on either the host page or inside the loaded page. In this particular scenario, I wasn't able to point a subdomain to my server. I also couldn't create a script on the CMS server that could proxy content from my server, so my last thought was to use a remote JavaScript. A remote JavaScript works. It breaks when the user has JavaScript disabled, which is a downside; but it works. The "problem" I was having with using a remote JavaScript was that I had to use the JS function document.write() to output any content. Any output that isn't JS causes script errors. In addition to using document.write() for every line, you also have to ensure that the content is escaped - or else you end up with more script errors. My solution was as follows: My script received a GET parameter ("page") and then looked for the file ({$page}.php), and read the contents into a variable. However, I had to use awkward buffering techniques in order to actually execute the included scripts (for things like database interaction) then strip the final content of all line break characters ("\n") followed by escaping all required characters. The end result is that my original script (which outputs JavaScript) accesses seemingly "standard" scripts on my server and converts their standard output to JavaScript for displaying within the CMS template. While this solution works, it seems like there may be a better way to accomplish the same thing. What is the best way to make cross-site scripting work specifically for the purpose of including content from a completely different domain?

    Read the article

  • Abstract Factory Using Generics: Is Explicitly Converting a Specified Type to Generic a Bad Practice

    - by Merritt
    The question's title says it all. I like how it fits into the rest of my code, but does it smell? public interface IFoo<T> { T Bar { get; set; } } public class StringFoo : IFoo<string> { public string Bar { get; set; } } public static class FooFactory { public static IFoo<T> CreateFoo<T>() { if (typeof(T) == typeof(string)) { return new StringFoo() as IFoo<T>; } throw new NotImplementedException(); } } UPDATE: this is sort of a duplicate of Is the StaticFactory in codecampserver a well known pattern?

    Read the article

  • Common practice for higher-order-polymorphism in scala

    - by raichoo
    Hi, I'm trying to grasp higher-order-polymophism in scala by implementing a very basic interface that describes a monad but I come across a problem that I don't really understand. I implemented the same with C++ and the code looks like this: #include <iostream> template <typename T> class Value { private: T value; public: Value(const T& t) { this->value = t; } T get() { return this->value; } }; template < template <typename> class Container > class Monad { public: template <typename A> Container<A> pure(const A& a); }; template <template <typename> class Container> template <typename A> Container<A> Monad<Container>::pure(const A& a) { return Container<A>(a); } int main() { Monad<Value> m; std::cout << m.pure(1).get() << std::endl; return 0; } When trying to do the same with scala I fail: class Value[T](val value: T) class Monad[Container[T]] { def pure[A](a: A): Container[A] = Container[A](a) } object Main { def main(args: Array[String]): Unit = { val m = new Monad[Value] m.pure(1) } } The compiler complains about: [raichoo@lain:Scala]:434> scalac highorder.scala highorder.scala:5: error: not found: value Container Container[A](a) ^ one error found What am I doing wrong here? There seems to be a fundamental concept I don't seem to understand about scala typeconstructors. Regards, raichoo

    Read the article

  • Best practice for assigning A/B test variation based on IP address

    - by mojones
    I am starting to write some code for A/B testing in a Grails web application. I want to ensure that requests from the same IP address always see the same variation. Rather than store a map of IP-variant, is it OK to simply turn the IP address into an integer by removing the dots, then use that as the seed for a random number generator? The following is taking place in a Grails Filter: def ip = request.remoteAddr def random = new Random(ip.replaceAll(/\./, '').toInteger()) def value = random.nextBoolean() session.assignment = value // value should always be the same for a given IP address I know that identifying users by IP address is not reliable, and I will be using session variables/cookies as well, but this seems to be useful for the case where we have a new session, and no cookies set (or the user has cookies disabled).

    Read the article

< Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >