Daily Archives

Articles indexed Tuesday April 20 2010

Page 13/121 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • MySQL stuck on "using filesort" when doing an "order by"

    - by noko
    I can't seem to get my query to stop using filesort. This is my query: SELECT s.`pilot`, p.`name`, s.`sector`, s.`hull` FROM `pilots` p LEFT JOIN `ships` s ON ( (s.`game` = p.`game`) AND (s.`pilot` = p.`id`) ) WHERE p.`game` = 1 AND p.`id` <> 2 AND s.`sector` = 43 AND s.`hull` > 0 ORDER BY p.`last_move` DESC Table structures: CREATE TABLE IF NOT EXISTS `pilots` ( `id` mediumint(5) unsigned NOT NULL AUTO_INCREMENT, `game` tinyint(3) unsigned NOT NULL DEFAULT '0', `last_move` int(10) NOT NULL DEFAULT '0', UNIQUE KEY `id` (`id`), KEY `last_move` (`last_move`), KEY `game_id_lastmove` (`game`,`id`,`last_move`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; CREATE TABLE IF NOT EXISTS `ships` ( `id` mediumint(5) unsigned NOT NULL AUTO_INCREMENT, `game` tinyint(3) unsigned NOT NULL DEFAULT '0', `pilot` mediumint(5) unsigned NOT NULL DEFAULT '0', `sector` smallint(5) unsigned NOT NULL DEFAULT '0', `hull` smallint(4) unsigned NOT NULL DEFAULT '50', UNIQUE KEY `id` (`id`), KEY `game` (`game`), KEY `pilot` (`pilot`), KEY `sector` (`sector`), KEY `hull` (`hull`), KEY `game_2` (`game`,`pilot`,`sector`,`hull`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; The explain: id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE p ref id,game_id_lastmove game_id_lastmove 1 const 7 Using where; Using filesort 1 SIMPLE s ref game,pilot,sector... game_2 6 const,fightclub_alpha.p.id,const 1 Using where; Using index edit: I cut some of the unnecessary pieces out of my queries/table structure. Anybody have any ideas?

    Read the article

  • conceptually different entities with a few similar properties should be stored in one table or more?

    - by Haghpanah
    Assume A and B are conceptually different entities that have a few similar properties and of course their own specific properties. In database design, should I put those two entities in one big aggregated table or two respectively designed tables. For instance, I have two types of payment; Online-payment and Manual-payment with following definition, TABLE [OnlinePayments] ( [ID] [uniqueidentifier], [UserID] [uniqueidentifier], [TrackingCode] [nvarchar](32), [ReferingCode] [nvarchar](32), [BankingAccID] [uniqueidentifier], [Status] [int], [Amount] [money], [Comments] [nvarchar](768), [CreatedAt] [datetime], [ShopingCartID] [uniqueidentifier], ) And TABLE [ManualPayments] ( [ID] [uniqueidentifier], [UserID] [uniqueidentifier], [BankingAccID] [uniqueidentifier], [BankingOrgID] [uniqueidentifier], [BranchName] [nvarchar](64), [BranchCode] [nvarchar](16), [Amount] [money], [SlipNumber] [nvarchar](64), [SlipImage] [image], [PaidAt] [datetime], [Comments] [nvarchar](768), [CreatedAt] [datetime], [IsApproved] [bit], [ApprovedByID] [uniqueidentifier], ) One of my friends told me that creating two distinct tables for such similar entities is not a well design method and they should be put in one single table for the sake of performance and ease of data manipulations. I’m now wondering what to do? What is the best practice in such a case?

    Read the article

  • RTSP client in android

    - by Vinay
    I am writing a RTSP client in Android. I am able to receive the Responses for all the requests i.e., DESCRIBE it sends back the 200 OK SETUP with transport: RTP/AVP:unicast:client_port=4568:4569 got the 200 OK Message back Sent PLAY, and got the OK Message After that how to get the audio and video frames? I have searched on blogs, but all say to listen at client_port but I am not receiving any packets. Please let me know am I doing correctly.

    Read the article

  • exiting script while running source scriptname over SSH

    - by CCG121
    I have a script with a number of options in it one of the option sets is supposed to change the directory and then exit the script however running over ssh with the source to get it to change in the parent it exits SSH is there another way to do this so that it does not exit? my script is in the /usr/sbin directory.

    Read the article

  • Of C# Iterators and Performance

    - by James Michael Hare
    Some of you reading this will be wondering, "what is an iterator" and think I'm locked in the world of C++.  Nope, I'm talking C# iterators.  No, not enumerators, iterators.   So, for those of you who do not know what iterators are in C#, I will explain it in summary, and for those of you who know what iterators are but are curious of the performance impacts, I will explore that as well.   Iterators have been around for a bit now, and there are still a bunch of people who don't know what they are or what they do.  I don't know how many times at work I've had a code review on my code and have someone ask me, "what's that yield word do?"   Basically, this post came to me as I was writing some extension methods to extend IEnumerable<T> -- I'll post some of the fun ones in a later post.  Since I was filtering the resulting list down, I was using the standard C# iterator concept; but that got me wondering: what are the performance implications of using an iterator versus returning a new enumeration?   So, to begin, let's look at a couple of methods.  This is a new (albeit contrived) method called Every(...).  The goal of this method is to access and enumeration and return every nth item in the enumeration (including the first).  So Every(2) would return items 0, 2, 4, 6, etc.   Now, if you wanted to write this in the traditional way, you may come up with something like this:       public static IEnumerable<T> Every<T>(this IEnumerable<T> list, int interval)     {         List<T> newList = new List<T>();         int count = 0;           foreach (var i in list)         {             if ((count++ % interval) == 0)             {                 newList.Add(i);             }         }           return newList;     }     So basically this method takes any IEnumerable<T> and returns a new IEnumerable<T> that contains every nth item.  Pretty straight forward.   The problem?  Well, Every<T>(...) will construct a list containing every nth item whether or not you care.  What happens if you were searching this result for a certain item and find that item after five tries?  You would have generated the rest of the list for nothing.   Enter iterators.  This C# construct uses the yield keyword to effectively defer evaluation of the next item until it is asked for.  This can be very handy if the evaluation itself is expensive or if there's a fair chance you'll never want to fully evaluate a list.   We see this all the time in Linq, where many expressions are chained together to do complex processing on a list.  This would be very expensive if each of these expressions evaluated their entire possible result set on call.    Let's look at the same example function, this time using an iterator:       public static IEnumerable<T> Every<T>(this IEnumerable<T> list, int interval)     {         int count = 0;         foreach (var i in list)         {             if ((count++ % interval) == 0)             {                 yield return i;             }         }     }   Notice it does not create a new return value explicitly, the only evidence of a return is the "yield return" statement.  What this means is that when an item is requested from the enumeration, it will enter this method and evaluate until it either hits a yield return (in which case that item is returned) or until it exits the method or hits a yield break (in which case the iteration ends.   Behind the scenes, this is all done with a class that the CLR creates behind the scenes that keeps track of the state of the iteration, so that every time the next item is asked for, it finds that item and then updates the current position so it knows where to start at next time.   It doesn't seem like a big deal, does it?  But keep in mind the key point here: it only returns items as they are requested. Thus if there's a good chance you will only process a portion of the return list and/or if the evaluation of each item is expensive, an iterator may be of benefit.   This is especially true if you intend your methods to be chainable similar to the way Linq methods can be chained.    For example, perhaps you have a List<int> and you want to take every tenth one until you find one greater than 10.  We could write that as:       List<int> someList = new List<int>();         // fill list here         someList.Every(10).TakeWhile(i => i <= 10);     Now is the difference more apparent?  If we use the first form of Every that makes a copy of the list.  It's going to copy the entire list whether we will need those items or not, that can be costly!    With the iterator version, however, it will only take items from the list until it finds one that is > 10, at which point no further items in the list are evaluated.   So, sounds neat eh?  But what's the cost is what you're probably wondering.  So I ran some tests using the two forms of Every above on lists varying from 5 to 500,000 integers and tried various things.    Now, iteration isn't free.  If you are more likely than not to iterate the entire collection every time, iterator has some very slight overhead:   Copy vs Iterator on 100% of Collection (10,000 iterations) Collection Size Num Iterated Type Total ms 5 5 Copy 5 5 5 Iterator 5 50 50 Copy 28 50 50 Iterator 27 500 500 Copy 227 500 500 Iterator 247 5000 5000 Copy 2266 5000 5000 Iterator 2444 50,000 50,000 Copy 24,443 50,000 50,000 Iterator 24,719 500,000 500,000 Copy 250,024 500,000 500,000 Iterator 251,521   Notice that when iterating over the entire produced list, the times for the iterator are a little better for smaller lists, then getting just a slight bit worse for larger lists.  In reality, given the number of items and iterations, the result is near negligible, but just to show that iterators come at a price.  However, it should also be noted that the form of Every that returns a copy will have a left-over collection to garbage collect.   However, if we only partially evaluate less and less through the list, the savings start to show and make it well worth the overhead.  Let's look at what happens if you stop looking after 80% of the list:   Copy vs Iterator on 80% of Collection (10,000 iterations) Collection Size Num Iterated Type Total ms 5 4 Copy 5 5 4 Iterator 5 50 40 Copy 27 50 40 Iterator 23 500 400 Copy 215 500 400 Iterator 200 5000 4000 Copy 2099 5000 4000 Iterator 1962 50,000 40,000 Copy 22,385 50,000 40,000 Iterator 19,599 500,000 400,000 Copy 236,427 500,000 400,000 Iterator 196,010       Notice that the iterator form is now operating quite a bit faster.  But the savings really add up if you stop on average at 50% (which most searches would typically do):     Copy vs Iterator on 50% of Collection (10,000 iterations) Collection Size Num Iterated Type Total ms 5 2 Copy 5 5 2 Iterator 4 50 25 Copy 25 50 25 Iterator 16 500 250 Copy 188 500 250 Iterator 126 5000 2500 Copy 1854 5000 2500 Iterator 1226 50,000 25,000 Copy 19,839 50,000 25,000 Iterator 12,233 500,000 250,000 Copy 208,667 500,000 250,000 Iterator 122,336   Now we see that if we only expect to go on average 50% into the results, we tend to shave off around 40% of the time.  And this is only for one level deep.  If we are using this in a chain of query expressions it only adds to the savings.   So my recommendation?  If you have a resonable expectation that someone may only want to partially consume your enumerable result, I would always tend to favor an iterator.  The cost if they iterate the whole thing does not add much at all -- and if they consume only partially, you reap some really good performance gains.   Next time I'll discuss some of my favorite extensions I've created to make development life a little easier and maintainability a little better.

    Read the article

  • File Transfer using RDP

    - by DesigningCode
    I often use RDP to log into servers.   A couple of issues I have had is that its a pain to get files onto the server from my PC at times, and, if there is something missing from the servers windows install, I can’t simply pop the DVD into remote server in some unknown location on the internet somewhere. The other day I was curious if RDP actually had anything…since it did support shared clipboards, so I went for a look through the options and low and behold, *hidden* away….. Select Options… Go to the “Local Resources” Tab, then where it has “Local devices and resources” it sneakily has a “More…” button. Which then displays a drive selection box.  Select the drive you want …. Then on your server you will get….. Nice.  That is useful.

    Read the article

  • How to email photo from Ubuntu F-Spot application via Gmail?

    - by Norman Ramsey
    My father runs Ubuntu and wants to be able to use the Gnome photo manager, F-Spot, to email photos. However, he must use Gmail as his client because (a) it's the only client he knows how to use and (b) his ISP refuses to reveal his SMTP password. I've got as far as setting up Firefox to use GMail to handle mailto: links and I've also configured firefox as the system default mailer using gnome-default-applications-properties. F-Spot presents a mailto: URL with an attach=file:///tmp/mumble.jpg header. So here's the problem: the attachment never shows up. I can't tell if Firefox is dropping the attachment header, if GMail doesn't support the header, or what. I've learned that: There's no official header in the mailto: URL RFC that explains how to add an attachment. I can't find documentation on how Firefox handles mailto: URLs that would explain to me how to communicate to Firefox that I want an attachment. I can't find any documentation for GMail's URL API that would enable me to tell GMail directly to start composing a message with a given file as an attachement. I'm perfectly capable of writing a shell script to interpolate around F-Spot to massage the URL that F-Spot presents into something that will coax Firefox into doing the right thing. But I can't figure out how to persuade Firefox to start composing a GMail message with a local file attached. Any help would be greatly appreciated.

    Read the article

  • Protecting offline IRM rights and the error "Unable to Connect to Offline database"

    - by Simon Thorpe
    One of the most common problems I get asked about Oracle IRM is in relation to the error message "Unable to Connect to Offline database". This error message is a result of how Oracle IRM is protecting the cached rights on the local machine and if that cache has become invalid in anyway, this error is thrown. Offline rights and security First we need to understand how Oracle IRM handles offline use. The way it is implemented is one of the main reasons why Oracle IRM is the leading document security solution and demonstrates our methodology to ensure that solutions address both security and usability and puts the balance of these two in your control. Each classification has a set of predefined roles that the manager of the classification can assign to users. Each role has an offline period which determines the amount of time a user can access content without having to communicate with the IRM server. By default for the context model, which is the classification system that ships out of the box with Oracle IRM, the offline period for each role is 3 days. This is easily changed however and can be as low as under an hour to as long as years. It is also possible to switch off the ability to access content offline which can be useful when content is very sensitive and requires a tight leash. So when a user is online, transparently in the background, the Oracle IRM Desktop communicates with the server and updates the users rights and offline periods. This transparent synchronization period is determined by the server and communicated to all IRM Desktops and allows for users rights to be kept up to date without their intervention. This allows us to support some very important scenarios which are key to a successful IRM solution. A user doesn't have to make any decision when going offline, they simply unplug their laptop and they already have their offline periods synchronized to the maximum values. Any solution that requires a user to make a decision at the point of going offline isn't going to work because people forget to do this and will therefore be unable to legitimately access their content offline. If your rights change to REMOVE your access to content, this also happens in the background. This is very useful when someone has an offline duration of a week and they happen to make a connection to the internet 3 days into that offline period, the Oracle IRM Desktop detects this online state and automatically updates all rights for the user. This means the business risk is reduced when setting long offline periods, because of the daily transparent sync, you can reflect changes as soon as the user is online. Of course, if they choose not to come online at all during that week offline period, you cannot effect change, but you take that risk in giving the 7 day offline period in the first place. If you are added to a NEW classification during the day, this will automatically be synchronized without the user even having to open a piece of content secured against that classification. This is very important, consider the scenario where a senior executive downloads all their email but doesn't open any of it. Disconnects the laptop and then gets on a plane. During the flight they attempt to open a document attached to a downloaded email which has been secured against an IRM classification the user was not even aware they had access to. Because their new role in this classification was automatically synchronized their experience is a good one and the document opens. More information on how the Oracle IRM classification model works can be found in this article by Martin Abrahams. So what about problems accessing the offline rights database? So onto the core issue... when these rights are cached to your machine they are stored in an encrypted database. The encryption of this offline database is keyed to the instance of the installation of the IRM Desktop and the Windows user account. Why? Well what you do not want to happen is for someone to get their rights for content and then copy these files across hundreds of other machines, therefore getting access to sensitive content across many environments. The IRM server has a setting which controls how many times you can cache these rights on unique machines. This is because people typically access IRM content on more than one computer. Their work desktop, a laptop and often a home computer. So Oracle IRM allows for the usability of caching rights on more than one computer whilst retaining strong security over this cache. So what happens if these files are corrupted in someway? That's when you will see the error, Unable to Connect to Offline database. The most common instance of seeing this is when you are using virtual machines and copy them from one computer to the next. The virtual machine software, VMWare Workstation for example, makes changes to the unique information of that virtual machine and as such invalidates the offline database. How do you solve the problem? Resolution is however simple. You just delete all of the offline database files on the machine and they will be recreated with working encryption when the Oracle IRM Desktop next starts. However this does mean that the IRM server will think you have your rights cached to more than one computer and you will need to rerequest your rights, even though you are only going to be accessing them on one. Because it still thinks the old cache is valid. So be aware, it is good practice to increase the server limit from the default of 1 to say 3 or 4. This is done using the Enterprise Manager instance of IRM. So to delete these offline files I have a simple .bat file you can use; Download DeleteOfflineDBs.bat Note that this uses pskillto stop the irmBackground.exe from running. This is part of the IRM Desktop and holds open a lock to the offline database. Either kill this from task manager or use pskillas part of the script.

    Read the article

  • When saving a model with has_one or has_many associations, which side of the association is saved fi

    - by SeeBees
    I have three simplified models: class Team < ActiveRecord::Base has_many :players has_one :coach end class Player < ActiveRecord::Base belongs_to :team validates_presence_of :team_id end class Coach < ActiveRecord::Base belongs_to :team validates_presence_of :team_id end I use the following code to test these models: t = Team.new team.coach = Coach.new team.save! team.save! returns true. But in another test: t = Team.new team.players << Player.new team.save! team.save! gives the following error: > ActiveRecord::RecordInvalid: > Validation failed: Players is invalid > from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/validations.rb:1090:in > `save_without_dirty!' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/dirty.rb:87:in `save_without_transactions!' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:200:in > `save!' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in > `transaction' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:182:in > `transaction' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:200:in > `save!' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:208:in > `rollback_active_record_state!' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:200:in > `save!' from (irb):14 I figured out that when team.save! is called, it first calls player.save!. player needs to validate the presence of the id of the associated team. But at the time player.save! is called, team hasn't been saved yet, and therefore, team_id doesn't yet exist for player. This fails the player's validation, so the error occurs. But on the other hand, team is saved before coach.save!, otherwise the first example will get the same error as the second one. So I've concluded that when a has_many bs, a.save! will save bs prior to a. When a has_one b, a.save! will save a prior to b. If I am right, why is this the case? It doesn't seem logical to me. Why do has_one and has_many association have different order in saving? Any ideas? And is there any way I can change the order? Say I want to have the same saving order for both has_one and has_many. Thanks.

    Read the article

  • What is the worst code you've ever written?

    - by Even Mien
    Step into the confessional. Now's your time to come clean. What's the worst code you personally have ever written? Why was it so bad? What did you learn from it? Don't tell us about code you inherited or from some co-worker. This is about your personal growth as a programmer and as a person.

    Read the article

  • How to change font color inside an existing script

    - by user320946
    Hi everyone, I get a script from a website to put it into my website, but the font color is not what I want. the script is: < script language="javascript" src="http://www.parstools.net/calendar/?type=2"< /script and now I want to change the font color of it, what should I do? I would really appreciate your help, thanks.

    Read the article

  • asp.net dynamic sitemap with querystring? Session variable seems like overkill.

    - by Mike
    Hi, I'm using ASP.NET WebForms. I'm using the standard sitemap provider. Home User Account Entry Going to the home page should have a user selection screen. Clicking on a user should list out the user's accounts with options to edit, delete, add accounts. Selecting an account should list out all the user's account's entries with options to edit delete and add entries. How do you normally pass this information between pages? I could use the query string, but then, the sitemap doesn't work. The sitemap only has the exact page without the query string and therefore loses the information. /User/Account/List.aspx?User=123 /User/Account/Entry/List.aspx?User=123&Account=322 I could use a session variable, but this seems overkill. Thoughts and suggestions very appreciated. Thanks!

    Read the article

  • Flex - How do I use a variable to define the name of an instantiated object

    - by flexfanatic
    Essentially this is what I want to accomplish, however it doesn't work like this. Is there any solution: - The problem is I can't dynamically name a new object... ??? pulling my hair out. import views.printingView; public function initComponent(o:Array):void{ SomeObject::Array = o; for(i=0; i <=SomeObject.length-1; i++){ 'invoice'+{SomeObject[i].namedID}:printingView = new printingView(); someDisplayContainer.addChild('invoice'+{SomeObject[i].namedID}); 'invoice'+{SomeObject.namedID}.publicInitFunction(SomeObject[i]); } }

    Read the article

  • LoginView inside FormView control is not databinding on PostBack

    - by subkamran
    I have a fairly simple form: <asp:FormView> <EditItemTemplate> <asp:LoginView> <RoleGroups> <asp:RoleGroup roles="Blah"> <ContentTemplate> <!-- Databound Controls using Bind/Eval --> </ContentTemplate> </asp:RoleGroup> </RoleGroups> </asp:LoginView> <!-- Databound Controls --> </EditItemTemplate> </asp:FormView> <asp:LinqDataSource OnUpdating="MyDataSource_Updating" /> I handle my LinqDataSource OnUpdating event and do some work handling some M:N fields. That all works. However, once the update is finished (and I call e.Cancel = true), the LoginView control does not databind its children... so they are all blank. The FormView's viewstate is still fine, as all the rest of the controls outside of the LoginView appear fine. I even handle the FormView_DataBound event and a Trace shows that the FormView is being databound on postback. Why then is the LoginView not keeping its ViewState/being databound? Here's a sample code snippet showing the flow: protected void MyDataSource_Updating(object s, LinqDataSourceUpdateEventArgs e) { try { Controller.DoSomething(newData); // attempts to databind again here fail // frmView.DataBind(); // MyDataSource.DataBind(); // LoginView.DataBind(); } catch { // blah } finally { e.Cancel = true; } }

    Read the article

  • My iPhone app has been downloaded by people all over the world, but has no use to anyone outside of

    - by Rob Lourens
    I wrote a basic free app for the bus schedule in my American university's town which was accepted into the app store on Saturday. Since then the app has been downloaded (assuming I'm reading the iTunes Connect reports right) 18 times in Canada, 6 times in Germany, and many times from other places all over the world. I can't figure out why all these people are downloading it... are there services automatically downloading free apps for some purpose that I can't even imagine? Should I put a price on it ASAP?

    Read the article

  • Key Window for background application

    - by jpoz
    Dear Cocoa Developers, I'm creating a backgrounded cocoa application. The only thing that it's missing is the ability to take text inputs! I'm making the application backgrounded by setting "Application is background only" in the Info.plist But no matter what I do I can't make any window the keyWindow. makeKeyWindow makeKeyAndOrderFront Both don't work... I know apps can do this, anyone have any idea how you can get background application to have a key window? Thanks, JPoz

    Read the article

  • USB port causing device problems after new motherboard upgrade

    - by enbuyukfener
    I'm looking into a PC with an issue with one of the front USB ports (perhaps both). It was working before a motherboard upgrade but since then, a USB drive was inserted, overheated and does not appear to be working. Then a phone (with USB charging) was plugged in, and the phone OS suspended. Removing and re-inserting the battery led to the phone (and hence battery) working, however the battery no longer charges (including with a wall charger). It seems too much to be a coincidence and am wondering what the issue may be? Ideas so far are short circuiting, or over-current to the USB ports. Note: Did not occur to me, so details are not 100% accurate or complete. Feel free to ask for missing info that I may have forgotten though.

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >