Daily Archives

Articles indexed Friday April 16 2010

Page 21/120 | < Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >

  • Improve long mysql query

    - by John Adawan
    I have a php mysql query like this $query = "SELECT * FROM articles FORCE INDEX (articleindex) WHERE category='$thiscat' and did>'$thisdid' and mid!='$thismid' and status='1' and group='$thisgroup' and pid>'$thispid' LIMIT 10"; As optimization, I've indexed all the parameters in articleindex and I use force index to force mysql to use the index, supposedly for faster processing. But it seems that this query is still quite slow and it's causing a jam and maxing out the max mysql connection limit. Let's discuss how we can improve on such long query.

    Read the article

  • Possible to convert list of #defines into strings (C++)

    - by brandonC
    Suppose I have a list of #defines in a header file for an external library. These #defines represent error codes returned from functions. I want to write a conversion function that can take as an input an error code and return as an output a string literal representing the actual #define name. As an example, if I have #define NO_ERROR 0 #define ONE_KIND_OF_ERROR 1 #define ANOTHER_KIND_OF_ERROR 2 I would like a function to be able to called like int errorCode = doSomeLibraryFunction(); if (errorCode) writeToLog(convertToString(errorCode)); And have convertToString() be able to auto-convert that error code without being a giant switch-case looking like const char* convertToString(int errorCode) { switch (errorCode) { case NO_ERROR: return "NO_ERROR"; case ONE_KIND_OF_ERROR: return "ONE_KIND_OF_ERROR"; ... ... ... I have a feeling that if this is possible, it would be possible using templates and metaprogramming, but that would only work the error codes were actually a type and not a bunch of processor macros. Thanks

    Read the article

  • Facebook connect | Django exception

    - by MMRUser
    Continue from this question. I'm getting this error when running the application Caught an exception while rendering: Tried xd_receiver in module myfirstapp.fbapp.views. Error was: 'module' object has no attribute 'xd_receiver' <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript"></script> <script type="text/javascript"> FB_RequireFeatures(["XFBML"], function() { FB.Facebook.init("{{ facebook_api_key }}", " {% url facebook_xd_receiver %} ") } ); function facebookConnect(form){ FB.Connect.requireSession(); FB.Facebook.get_sessionState().waitUntilReady( function(){ form.submit(); } ); } PS: Can somebody please tell me a good tutorial on django socialregistration (which covers all the basic steps) I'm a newbe, I tried facebook dev tutorial but that also didn't work..

    Read the article

  • Javascript check if it has passed midnight since a certain time

    - by Jonah
    I need to create a javascript function that checks if it has been a day since timeX (an instance of Date). I do NOT mean whether is has been 24 hours since timeX, but instead whether it has passed a midnight since timeX. I am a PHP expert, not a JavaScript one, so I was wondering if anyone here had any quick answers. Thanks! function(dateLast, dateNow) {...}

    Read the article

  • Rails: Best practice to store user settings?

    - by ole_berlin
    Hi, I'm wondering what the best way is to store user settings? For a web 2.0 app I want users to be able to select certain settings. At the moment is it only when to receive email notifications. The easiest way would be to just create a Model "Settings" and have a column for every setting and then have a 1-1 relationship with users. But is there a pattern to solve this better? Is it maybe better to store the info in the user table itself? Or should I use a table with "settings_name" and "settings_value" to be completely open about the type of settings stored there (without having to run any migrations when adding options)? What is your opinion? Thanks

    Read the article

  • ASP.NET MVC Paging/Sorting/Filtering a list using ModelMetadata

    - by rajbk
    This post looks at how to control paging, sorting and filtering when displaying a list of data by specifying attributes in your Model using the ASP.NET MVC framework and the excellent MVCContrib library. It also shows how to hide/show columns and control the formatting of data using attributes.  This uses the Northwind database. A sample project is attached at the end of this post. Let’s start by looking at a class called ProductViewModel. The properties in the class are decorated with attributes. The OrderBy attribute tells the system that the Model can be sorted using that property. The SearchFilter attribute tells the system that filtering is allowed on that property. Filtering type is set by the  FilterType enum which currently supports Equals and Contains. The ScaffoldColumn property specifies if a column is hidden or not The DisplayFormat specifies how the data is formatted. public class ProductViewModel { [OrderBy(IsDefault = true)] [ScaffoldColumn(false)] public int? ProductID { get; set; }   [SearchFilter(FilterType.Contains)] [OrderBy] [DisplayName("Product Name")] public string ProductName { get; set; }   [OrderBy] [DisplayName("Unit Price")] [DisplayFormat(DataFormatString = "{0:c}")] public System.Nullable<decimal> UnitPrice { get; set; }   [DisplayName("Category Name")] public string CategoryName { get; set; }   [SearchFilter] [ScaffoldColumn(false)] public int? CategoryID { get; set; }   [SearchFilter] [ScaffoldColumn(false)] public int? SupplierID { get; set; }   [OrderBy] public bool Discontinued { get; set; } } Before we explore the code further, lets look at the UI.  The UI has a section for filtering the data. The column headers with links are sortable. Paging is also supported with the help of a pager row. The pager is rendered using the MVCContrib Pager component. The data is displayed using a customized version of the MVCContrib Grid component. The customization was done in order for the Grid to be aware of the attributes mentioned above. Now, let’s look at what happens when we perform actions on this page. The diagram below shows the process: The form on the page has its method set to “GET” therefore we see all the parameters in the query string. The query string is shown in blue above. This query gets routed to an action called Index with parameters of type ProductViewModel and PageSortOptions. The parameters in the query string get mapped to the input parameters using model binding. The ProductView object created has the information needed to filter data while the PageAndSorting object is used for paging and sorting the data. The last block in the figure above shows how the filtered and paged list is created. We receive a product list from our product repository (which is of type IQueryable) and first filter it by calliing the AsFiltered extension method passing in the productFilters object and then call the AsPagination extension method passing in the pageSort object. The AsFiltered extension method looks at the type of the filter instance passed in. It skips properties in the instance that do not have the SearchFilter attribute. For properties that have the SearchFilter attribute, it adds filter expression trees to filter against the IQueryable data. The AsPagination extension method looks at the type of the IQueryable and ensures that the column being sorted on has the OrderBy attribute. If it does not find one, it looks for the default sort field [OrderBy(IsDefault = true)]. It is required that at least one attribute in your model has the [OrderBy(IsDefault = true)]. This because a person could be performing paging without specifying an order by column. As you may recall the LINQ Skip method now requires that you call an OrderBy method before it. Therefore we need a default order by column to perform paging. The extension method adds a order expressoin tree to the IQueryable and calls the MVCContrib AsPagination extension method to page the data. Implementation Notes Auto Postback The search filter region auto performs a get request anytime the dropdown selection is changed. This is implemented using the following jQuery snippet $(document).ready(function () { $("#productSearch").change(function () { this.submit(); }); }); Strongly Typed View The code used in the Action method is shown below: public ActionResult Index(ProductViewModel productFilters, PageSortOptions pageSortOptions) { var productPagedList = productRepository.GetProductsProjected().AsFiltered(productFilters).AsPagination(pageSortOptions);   var productViewFilterContainer = new ProductViewFilterContainer(); productViewFilterContainer.Fill(productFilters.CategoryID, productFilters.SupplierID, productFilters.ProductName);   var gridSortOptions = new GridSortOptions { Column = pageSortOptions.Column, Direction = pageSortOptions.Direction };   var productListContainer = new ProductListContainerModel { ProductPagedList = productPagedList, ProductViewFilterContainer = productViewFilterContainer, GridSortOptions = gridSortOptions };   return View(productListContainer); } As you see above, the object that is returned to the view is of type ProductListContainerModel. This contains all the information need for the view to render the Search filter section (including dropdowns),  the Html.Pager (MVCContrib) and the Html.Grid (from MVCContrib). It also stores the state of the search filters so that they can recreate themselves when the page reloads (Viewstate, I miss you! :0)  The class diagram for the container class is shown below.   Custom MVCContrib Grid The MVCContrib grid default behavior was overridden so that it would auto generate the columns and format the columns based on the metadata and also make it aware of our custom attributes (see MetaDataGridModel in the sample code). The Grid ensures that the ShowForDisplay on the column is set to true This can also be set by the ScaffoldColumn attribute ref: http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.html) Column headers are set using the DisplayName attribute Column sorting is set using the OrderBy attribute. The data is formatted using the DisplayFormat attribute. Generic Extension methods for Sorting and Filtering The extension method AsFiltered takes in an IQueryable<T> and uses expression trees to query against the IQueryable data. The query is constructed using the Model metadata and the properties of the T filter (productFilters in our case). Properties in the Model that do not have the SearchFilter attribute are skipped when creating the filter expression tree.  It returns an IQueryable<T>. The extension method AsPagination takes in an IQuerable<T> and first ensures that the column being sorted on has the OrderBy attribute. If not, we look for the default OrderBy column ([OrderBy(IsDefault = true)]). We then build an expression tree to sort on this column. We finally hand off the call to the MVCContrib AsPagination which returns an IPagination<T>. This type as you can see in the class diagram above is passed to the view and used by the MVCContrib Grid and Pager components. Custom Provider To get the system to recognize our custom attributes, we create our MetadataProvider as mentioned in this article (http://bradwilson.typepad.com/blog/2010/01/why-you-dont-need-modelmetadataattributes.html) protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName) { ModelMetadata metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);   SearchFilterAttribute searchFilterAttribute = attributes.OfType<SearchFilterAttribute>().FirstOrDefault(); if (searchFilterAttribute != null) { metadata.AdditionalValues.Add(Globals.SearchFilterAttributeKey, searchFilterAttribute); }   OrderByAttribute orderByAttribute = attributes.OfType<OrderByAttribute>().FirstOrDefault(); if (orderByAttribute != null) { metadata.AdditionalValues.Add(Globals.OrderByAttributeKey, orderByAttribute); }   return metadata; } We register our MetadataProvider in Global.asax.cs. protected void Application_Start() { AreaRegistration.RegisterAllAreas();   RegisterRoutes(RouteTable.Routes);   ModelMetadataProviders.Current = new MvcFlan.QueryModelMetaDataProvider(); } Bugs, Comments and Suggestions are welcome! You can download the sample code below. This code is purely experimental. Use at your own risk. Download Sample Code (VS 2010 RTM) MVCNorthwindSales.zip

    Read the article

  • Iframe Vs Dynamiclly load web user controls

    - by kevin
    I need some advice on technique to perform page redirect in asp.net. Which one is more recommended to use in asp.net? Dynamically changed the src of the Iframe to difference aspx. Dim frame As HtmlControl = CType(Me.FindControl("frameMain"), HtmlControl) frame.Attributes("src") = "page1.aspx" Dynamically load web user controls to an asp:panel. panelMain.Controls.Clear() panelMain.Controls.Add(LoadControl("WebControl/page1.ascx")) (convert all aspx page to web user controls)

    Read the article

  • XMLHttpRequest - JSON - .NET

    - by user318194
    I am trying to send JSON from my mozilla addon to my asp.net page. var myJSONObject = {"userName": una,"password": pass}; request = new XMLHttpRequest(); request.open("GET",http://www.google.com/jo=" + myJSONObject,true, null, null); on my .net page I have tried several ways of doing it but not able to find the best way to serialize and deserialize the code. All I need is to send the json data back n forth and parse it on C# n javascript. I am new to all this so any guidance and/or change in direction is appreciated.

    Read the article

  • how to indicate a change in list elements' order using jquery?

    - by keisimone
    i am using jquery sortable. right now i have a list of items that i can ALREADY use drag and drop. which is cool. i will use a submit button at the bottom of the list to submit the new order. the change in the list is not automatically submitted. All i need is somehow indicate that an element's position has changed. I googled quite a bit. no answer. original list: item1 item2 item3 item4 item5 submitbutton here. changed list: i moved item 2 below item3 for eg. item1 item3 item2 * item4 item5 submitbutton here. how do i use the sortable in jquery for me to display a sign on the item 2? i think should be the change event of sortable but i still do not know how to use it since i am a newbie in jquery. http://docs.jquery.com/UI/Sortable#event-change thank you.

    Read the article

  • Bread-crumb style navigation for Winforms

    - by lazycoder
    Does anybody know of a bread-crumb style navigation for Winforms like the one from DotNetBar. http://www.devcomponents.com/dotnetbar/BreadCrumbHorizontalTreeControl.aspx I really like that control. However I am using a other UI library already and just for this control I do not want a reference to another 4 MB lib. I just need this control. Does anybody if something like this is available as a standalone control?

    Read the article

  • Facebook connect problem

    - by Stefano
    I'm trying to add facebook connect button to my ZF web site. After i click on FB connect button the popup with email and password fields opens. But when i send email and password to login with facebook the popub don't close and reload the same page where the facebook connect button was. Any idea? Sorry for my english ..

    Read the article

  • MySQL Connector: parameters not being added

    - by LookitsPuck
    Hey all! Looking at my query log for MySQL, I see my parameters aren't being added. Here's my code: MySqlConnection conn = new MySqlConnection(ApplicationVariables.ConnectionString()); MySqlCommand com = new MySqlCommand(); try { conn.Open(); com.Connection = conn; com.CommandText = String.Format(@"SELECT COUNT(*) AS totalViews FROM pr_postreleaseviewslog AS prvl WHERE prvl.dateCreated BETWEEN (@startDate) AND (@endDate) AND prvl.postreleaseID IN ({0})" , ids); com.CommandType = CommandType.Text; com.Parameters.Add(new MySqlParameter("@startDate", thisCampaign.Startdate)); com.Parameters.Add(new MySqlParameter("@endDate", endDate)); numViews = Convert.ToInt32(com.ExecuteScalar()); } catch (Exception ex) { } finally { conn.Dispose(); com.Dispose(); } Looking at the query log, I see this: SELECT COUNT(*) AS totalViews FROM pr_postreleaseviewslog AS prvl WHERE prvl.dateCreated BETWEEN (@startDate) AND (@endDate) AND prvl.postreleaseID IN (1,2) I've used the MySQL .NET connector on countless projects (I actually have a base class that takes care of opening these connections, and closing them with transactions, etc.). However, I took over this application, and here I am now. Thanks for the help!

    Read the article

  • Accessing elements of List<List<string>>

    - by shiv09
    Hello Friends........... Can anyone let me know how can access an element of a list that has been added to a list of list............. I'll mention the code............ List str = new List(); List stud = new List(); A method has been defined that inserts data into str and after the method gets over......... stud.Add(str); The method and stud.Add(str) is on a button click...... so, each time str contains different data....... the problem is I want to search in whole of stud i.e. all the str created, whether str[0]==textBox3.Text; I'm confused in the For loops...how to reach to all the str[0] in stud to verify the condition...................

    Read the article

  • Threading questions

    - by JK
    If I spawn a secondary thread and the threaded method calls other methods, are those methods run in the secondary thread or the main thread? Is there a way to determine on which thread a specified piece of code is being run?

    Read the article

  • jruby/activerecord-jdbc/tomcat/DB2 ready for enterprise?

    - by arkadiy
    I am trying to introduce RoR to my company and I have two ways of doing so in my mind: (1) rails/ibm_db2/passenger/DB2 - which is my preferable way but it is not really supported by company's infrastructure. (2) jruby/activerecord-jdbc/tomcat/DB2 - probably easier way to migrate relying on current infrastructure and java libs IF I have a proof this is an enterprise ready technology. Does anyone know if there is any prof that jruby/aciverecord-jdbc-adapter/DB2/tomcat is mature enough for production? Are there any problems I should know about during Development/Deployment/Runtime? My webapp is for a company intranet, around 200~400 active users.

    Read the article

  • How to get this done in mysql?

    - by bala3569
    Consider i have a registartion table and there is field prefLocationId and it contains value like this 1,2,3,2,1,4 and so many.... And i have a table prefLocation which looks like this Id LocationName 1 Chennai 2 Mumbai 3 Kolkatta 4 Delhi and i want to select record of users and show values like Chennai,Mumbai,Kolkatta,Mumbai,Chennai,Delhi and so on...

    Read the article

  • Facing problem in configuring Reporting Server

    - by idrees99
    Dear All, I am unable to configure reporting server with sql server 2005 express edition. I have posted the link of a screen shot which shows the status.when ever i go to configure the reporting services it gives me the following errors(see screen shot)...also unable to start the reporting services.It starts and then stopped automatically.... I am using windowsxp professional..... Need help... thanks. ![alt text][1] http://www.freeimagehosting.net/image.php?8977c7f37a.jpg

    Read the article

< Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >