Search Results

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

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

  • What is .htaccess RewriteRule best practice?

    - by Pablo
    Is it better to have a single RewriteRule with a bunch of RegEx or multiples Rules with fewer RegEx for the server to query? Will there be any performance differences? Heres is an example a single rule with almost all RegEx groups as optional: RewriteRule ^gallery/?([\w]+)?/?([\w]+)?/?([\d]+)?/?([\w]+)/?$ /gallery.php?$1=$2&start=$3&by=$4 [NC] Here are some of the rules lists that would replace the one above: RewriteRule ^gallery/category/([\w]+)/$ /gallery.php?category=$1& [NC] RewriteRule ^gallery/category/([\w]+)/([\d]+)/$ /gallery.php?category=$1&start=$2 [NC] RewriteRule ^gallery/category/([\w]+)/([\d]+)/([\w]+)/$ /gallery.php?category=$1&start=$2&by=$3 [NC] ... RewriteRule ^gallery/tag/([\w]+)/$ /gallery.php?category=$1& [NC] RewriteRule ^gallery/tag/([\w]+)/([\d]+)/$ /gallery.php?category=$1&start=$2 [NC] RewriteRule ^gallery/tag/([\w]+)/([\d]+)/([\w]+)/$ /gallery.php?category=$1&start=$2&by=$3 [NC] ... I'll be glad to hear your options or personal experiences.

    Read the article

  • Single SignOn - Best practice

    - by halfdan
    Hi Guys, I need to build a scalable single sign-on mechanism for multiple sites. Scenario: Central web application to register/manage account (Server in Europe) Several web applications that need to authenticate against my user database (Servers in US/Europe/Pacific region) I am using MySQL as database backend. The options I came up with are either replicating the user database across all servers (data security?) or allowing the servers to directly connect to my MySQL instance by explicitly allowing connections from their IPs in my.cnf (high load? single point of failure?). What would be the best way to provide a scalable and low-latency single sign-on for all web applications? In terms of data security would it be a good idea to replicate the user database across all web applications? Note: All web applications provide an API which users can use to embed widgets into their own websites. These widgets work through a token auth mechanism which will again need to authenticate against my user database.

    Read the article

  • SVN Symfony Best Practice

    - by Daniel Hertz
    So I am starting a Symfony project that I will be developing on my local machine and pushing changes everyday to the live server. I wanna use SVN as the version control but Im not sure what the best way to set it up is. Do i make the actual html directory on the server be the repo so that when I check things in it goes live? Do I make it a separate directory and move things over by hand? Any help would be appreciated! Thanks!

    Read the article

  • jQuery e.target bubbling best practice ?

    - by olouv
    In my heavy-ajax code, i always bind "click" the body tag & act depending on $(e.target) & using $.fn.hasClass(). However when i click on an anchor that has a </span> tag inside, my $(e.target) equals this node, and not the parent anchor as i would like it to. From now on, i have used this trick (var $t = $(e.target);) : /** bubbling **/ if($t.get(0).tagName !== "A" && $t.get(0).tagName !== "AREA") { $t = $t.parent("a"); if(empty($t)) return true; //else console.log("$t.bubble()", $t); } It feels wrong somehow... Do you have any better implementation ? $.fn.live() does not solve my issue as it still returns the span as the target. Moreover i'm looking for speed (running on atom-based touch devices) & live appeared to be way slower (twice) : http://jsperf.com/bind-vs-click/3 In fact, as @Guffa pointed, using $.fn.live() solves the span bubbling issue as i don't need the event.target anymore. I guess there is no other "right" answer here (using bind).

    Read the article

  • Should I practice "mockist" or "classical" TDD?

    - by Daryl Spitzer
    I've read (and re-read) Martin Fowler's Mocks Aren't Stubs. In it, he defines two different approaches to TDD: "Classical" and "Mockist". He attempts to answer the question "So should I be a classicist or a mockist?", but he admits that he has never tried mockist TDD on "anything more than toys." So I thought I'd ask the question here. Good answers may repeat Fowler's arguments (but hopefully more clearly) or add arguments that he didn't think of or that others have come up with since Fowler last updated the essay back in January 2007.

    Read the article

  • Configuration file reading. Best practice

    - by Andrew Florko
    Application stores configuration data in custom section of configuration file. This information is used all over the application. Nowadays I use helper static class to to provide access like this (some code omitted or simplified): [XmlRoot("webSiteSection")] public class WebSiteConfig : IConfigurationSectionHandler { public static WebSiteConfig Current { get { if (_current == null) _current = (WebSiteConfig) ConfigurationManager.GetSection("webSiteSection"); return _current; } } [XmlElement("section1")] public Section1 Section1 { get; set; } [XmlElement("section2")] public Section2 Section2 { get; set; } ... public object Create(object parent, object configContext, XmlNode section) { var serializer = new XmlSerializer(typeof(WebSiteConfig)); return serializer.Deserialize(new XmlNodeReader(section)); } } Then I use it like this <%: WebSiteConfig.Current.Section1.Value1 %> <%: WebSiteConfig.Current.Section1.Value2 %> What do you think of it? I find it usable because it keeps code simple, but also confused as IConfigurationSectionHandler is deprecated since .NET Framework 2.0

    Read the article

  • best practice on precedence of variable declaration and error handling in C

    - by guest
    is there an advantage in one of the following two approaches over the other? here it is first tested, whether fopen succeeds at all and then all the variable declarations take place, to ensure they are not carried out, since they mustn't have had to void func(void) { FILE *fd; if ((fd = fopen("blafoo", "+r")) == NULL ) { fprintf(stderr, "fopen() failed\n"); exit(EXIT_FAILURE); } int a, b, c; float d, e, f; /* variable declarations */ /* remaining code */ } this is just the opposite. all variable declarations take place, even if fopen fails void func(void) { FILE *fd; int a, b, c; float d, e, f; /* variable declarations */ if ((fd = fopen("blafoo", "+r")) == NULL ) { fprintf(stderr, "fopen() failed\n"); exit(EXIT_FAILURE); } /* remaining code */ } does the second approach produce any additional cost, when fopen fails? would love to hear your thoughts!

    Read the article

  • Buffer management for socket application best practice

    - by Poni
    Having a Windows IOCP app............ I understand that for async i/o operation (on network) the buffer must remain valid for the duration of the send/read operation. So for each connection I have one buffer for the reading. For sending I use buffers to which I copy the data to be sent. When the sending operation completes I release the buffer so it can be reused. So far it's nice and not of a big issue. What remains unclear is how do you guys do this? Another thing is that even when having things this way, I mean multi-buffers, the receiver side might be flooded (talking from experience) with data. Even setting SO_RCVBUF to 25MB didn't help in my testings. So what should I do? Have a to-be-sent queue?

    Read the article

  • Best practice way to handle variable content margin?

    - by Aithne
    Ok, so a quick site that I am throwing together for a friend has about 20 static pages. Each one with a small amount of content. the div Container contains, well, the div Content, and the div Content contains, obviously, the content that changes on each page. Now, depending on the length of the content, I want a different margin at the top. The less content, then the larger the margin. Simply an aesthetic choice. For example, if the content almost fills the static sized container, there is less padding, but a 1 line page of content might be 1/3 of the way down the static container. Centering the content in the div wont do, as that creates too large of a margin. Whats the best way to handle this? A new class for each content with a different margin? A new Id, so that it is in its own special div positioned or margined differently? Inline css on each page to override the standard css for div Content? A differnt spacer div inside Container before Content on each page? Some sort of scripting along the lines of margin of Content = (ContainerHeight - ContentHeight) / 3? Whats the acceptable way of doing this? I don't want to get into bad habits.

    Read the article

  • Rails best practice on conditional parameters in a controller action

    - by randombits
    I have a controller create action looks for one or more parameters in the following ruleset. Let's say we have two parameters, foo and bar. The rules are the following: 1) if foo doesn't exist in the parameter list, bar must. 2) if bar doesn't exist in the parameter list, foo must. 3) they can both co-exist. they can't both be omitted (that's redundant with my rules above :) ) Can anyone show an example in Rails on how this is handled in the controller? Should I use a before_filter? Would appreciate some guidance as this isn't something that ActiveRecord validates.. so I'd need to build an error message to the user directly from controller logic, not model logic. For bonus points, I output the error in XML, so if you can show how that's done, that'd be great. Hypothetically let's call the resource "Lorem", so it is created via http://foo/lorem.xml and we have lorem_controller.rb.

    Read the article

  • Best practice for Python Assert

    - by meade
    Is there a performance or code maintenance issue with using assert as part of the standard code instead of using it just for debugging purposes? Is assert x >= 0, 'x is less then zero' and better or worse then if x < 0: raise Exception, 'x is less then zero' Also, is there anyway to set a business rule like if x < 0 raise error that is always checked with out the try, except, finally so, if at anytime throughout the code x is < 0 an error is raised, like if you set assert x < 0 at the start of a function, anywhere within the function where x becomes less then 0 an exception is raised?

    Read the article

  • Best Practice of Field Collapsing in SOLR 1.4

    - by Dominik
    I need a way to collapse duplicate (defined in terms of a string field with an id) results in solr. I know that such a feature is comming in the next version (1.5), but I can't wait for that. What would be the best way to remove duplicates using the current stable version 1.4? Given that finding duplicates in my case is really easy (comparison of a string field), should it be a Filter, should I overwrite the existing SearchComponent or write a new Component, or use some external libraries like carrot2? The overall result count should reflect the shortened result.

    Read the article

  • best practice to persist classes model

    - by Yaron Naveh
    My application contains a set of model classes. e.g. Person, Department... The user changes values for instances of these classes in the UI and the classes are persisted to my "project" file. Next time the user can open and edit the project. Next version of my product may change the model classes drastically. It will still need to open existing projects files (I will know how to handle missing data). How is it best to persist my model classes to the project file? The easiest way to persist classes is Data contract serialization. However it will fail on breaking changes (I expect to have such). How to handle this? use some other persistence, e.g. name-value collection or db which is more tolerance ship a "project converter" application to migrate old projects. This requires to either ship with both old and new models or to manipulate xml, which is best?

    Read the article

  • Best practice - logging events (general) and changes (database)

    - by b0x0rz
    need help with logging all activities on a site as well as database changes. requirements: * should be in database * should be easily searchable by initiator (user name / session id), event (activity type) and event parameters i can think of a database design but either it involves a lot of tables (one per event) so i can log each of the parameters of an event in a separate field OR it involves one table with generic fields (7 int numeric and 7 text types) and log everything in one table with event type field determining what parameter got written where (and hoping that i don't need more than 7 fields of a certain type, or 8 or 9 or whatever number i choose)... example of entries (the usual things): [username] login failed @datetime [username] login successful @datetime [username] changed password @datetime, estimated security of password [low/ok/high/perfect] @datetime [username] clicked result [result number] [result id] after searching for [search string] and got [number of results] @datetime [username] clicked result [result number] [result id] after searching for [search string] and got [number of results] @datetime [username] changed profile name from [old name] to [new name] @datetime [username] verified name with [credit card type] credit card @datetime datbase table [table name] purged of old entries @datetime via automated process etc... so anyone dealt with this before? any best practices / links you can share? i've seen it done with the generic solution mentioned above, but somehow that goes against what i learned from database design, but as you can see the sheer number of events that need to be trackable (each user will be able to see this info) is giving me headaches, BUT i do LOVE the one event per table solution more than the generic one. any thoughts? edit: also, is there maybe an authoritative list of such (likely) events somewhere? thnx stack overflow says: the question you're asking appears subjective and is likely to be closed. my answer: probably is subjective, but it is directly related to my issue i have with designing a database / writing my code, so i'd welcome any help. also i tried narrowing down the ideas to 2 so hopefully one of these will prevail, unless there already is an established solution for these kinds of things.

    Read the article

  • Cocoa Touch best practice for capturing/logging/diagnosing crashes

    - by Dylan
    As I get closer to releasing my first public iPhone app I'm concerned about catching crashes in the field. I'm curious to hear how others have gone about this. I'm not sure what's possible outside of the debugger. Is all lost with an EXC_BAD_ACCESS or can I still catch it and get something useful into a log? Is the program main() the spot to put a @try/@catch?

    Read the article

  • best practice - loging events (general) and changes (database)

    - by b0x0rz
    need help with logging all activities on a site as well as database changes. requirements: * should be in database * should be easily searchable by initiator (user name / session id), event (activity type) and event parameters i can think of a database design but either it involves a lot of tables (one per event) so i can log each of the parameters of an event in a separate field OR it involves one table with generic fields (7 int numeric and 7 text types) and log everything in one table with event type field determining what parameter got written where (and hoping that i don't need more than 7 fields of a certain type, or 8 or 9 or whatever number i choose)... example of entries (the usual things): [username] login failed @datetime [username] login successful @datetime [username] changed password @datetime, estimated security of password [low/ok/high/perfect] @datetime [username] clicked result [result number] [result id] after searching for [search string] and got [number of results] @datetime [username] clicked result [result number] [result id] after searching for [search string] and got [number of results] @datetime [username] changed profile name from [old name] to [new name] @datetime [username] verified name with [credit card type] credit card @datetime datbase table [table name] purged of old entries @datetime etc... so anyone dealt with this before? any best practices / links you can share? i've seen it done with the generic solution mentioned above, but somehow that goes against what i learned from database design, but as you can see the sheer number of events that need to be trackable (each user will be able to see this info) is giving me headaches, BUT i do LOVE the one event per table solution more than the generic one. any thoughts? edit: also, is there maybe an authoritative list of such (likely) events somewhere? thnx stack overflow says: the question you're asking appears subjective and is likely to be closed. my answer: probably is subjective, but it is directly related to my issue i have with designing a database / writing my code, so i'd welcome any help. also i tried narrowing down the ideas to 2 so hopefully one of these will prevail, unless there already is an established solution for these kinds of things.

    Read the article

  • 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.

    Read the article

  • Secure database connection. DAL .net architecture best practice

    - by Andrew Florko
    We have several applications that are installed in several departments that interact with database via Intranet. Users tend to use weak passwords or store login/password written on a shits of paper where everybody can see them. I'm worried about login/password leakage & want to minimize consequences. Minimizing database-server attack surface by hiding database-server from Intranet access would be a great idea also. I'm thinking about intermediary data access service method-based security. It seems more flexible than table-based or connection-based database-server one. This approach also allows to hide database-server from public Intranet. What kind of .net technologies and best practices would you suggest? Thank in you in advance!

    Read the article

  • asp.net web forms best practice to retrieve dynamic server control values

    - by Andrew Florko
    I populate web form with dynamic list of exams from database. I want user to enter examination marks for each exam. There is list of exam titles and textbox near each title. I create list with repeater control: <asp:Repeater ID="rptExams" runat="server" onitemdatabound="rptExams_ItemDataBound" > <ItemTemplate> <tr> <td> <asp:Literal runat="server" ID="ltTitle"/> </td> <td> <asp:HiddenField runat="server" ID="hfId"/> <asp:Textbox runat="server" ID="tbMark"/> </td> </tr> </ItemTemplate> </asp:Repeater> And bind data to repeater on page_init: class Exam { public int Id { get; set;} public string Title { get; set;} } ... // this list is retrieved from database actually Exam[] Exams = new Exam[] { new Exam { Id = 1, Title = "Math"}, new Exam { Id = 2, Title = "History"} }; ... protected void Page_Init(object sender, EventArgs e) { rptExams.DataSource = Exams; rptExams.DataBind(); } So far so good. Then I have to retrieve data on postback. I have two ways but both of them looks ugly. Idea is to store dynamically created databounded controls on ItemDataBoundEvent in Page_Init stage, and process their values in Page_Load stage. It looks like this: private Dictionary<HiddenField, TextBox> Id2Mark = new Dictionary<HiddenField, TextBox>(); protected void rptExams_ItemDataBound(object sender, RepeaterItemEventArgs e) { ... if (IsPostBack) { var tbMark = (TextBox)e.Item.FindControl("tbMark"); var hfId = (HiddenField)e.Item.FindControl("hfId"); // store dynamically created controls Id2Mark.Add(hfId, tbMark); } ... } protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { foreach (var pair in Id2Mark) { int examId = Int32.Parse(pair.Key.Value); string mark = pair.Value.Text; // PROCESS } ... I'm completely sure there is a better way to retrieve data from dynamically created controls. Thank you in advance!

    Read the article

  • html clickable layout area. best practice

    - by Andrew Florko
    I am bad in html layout but I have to produce it :) I want to make big button on a page that is implemented as div with children tags (maybe - a bad idea). I can handle click event on boundary-div with javascript but it requires javascript enabled. I can wrap boundary-div with "anchor" tag but is doesn't work in IE Please, suggest me the best way to implement this. <a href="..."> <table> <td> ... </td> <td> ... <table> ... </table> </td> </table> </a>

    Read the article

  • Java Best Practice for type resolution at runtime.

    - by Brian
    I'm trying to define a class (or set of classes which implement the same interface) that will behave as a loosely typed object (like JavaScript). They can hold any sort of data and operations on them depend on the underlying type. I have it working in three different ways but none seem ideal. These test versions only allow strings and integers and the only operation is add. Adding integers results in the sum of the integer values, adding strings concatenates the strings and adding an integer to a string converts the integer to a string and concatenates it with the string. The final version will have more types (Doubles, Arrays, JavaScript-like objects where new properties can be added dynamically) and more operations. Way 1: public interface DynObject1 { @Override public String toString(); public DynObject1 add(DynObject1 d); public DynObject1 addTo(DynInteger1 d); public DynObject1 addTo(DynString1 d); } public class DynInteger1 implements DynObject1 { private int value; public DynInteger1(int v) { value = v; } @Override public String toString() { return Integer.toString(value); } public DynObject1 add(DynObject1 d) { return d.addTo(this); } public DynObject1 addTo(DynInteger1 d) { return new DynInteger1(d.value + value); } public DynObject1 addTo(DynString1 d) { return new DynString1(d.toString()+Integer.toString(value)); } } ...and similar for DynString1 Way 2: public interface DynObject2 { @Override public String toString(); public DynObject2 add(DynObject2 d); } public class DynInteger2 implements DynObject2 { private int value; public DynInteger2(int v) { value = v; } @Override public String toString() { return Integer.toString(value); } public DynObject2 add(DynObject2 d) { Class c = d.getClass(); if(c==DynInteger2.class) { return new DynInteger2(value + ((DynInteger2)d).value); } else { return new DynString2(toString() + d.toString()); } } } ...and similar for DynString2 Way 3: public class DynObject3 { private enum ObjectType { Integer, String }; Object value; ObjectType type; public DynObject3(Integer v) { value = v; type = ObjectType.Integer; } public DynObject3(String v) { value = v; type = ObjectType.String; } @Override public String toString() { return value.toString(); } public DynObject3 add(DynObject3 d) { if(type==ObjectType.Integer && d.type==ObjectType.Integer) { return new DynObject3(Integer.valueOf(((Integer)value).intValue()+((Integer)value).intValue())); } else { return new DynObject3(value.toString()+d.value.toString()); } } } With the if-else logic I could use value.getClass()==Integer.class instead of storing the type but with more types I'd change this to use a switch statement and Java doesn't allow switch to use Classes. Anyway... My question is what is the best way to go about something thike this?

    Read the article

  • What is best practice about having one-many hibernate

    - by Patrick
    Hi all, I believe this is a common scenario. Say I have a one-many mapping in hibernate Category has many Item Category: @OneToMany( cascade = {CascadeType.ALL},fetch = FetchType.LAZY) @JoinColumn(name="category_id") @Cascade( value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN ) private List<Item> items; Item: @ManyToOne(targetEntity=Category.class,fetch=FetchType.EAGER) @JoinColumn(name="category_id",insertable=false,updatable=false) private Category category; All works fine. I use Category to fully control Item's life cycle. But, when I am writing code to update Category, first I get Category out from DB. Then pass it to UI. User fill in altered values for Category and pass back. Here comes the problem. Because I only pass around Category information not Item. Therefore the Item collection will be empty. When I call saveOrUpdate, it will clean out all associations. Any suggestion on what's best to address this? I think the advantage of having Category controls Item is to easily main the order of Item and not to confuse bi-directly. But what about situation that you do want to just update Category it self? Load it first and merge? Thank you.

    Read the article

  • SQL Query - 20mil records - Best practice to return information

    - by eqiz
    I have a SQL database that has the following table: Table: PhoneRecords ID(identity Seed) FirstName LastName PhoneNumber ZipCode Very simple straight forward table. This table has over 20million records. I am looking for the best way to do queries that pull out records based off area codes from the table. For instance here is an example query that I have done. SELECT phonenumber, firstname FROM [PhoneRecords] WHERE (phone LIKE '2012042%') OR (phone LIKE '2012046%') OR (phone LIKE '2012047%') OR (phone LIKE '2012083%') OR (phone LIKE '2012088%') OR (phone LIKE '2012841%') As you can see this is an ugly query, but it would get the job done (if I wasn't running into timeout issues) Can anyone tell me the best way for speed/optimization to do the above query to display the results? Currently that query above takes around 2 hours to complete on a 9gb 1600mhz ram, i7 930 quadcore OC'd 4.01ghz. I obviously have the computer power required to do such a query, but still takes too long for queries.

    Read the article

  • Best practice accessing an array set within a class

    - by user350599
    I have created a basic class for a customer. I haven't done this before and want to know the best way to access the data. Should I have a get() method for every field in the customer array or should I simply pass the customer array back and access with the page. i.e. Just return the array class Customer { protected $id; protected $customer; public function __construct($customer_id) { $this->id = $customer_id; $this->set_customer(); } protected function set_customer() { $query = mysql_query("SELECT * FROM customer WHERE id = '$this->id'"); $this->customer = mysql_fetch_row($query); } public function get_customer() { return $this->customer; } } versus create a method for each item in the array class Customer { protected $id; protected $customer; public function __construct($customer_id) { $this->id = $customer_id; $this->set_customer(); } protected function set_customer() { $query = mysql_query("SELECT * FROM customer WHERE id = '$this->id'"); $this->customer = mysql_fetch_row($query); } public function get_customer_name() { return $this->customer->customer_name; } ... ... } versus option 3 based on Tobias' feedback: (not sure if syntax is correct) class Customer { protected $id; protected $customer; public function __construct($customer_id) { $this->id = $customer_id; return $this->set_customer(); } protected function set_customer() { $query = mysql_query("SELECT * FROM customer WHERE id = '$this->id'"); return mysql_fetch_row($query); } }

    Read the article

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