instruction
stringlengths
0
30k
The ps is a really poor way of doing that and probably open to race conditions. The traditional Unix/Linux way would be to write the PID to a file (typically in /var/run) and check to see if that file exists on startup. e.g. the pidfile being located at /var/run/myscript.pid then you'd check to see if that exists before running the program. There are a few tricks to avoid race conditions involving using O_EXCL (exclusing locking) to open the file and symbolic links. However unlikely, you should try to code to avoid race conditions by using atomic operations on the filesystem. To save re-inventing the wheel, you might want to look at http://rubyforge.org/projects/pidify/
Hm, [Rockford Lhotka][1] sad, that LINQ to SQL is wonderful technology for fetching data from database. He suggests that afterwards they'll must to be bind to "reach domain objects" (aka. CSLA objetcs). Seriously speaking, LINQ to SQL had it's support for n-tier architecture see **DataContext.Update** method. [1]: http://www.lhotka.net/
[CreateFile][1] has support for direct disk access. Read the notes under "Physical Disks and Volumes". You should be able to P/Invoke the call. Note that Vista and Server 2008 have [severely restricted][2] this. [1]: http://msdn.microsoft.com/en-us/library/aa363858.aspx [2]: http://support.microsoft.com/kb/942448
100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100. One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly permuted!). Once inside room B, each prisoner gets to open 50 boxes (he chooses which one he opens). If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed. Before entering room B, the prisoners can agree on a strategy (algorithm). There is no way to communicate between rooms (and no message can be left in room B!). Find a strategy (algorithm) that maximizes the probability that all prisoners survive. What probability does your algorithm achieve? Edits: - Note that I did ask if it was OK to post puzzles. I'd like to get some feedback from people downvoting if possible! - @Ross: doing things randomly (what you call 'no strategy') indeed gives a probability of 1/2 for each prisoner, but then the probability of all of them surviving is 1/2^100 (which is quite low). One can do much better! - The prisoners are not allowed to reorder the boxes! - Also, be assured that I do have an interesting solution. I'll post it in a week or so :) - @Sam Hasler: all prisoners are killed the first time a prisoner fails to find his number. *And* no communication is possible. - <b>Hint</b>: one can save more than 30 prisoners *on average*, which is much more that (50/100) * (50/99) * [...] * 1 - @Rob Cooper: I get your point (no point in yelling!), however it reflects your opinion (and that of some others I'm sure), and I don't yet see a consensus on that matter. I do respect your opinion (didn't vote on your answer, or on any other by the way), but I'd really like to have this clarified (in the FAQ for example...). - @Jorge: I still didn't get into the details of your solution, but I believe that you can indeed do it this way. However, this is basically using time to communicate. The solution I have in mind doesn't involve any kind of communication (so people can't rely on time, for example). - @chakrit: it would help if you provided the probability that your method achieves. In case it's too complicated to work out, running simulations (Monte-Carlo like) would give you an estimate! - @jbettis: **this is indeed the solution** I had in mind (and believe me or not, but I found it myself when presented with the problem). As for the wording, I'm sorry but I'm not a native English speaker. For the specific wordings you refer to: for me, saving more that 30 on average is equivalent to your wording; also the problem is the same if you kill all prisoners as soon as one fails...
Early is good, definitely before you try to parse it. Anything you're going to output later, or especially pass to other components (i.e., shell, SQL, etc) must be sanitized. But don't go overboard - for instance, passwords are hashed before you store them (right?). Hash functions can accept arbitrary binary data. And you'll never print out a password (right?). So don't parse passwords - and don't sanitize them. Also, make sure that you're doing the sanitizing from a trusted process - JavaScript/anything client-side is worse than useless security/integrity-wise. (It might provide a better user experience to fail early, though - just do it both places.)
on *nix, there's a tool called [valgrind][1] that I use for dealing with memory issues, like memory leaks and memory corruption. [1]: http://valgrind.org/
We currently have one branch for ongoing maintenance, one branch for "new initiatives" which just means "stuff that will come out sometime in the future; we're not sure when." We have also occasionally had two maintenance branches going on: one to provide fixes for what is currently in production and one that is still in QA. The main advantage we've seen is the ability to react to user requests and emergencies more rapidly. We can do the fix on the branch that is in production and release it without releasing anything extra that may have already been checked in. The main disadvantage is that we end up doing a lot of merging between branches, which increases the chance that something will get missed or merged incorrectly. So far, that hasn't been a problem, but it is definitely something to keep in mind. Before we instituted this policy, we generally did all development in the trunk and only branched when we released code. We then did fixes against that branch as needed. It was simpler, but not as flexible.
The C-runtime libraries are often the biggest culprit. Making sure all your projects have the same settings wrt single vs multi-threading and static vs dll. The MSDN documentation is good for pointing out which lib a particular Win32 API call requires if it comes up as missing. Other than that it usually comes down to turning on the verbose flag and wading through the output looking for clues.
Same concept. **Aonther take:** 1. Write down a list of the first 100 binary numbers which has fifty 1s and fifty 0s. 2. Sort them from lowest to highest. 3. Prisoner #1 gets the first number, prisoner #2 gets the second, prisoner #3 gets the third and so on... 4. Each prisoner remembers his/her binary number. 5. When any prisoner is moved to room B, he/she then match the binary digits of the number he remembered with each of the box, the highest bit is matched with the leftmost box, the next highest bit is matched with the second leftmost box ... the lowest bit is matched with the rightmost box. 6. He/she opens whatever boxes matched with 1 and leave closed boxes matched with 0.
Same concept. **Aonther take:** 1. Write down a list of the first 100 binary numbers which has fifty 1s and fifty 0s. 2. Sort them from lowest to highest. 3. Prisoner #1 gets the first number, prisoner #2 gets the second, prisoner #3 gets the third and so on... 4. Each prisoner remembers his/her binary number. 5. When any prisoner is moved to room B, he/she then match the binary digits of the number he remembered with each of the box, the highest bit is matched with the leftmost box, the next highest bit is matched with the second leftmost box ... the lowest bit is matched with the rightmost box. 6. He/she opens whatever boxes matched with 1 and leave closed boxes matched with 0. This would minimizes the probability because early prisoners will get digits that are different from the later prisoners and prisoners which has number close together would get digits close together. This doesn't guarantee survivability but if the early prisoners do survive, chances are the later prisoners would have a higher probability of surviving as well. I haven't thought out the exact figures and rationale though, but this is one quick solution I can think of at the moment.
Bear in mind that the EntLib documentation specifically steers you towards the ASP.NET cache for ASP.NET applications. That's probably the strongest recommendation towards using it here. Plus the EntLib cache doesn't have dependencies, which for me is a big reason not to use it. I don't think there's a technical limitation as such on shipping System.Web as part of your app, though it's slightly odd that they've put that notice in on the .NET 3.5 page. Hanselman actually says he started out being creeped out by this notion, but became convinced. Also if you read the comments, he says that the block has too many moving parts and the ASP.NET Cache is much more lightweght. I think this is exactly the kind of problem that [Velocity][1] is going to solve, but that's only a preview for now :-( I'd say use Web.Caching and see how you get on. If you put some kind of abstraction layer over the top of it, you've always got the option to swap it out for the EntLib block later on if you find problems. [1]: http://blogs.msdn.com/velocity/
@TK: a hashing algo can only be 'guessed', not reverse engineered. One can only reconstruct the input to a hash value by completely guessing the input (apart from collisions, that is) This can be done by a rainbow crack for example (see [an implementation of a rainbow cracker here][1]) I would say that a 3rd party encryption tool is not safer than the .NET framework encryption algorithms, these libraries just help you doing your job faster [1]: http://www.antsight.com/zsl/rainbowcrack/
FlashWindowEx FLASHW_STOP still keeps taskbar colored
|c#|winapi|pinvoke|
<p>I am developing an application that controls an Machine.<br/> When I receive an error from the Machine the users should be able to directly notice it, one way that is done is Flashing the tray on the taskbar. When the machine clears the error the tray should stop flashing.</p> <p>There's one little annoyance using the FlashWindowEx function, when I clear the flashing of the window, it stays (in my case winXP) orange (not flashing).<br/> <img src="http://files.stormenet.be/flashwinex_stop.gif" alt="Sample of status"/></p> <pre><code> [Flags] public enum FlashMode { /// <summary> /// Stop flashing. The system restores the window to its original state. /// </summary> FLASHW_STOP = 0, /// <summary> /// Flash the window caption. /// </summary> FLASHW_CAPTION = 1, /// <summary> /// Flash the taskbar button. /// </summary> FLASHW_TRAY = 2, /// <summary> /// Flash both the window caption and taskbar button. /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags. /// </summary> FLASHW_ALL = 3, /// <summary> /// Flash continuously, until the FLASHW_STOP flag is set. /// </summary> FLASHW_TIMER = 4, /// <summary> /// Flash continuously until the window comes to the foreground. /// </summary> FLASHW_TIMERNOFG = 12 } public static bool FlashWindowEx(IntPtr hWnd, FlashMode fm) { FLASHWINFO fInfo = new FLASHWINFO(); fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); fInfo.hwnd = hWnd; fInfo.dwFlags = (UInt32)fm; fInfo.uCount = UInt32.MaxValue; fInfo.dwTimeout = 0; return FlashWindowEx(ref fInfo); } [StructLayout(LayoutKind.Sequential)] public struct FLASHWINFO { public UInt32 cbSize; public IntPtr hwnd; public UInt32 dwFlags; public UInt32 uCount; public UInt32 dwTimeout; } </code></pre> <p>In my case I use FLASHW_TRAY to start flashing and FLASHW_STOP to stop the flashing.</p> <p>Am I doing something wrong or is this a known bug of WinXP and is there a fix for it?</p>
<P>Ok, in terms of reading material, this is the pick of the books out there: <A href="http://www.amazon.com/exec/obidos/ASIN/0672328917">Windows Presentation Foundation Unleashed</A>.</P> <P>For blogs, there are a lot of blogs and&nbsp;articles on <A href="http://windowsclient.net/">WindowsClient.net</A>, and there's an excellent blog all about data binding in WPF by <A href="http://www.beacosta.com/blog/">Beatriz Costa</A>. Also take a look at <A href="http://learnwpf.com/">LearnWPF.com</A> and <A href="http://www.drwpf.com/blog/">Ask Dr. WPF</A>.</P>
Input filtering is usually done on the language level rather than database layers. php and .NET both have their respective libraries for escaping sql statements. Check your language, see waht's available. If your data are trustable, then you can just do a string replace to add another ' infront of the ' to escape it. Usually that is enough if there isn't any risks that the input is malicious.
Here's a little ruby script that does *exactly* what your question asks (pull an attribute called 'name' out of elements called 'myel'. Should be easy to generalize #!/usr/bin/ruby -w require 'rexml/document' xml = REXML::Document.new(File.open(ARGV[0].to_s)) xml.elements.each("//myel") { |el| puts "#{el.attributes['name']}," if el.attributes['name'] }
Here's a little ruby script that does *exactly* what your question asks (pull an attribute called 'name' out of elements called 'myel'). Should be easy to generalize #!/usr/bin/ruby -w require 'rexml/document' xml = REXML::Document.new(File.open(ARGV[0].to_s)) xml.elements.each("//myel") { |el| puts "#{el.attributes['name']}," if el.attributes['name'] }
I suppose a good question is what language are you using?<br /> In PHP you would do: SELECT * FROM PEOPLE WHERE SURNAME='mysql_escape_string(O'Keefe)'<br /> But since you didn't specify the language I will suggest that you look into a escape string function mysql or otherwise in your language.
If you right-click in the source of a file in Eclipse, it has a Javadoc generation option under the source menu.
@garethm(29662): > I believe that the function you're looking for is called tmpnam. You should definitely *not* use `tmpnam`. It suffers from the race condition problem I mentioned in my answer: Between determining the name and opening it, another program may create the file or a symlink to it, which is a huge security hole. The `tmpnam` man page specifically says not to use it, but to use `mkstemp` or `tmpfile` instead.
@[garethm](#29662): > I believe that the function you're looking for is called tmpnam. You should definitely *not* use `tmpnam`. It suffers from the race condition problem I mentioned in my answer: Between determining the name and opening it, another program may create the file or a symlink to it, which is a huge security hole. The `tmpnam` man page specifically says not to use it, but to use `mkstemp` or `tmpfile` instead.
I seem to remember that I have sometimes found it useful to use RunAs when you run msvcmon (or whatever it's called this week - the remote debugging stub anyway), to force it to start as the user which you have set up to be the same on both machines. I would guess that on the machine you're running VS on, you will also need to log in as the local user rather than a domain user (or start VS with RunAs). I have never understood why this needed to be so hard, given that unmanaged debugging is so much easier, and must expose every security hole that managed debugging could.
Same concept. **Aonther take:** > 1. Write down a list of the first 100 binary numbers which has fifty 1s and fifty 0s. 2. Sort them from lowest to highest. 3. Prisoner #1 gets the first number, prisoner #2 gets the second, prisoner #3 gets the third and so on... 4. Each prisoner remembers his/her binary number. 5. When any prisoner is moved to room B, he/she then match the binary digits of the number he remembered with each of the box, the highest bit is matched with the leftmost box, the next highest bit is matched with the second leftmost box ... the lowest bit is matched with the rightmost box. 6. He/she opens whatever boxes matched with 1 and leave closed boxes matched with 0. This would minimizes the probability because early prisoners will get digits that are different from the later prisoners and prisoners which has number close together would get digits close together. This doesn't guarantee survivability but if the early prisoners do survive, chances are the later prisoners would have a higher probability of surviving as well. I haven't thought out the exact figures and rationale though, but this is one quick solution I can think of at the moment.
The `|` is a bitwise operator in PHP. It does not mean `$a OR $b`, exactly. You'll want to use the double-pipe. And yes, as mentioned, PHP does short-circuit evaluation. In similar fashion, if the first condition of an `&&` clause evaluates to false, PHP does not evaluate the rest of the clause, either.
While Scrum other agile methodologies like it embody a lot of good practices, sometimes giving it a name and making it (as many bloggers have commented on) a "religion" that must be adopted in the workplace is rather offputting to a lot of people, including myself. It depends on what your options and commitments are, but I know I'd be a lot more keen on accepting ideas because they are good ideas, not because they are a bandwagon. Try implementing/drawing her in to the practices one at a time, by showing her how they can improve her life and workflow as well. Programmers love cool things that help them get stuff done. They hate being preached at or being asked to board what they see as a bandwagon. Present it as the former rather than the latter. (It goes without saying, make sure it actually IS the former) **Edit: another question** I've never actually worked for a place that used a specific agile methodology, though I'm pretty happy where I'm at now in that we incorporate a lot of agile practices without the hype and the dogma (best of both worlds, IMHO). But I was just reading about Scrum and, is a system like that even beneficial for a 2 person team? Scrum does add a certain amount of overhead to a project, it seems, and that might outweigh the benefits when you have a very small team where communication and planning is already easy.
Some notes that I also found useful: - Keep your default values on the right side. function whatever($var1, $var2, $var3="constant", $var4="another") - The default value of the argument must be a constant expression. It can't be a variable or a function call.
I think the key would be to help her understand why you are doing Scrum in the first place. I guess you have your reasons, so why not tell her? You are likely to get resistance towards any change if the people involved don't understand why there is change or what they will benefit from it. If you can explain your reasons for using Scrum, and the following benefits, to her in a way that relates to her everyday work, I think she is more likely to adapt a more positive attitude towards it. If she sees no value in the Scrum process, or doesn't understand how it relates to her, she probably won't care about it. I think one of the most important concepts for someone to understand regarding Scrum is the fact that you are working as a group and commit to your project as a group, not as individuals. For many people, this is the hardest thing to grasp, since they are so used to living in "their own World".
We've invested in a few licenses of [Simply File][1] for our employees. Works a treat at managing your inbox - it learns (don't ask me how, but it is very good) how to file things for you and does it automatically. I was sceptical about it at first, until I tried it then I was a convert. [1]: http://www.techhit.com/SimplyFile/
Sure there is. This is all you need to do: - Go to <pre>File -> Settings -> Global Code Style -> General</pre> - Disable the checkbox next to 'Use same settings for all file types' - The 'XML' tab should become enabled. Click it and set the 'tab' (and probably 'indent') size to 2.
<pre> maxjobs=4 parallelize () { while [ $# -gt 0 ] ; do jobcnt=(`jobs -p`) if [ ${#jobcnt[@]} -lt $maxjobs ] ; then do-something $1 & shift fi done wait } parallelize arg1 arg2 "5 args to third job" arg4 ... </pre>
Compiling the boost libraries for yourself is actually quite simple, if not that well documented. The documentation is in the jamroot file. Run `bjam --help` in the boost root directory for a detailed list of options. As an example I used the following command line to build my current set up with boost 1.36.0: bjam --build-type=complete --toolset=msvc --build-dir=c:\boost\build install It ran for about a half hour on my machine and put the resulting files into c:\boost
celsius = (5.0/9.0) * (fahr-32.0); In this expression, `5.0`, `9.0`, and `32.0` are `double`s. That's the default type for a floating-point constant - if you wanted them to be `float`s, then you would use the `F` suffix: celsius = (5.0F/9.0F) * (fahr-32.0F); Note that if `fahr` was a `double`, then the result of this last expression would *still* be a `double`: as Vaibhav noted, types are promoted in such a way as to avoid potentially losing precision.
Mark's answer is the way to go, after all, that's why the /proc file system is there. For something a little more copy/pasteable: >>> import os.path >>> os.path.exists("/proc/0") False >>> os.path.exists("/proc/12") True
Inbox Management (in Outlook)
|email|outlook|gettingthingsdone|
I've gone back and forth between having an organized inbox and having an inbox with absolutely everything I've received in it. Would you recommend leaving everything in an inbox, or organize it? If you organize it, is there any method to your madness or possibly an Outlook (2003) plug-in to aid in this task? For what it's worth, I *feel* way more productive with everything in my inbox, grouped by date. I *feel* like a spend way more time doing inbox management any other way.
|email|outlook|gtd|
The limitation of MOSS crawling sites with different forms authentication should have been addressed in MOSS SP1. : <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ad59175c-ad6a-4027-8c2f-db25322f791b&displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=ad59175c-ad6a-4027-8c2f-db25322f791b&displaylang=en</a> Here's a link to a post which describes how to get the hotfix for pre-SP1 MOSS to enable the crawling of sites with forms authentication: <a href="http://blogs.microsoft.co.il/blogs/adir_ron/archive/2007/10/11/moss-search-for-sso-form-based-authentication-sites.aspx">http://blogs.microsoft.co.il/blogs/adir_ron/archive/2007/10/11/moss-search-for-sso-form-based-authentication-sites.aspx</a> Hope that helps!
I haven't used it myself, but the Microsoft Enterprise library has good encryption support that will possibly suit your needs: [http://msdn.microsoft.com/en-us/library/cc309503.aspx][1] [1]: http://msdn.microsoft.com/en-us/library/cc309503.aspx
XmlHttpRequest return values
|javascript|ajax|
For an application I'm building in my spare time I am looking for (arguably) the correct way to return data from an XmlHttpRequest. Options I see are: - Plain HTML. Let the request format the data and return it in a usable format. Advantage: easy to consume by the calling page. Disadvantage: Very rigid, stuck with a fixed layout. - XML. Let the request return XML, format it using XSLT on the calling page. Advantage: the requested service is easily consumed by other sources. Disadvantage: Is browser support for XSLT good enough? - JSON. Let the request return JSON, consume it using javascript, render HTML accordingly. Advantage: easier to 'OO-ify' the javascript making the request. Disadvantage: Probably not as easy to use as the previous two options. I've also thought about going for option one while abstracting the view logic in the called service in such a way that switching in and out different layouts would be trivial. Personally I think this option is the best out of three, for compatibility reasons. While typing this, I got another insight. Would it be a good idea to allow all three response formats, based on a parameter added to the request?
Using fck for some tine now, after "free text box", or something like that. Had problems only once, when I put fck inside asp.net ajax updatepanel, but found fix on forums. Problem was solved in next release. I would like to see some nice photo browser in it, because fck comes only with simple browser that displays filename, no thumbs. The other one, that has thumbs costs bunch of money. Didn't try it with asp.net mvc, don't know how will uploading work. It uses one ascx for wrapping js functionality.
The problem with catching all exceptions is that you may be catching ones that you don't expect, or indeed ones that you should **not** be catching. The fact is that an exception of any kind indicates that something has gone wrong, and you have to sort it out before continuing otherwise you may end up with data integrity problems and other bugs that are not so easy to track down. To give one example, in one project I implemented an exception type called CriticalException. This indicates an error condition that requires intervention by the developers and/or administrative staff otherwise customers get incorrectly billed, or other data integrity problems might result. It can also be used in other similar cases when merely logging the exception is not sufficient, and an e-mail alert needs to be sent out. Another developer who didn't properly understand the concept of exceptions then wrapped some code that could potentially throw this exception in a generic try...catch block which discarded all exceptions. Fortunately, I spotted it, but it could have resulted in serious problems, especially since the "very uncommon" corner case that it was supposed to catch turned out to be a lot more common than I anticipated. So in general, catching generic exceptions is bad unless you are 100% sure that you know **exactly** which kinds of exceptions will be thrown and under which circumstances. If in doubt, let them bubble up to the top level exception handler instead. A similar rule here is never throw exceptions of type System.Exception. You (or another developer) may want to catch your specific exception higher up the call stack while letting others go through. (There is one point to note, however. In .NET 2.0, if a thread encounters any uncaught exceptions it unloads your whole app domain. So you should wrap the main body of a thread in a generic try...catch block and pass any exceptions caught there to your global exception handling code.)
Post office box number. It's a piece of information that allows you to access something else. (And if you do arithmetic on post office box numbers, you may have a problem, because the letter goes in the wrong box. And if somebody moves to another state -- with no forwarding address -- then you have a dangling pointer. On the other hand -- if the post office forwards the mail, then you have a pointer to a pointer.)
To answer the first part of your post, check out AzMan (Authorization Manager), which, incidentally, is built into windows. It has the capability to specify operations which can be recombined into roles or assigned directly to users. http://msdn.microsoft.com/en-us/magazine/cc300469.aspx
To answer the first part of your post, check out AzMan (Authorization Manager), which, incidentally, is built into windows. It has the capability to specify operations which can be recombined into roles or assigned directly to users. http://msdn.microsoft.com/en-us/magazine/cc300469.aspx To answer the second part of your question, I wouldn't use an Abstract class. Instead just provide the functionality in the constructor and be done with it. It appeasr you want the specified behavior, and you don't want it to change. Why force descendents to provide the implementation.
> Problems - no way to get the number of strings automatically (that i know of). There is a bog-standard way of doing this, which lots of people (including MS) define macros like arraysize() for: #define arraysize(ar) (sizeof(ar) / sizeof(ar[0]))
This [article describes][1] another developers frustrations with lack of C++ code coverage tools. It looks like their search led them to a tool called [Bullseye Coverage][2]. I haven't used any C++ coverage tools myself, but if you find one that works for you, find a way to get coverage to launch via a make file. Then you can hook that make file into your continuous integration build process. [1]: http://www.kimbly.com/blog/000331.html [2]: http://www.bullseye.com/
This [article describes][1] another developers frustrations with lack of C++ code coverage tools. It looks like their search led them to a tool called [Bullseye Coverage][2]. Other tools like gcov are also mentioned in the article. I haven't used any C++ coverage tools myself, but if you find one that works for you, find a way to get coverage to launch via a make file. Then you can hook that make file into your continuous integration build process. [1]: http://www.kimbly.com/blog/000331.html [2]: http://www.bullseye.com/
###What tools are available? This [article describes][1] another developers frustrations with lack of C++ code coverage tools. It looks like their search led them to a tool called [Bullseye Coverage][2]. Other tools like gcov are also mentioned in the article. I haven't used any C++ coverage tools myself, but if you find one that works for you, find a way to get coverage to launch via a make file. Then you can hook that make file into your continuous integration build process. ###Testing Linux vs Windows So long as all your tests run correctly in both environments, you should be fine measuring coverage on one or the other. But why aren't you doing continuous integration builds in both environments?? If you deliver to clients in both environments then you *need* to be testing in both. For that reason, it sounds like you might need to have two continuous build servers set up, one for a linux build and one for a windows build. Perhaps this can be easily accomplished with some virtualization software like [vmware][3] or [virtualbox][4]. You may not need to run code coverage metrics on both OSs, but you should definitely be running your unit tests on both. [1]: http://www.kimbly.com/blog/000331.html [2]: http://www.bullseye.com/ [3]: http://www.vmware.com/ [4]: http://www.virtualbox.org/
Here are a few "How Do I" videos to get you started: <http://windowsclient.net/learn/videos_wpf.aspx>
Scott Hanselmann has blogged extensively about his experience in learning WPF by creating his 'BabySmash' windows application. All the source code is on codeplex and he has many blog articles describing his progress. [Initial BabySmash article][1] [Codeplex source][2] [BabySmash website][3] [1]: http://www.hanselman.com/blog/IntroducingBabySmashAWPFExperiment.aspx [2]: http://www.codeplex.com/babysmash/SourceControl/ListDownloadableCommits.aspx [3]: http://www.hanselman.com/babysmash/
Add these attributes to the property in your control: [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
You can modify the user's personal.xls file, stored in the excel startup directory (varies between Office versions). If you have lots of users though, that can be fiddly. An alternative way to get over your problem is to store the macro in a template (.xlt) file. Then when the users opens it they can't save it back over the original file, but have to specify a new filename to save it as. The disadvantage of this method is that you then get multiple copies of your original code all over the place with each saved file. If you modify the original .xlt and someone reruns the old macro in a previously-saved .xls file then things can get out of step.
Use the DesignerSerializationVisibilityAttribute on the properties that you want to hide from the designer serialization and set the parameter to Hidden. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public string Name { get; set; }
This is my install scrpt, I use it on debian servers, but it will work in Ubuntu (Ubuntu is built on Debian) apt-get -yq update apt-get -yq upgrade apt-get -yq install sudo apt-get -yq install gcc apt-get -yq install g++ apt-get -yq install make apt-get -yq install apache2 apt-get -yq install php5 apt-get -yq install php5-curl apt-get -yq install php5-mysql apt-get -yq install php5-gd apt-get -yq install mysql-common apt-get -yq install mysql-client apt-get -yq install mysql-server apt-get -yq install phpmyadmin apt-get -yq install samba echo '[global] workgroup = workgroup server string = %h server dns proxy = no log file = /var/log/samba/log.%m max log size = 1000 syslog = 0 panic action = /usr/share/samba/panic-action %d encrypt passwords = true passdb backend = tdbsam obey pam restrictions = yes ;invalid users = root unix password sync = no passwd program = /usr/bin/passwd %u passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n *password\supdated\ssuccessfully* . socket options = TCP_NODELAY [homes] comment = Home Directories browseable = no writable = no create mask = 0700 directory mask = 0700 valid users = %S [www] comment = WWW writable = yes locking = no path = /var/www public = yes' > /etc/samba/smb.conf (echo SAMBAPASSWORD; echo SAMBAPASSWORD) | smbpasswd -sa root echo 'NameVirtualHost * <VirtualHost *> ServerAdmin webmaster@localhost DocumentRoot /var/www/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined ServerSignature On </VirtualHost>' > /etc/apache2/sites-enabled/000-default /etc/init.d/apache2 stop /etc/init.d/samba stop /etc/init.d/apache2 start /etc/init.d/samba start This is a bit specailised but you get the idea, if you save this to a file ('install' for example) all you have to do is: chmod +x install ./install Some of my apt-get commands are not necessary, because apt will automatically get the dependencies but I prefer to be specific, for my installs. If you want some 1 on 1 help just let me know: http://www.unkwndesign.com/?page=contact
Not sure where it went. You could roll your own extension though: <pre> public static class MyBindingExtensions { public static T ReadFromRequest &-l-t-; T &-g-t-; (this Controller controller, string key) { // Setup HttpContextBase context = controller.ControllerContext.HttpContext; object val = null; T result = default(T); // Gaurd if (context == null) return result; // no point checking request // Bind value (check form then query string) if (context.Request.Form[key] != null) val = context.Request.Form[key]; if (val == null) { if (context.Request.QueryString[key] != null) val = context.Request.QueryString[key]; } // Cast value if (val != null) result = (t)val; return result; } } </pre>
Not sure where it went. You could roll your own extension though: public static class MyBindingExtensions { public static T ReadFromRequest < T > (this Controller controller, string key) { // Setup HttpContextBase context = controller.ControllerContext.HttpContext; object val = null; T result = default(T); // Gaurd if (context == null) return result; // no point checking request // Bind value (check form then query string) if (context.Request.Form[key] != null) val = context.Request.Form[key]; if (val == null) { if (context.Request.QueryString[key] != null) val = context.Request.QueryString[key]; } // Cast value if (val != null) result = (t)val; return result; } }
I was going to suggest [Gridiron Flow][1]. But Brian beat me to it. [1]: http://www.gridironsoftware.com/Flow/
@[BCS][1] I'm 99.9% sure that the -l isn't causeing the problem because I can watch the load average on the machine and it drops down to about three and sometimes as low as one (!) without starting the next job. [1]: http://stackoverflow.com/users/1343/bcs
The XMPP gateway protocol you've heard of is most likely to do with transports. A transport is a server that connects to both a XMPP server and a non-XMPP server. By running a transport, I can use my Jabber client to talk to someone using, say, MSN Messenger. A transport typically connects once to the remote network for each JID that it sees as online. That is, it's your option 2 in reverse. This is because there is no special relationship between the transport and the non-XMPP network; the transport is simply acting as a bunch of regular clients. For this to work, XMPP clients must first register with the transport, giving login credentials for the remote network, and allowing the transport to view their presence. The only reason this has a chance of scaling better is that there can be many transports for the same remote network. For example, my Jabber server could run a transport to MSN, another Jabber server could run another one, and so on, each one providing connections for a different subset of XMPP users. While this spreads out the load on the Jabber side, and load balancing on your system may spread out the load as well, it still requires many connections between the two systems. In your case, because (I assume) the non-XMPP side of things is cooperating, putting a XMPP server interface on the non-XMPP server is likely your best bet. That server interface is best suited for managing the mapping between XMPP JIDs and how that JID will appear on its own network, rather than forcing XMPP users to register and so on. In case you haven't seen these, you might find them useful: - [http://www.jabber.org/jabber-for-geeks/technology-overview][1] - [http://www.xmpp.org/protocols/][2] - [http://www.xmpp.org/extensions/][3] Hope that helps. [1]: http://www.jabber.org/jabber-for-geeks/technology-overview [2]: http://www.xmpp.org/protocols/ [3]: http://www.xmpp.org/extensions/
@pkaeding Yes, you're right. *window\[functionName]()* doesn't work in this case, but *eval* does. If I needed something like this, I'd create my own object to keep those functions together. var func = {}; func.bar = ...; var s = "bar"; func[s]();
I think [GPGME][1] and the [PyMe Python wrapper][2] should do what you need. [1]: http://www.gnupg.org/related_software/gpgme/ [2]: http://pyme.sourceforge.net/
Here's the basic pattern: - Check the cache for the value, return if its available - If the value is not in the cache, then implement a lock - Inside the lock, check the cache again, you might have been blocked - Perform the value look up and cache it - Release the lock In code, it looks like this: private static object ThisLock = new object(); public string GetFoo() { // try to pull from cache here lock (ThisLock) { // cache was empty before we got the lock, check it again inside the lock // cache is still empty, so retreive the value here // store the value in the cache here } // return the cached value here }
Here's the basic pattern: - Check the cache for the value, return if its available - If the value is not in the cache, then implement a lock - Inside the lock, check the cache again, you might have been blocked - Perform the value look up and cache it - Release the lock In code, it looks like this: private static object ThisLock = new object(); public string GetFoo() { // try to pull from cache here lock (ThisLock) { // cache was empty before we got the lock, check again inside the lock // cache is still empty, so retreive the value here // store the value in the cache here } // return the cached value here }
I am not sure WHY it does that, but here's what you do in order to get Visual Studio to create the class as Public by default: Go over to “Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033″, you will find a file called Class.zip, inside the .zip file open the file called Class.cs, the content of the file looks like this: using System; using System.Collections.Generic; $if$ ($targetframeworkversion$ == 3.5)using System.Linq; $endif$using System.Text; namespace $rootnamespace$ { class $safeitemrootname$ { } } All you need to do is add “Public” before the class name. The outcome should look like this: using System; using System.Collections.Generic; $if$ ($targetframeworkversion$ == 3.5)using System.Linq; $endif$using System.Text; namespace $rootnamespace$ { public class $safeitemrootname$ { } } One last thing you need to do is flush all the Templates Visual Studio is using, and make him reload them. The command for that is ( it takes a while so hold on): devenv /installvstemplates And that’s it, no more private classes by default. Of course you can also add internal or whatever you want.
I am not sure WHY it does that, but here's what you do in order to get Visual Studio to create the class as Public by default: Go over to “Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033″, you will find a file called Class.zip, inside the .zip file open the file called Class.cs, the content of the file looks like this: using System; using System.Collections.Generic; $if$ ($targetframeworkversion$ == 3.5)using System.Linq; $endif$using System.Text; namespace $rootnamespace$ { class $safeitemrootname$ { } } All you need to do is add “Public” before the class name. The outcome should look like this: using System; using System.Collections.Generic; $if$ ($targetframeworkversion$ == 3.5)using System.Linq; $endif$using System.Text; namespace $rootnamespace$ { public class $safeitemrootname$ { } } One last thing you need to do is flush all the Templates Visual Studio is using, and make him reload them. The command for that is ( it takes a while so hold on): devenv /installvstemplates And that’s it, no more private classes by default. Of course you can also add internal or whatever you want. [Source][1] [1]: http://www.dev102.com/2008/03/14/how-to-get-visual-studio-to-create-new-classes-public-by-default/
I think this sort of depends on the level of "ajaxyness" your app is going to have. If your front end is a "rich client", al'a gmail, I'd go with the JSON solution, as you'd have to solve the problem of having client side view generation anyway. If you're using ajax sparingly, to provide simple messages to the user, update a few fields now and then, etc, then I'd go with option 1, since most of your view logic is already on the server.
Table cells larger than they are meant to be
|html|css|
I've created a map system for a game that runs on the principle of drawing the picture of the map from tiles. There are many reasons for this which I won't go into here but if you really want to know then I'm sure you can find out how to contact me ;) I have [made the latest version live][1] so you can see exactly where the problem lies and the source. The issue is the line between the top 2 tiles and the bottom 2 tiles, I can't figure out why it's gone like this and any help would be appreciated. In the source is a marker called "stackoverflow", if you search for "stackoverflow" when viewing source then it should take you to the table in question. I have also uploaded an [image of the issue][2]. Thanks in advance for any help you can offer. [1]: http://woarl.com/board/rob.php?mode=map&x=-1&y=9&w=2&h=2 [2]: http://woarl.com/badMap.png
Different response format shouldn't be difficult to produce. JSON works best for me, i like to keep OO in js, and don't know how to parse xml well :)
#define IBOutlet Whenever IBOutlet is used in program text, it will be replaced with nothing at all.
If you're looking for a quick solution that should work with most available frameworks, I'd go for JSON. It's easy to start with and works. If you're trying to build a larger application that you're going to extend (in terms of size or maybe your own API for 3rd party extensions) I'd go for XML. You could write a proxy to provide the information in JSON or HTML too, but having XML as the main source is definitly worth the time and effort while building the app. Like [@John Topley][1] said: it depends. [1]: http://stackoverflow.com/users/1450/john-topley
The File.Copy method: http://msdn.microsoft.com/en-us/library/system.io.file.copy(VS.71).aspx
The File.Copy method: [MSDN Link][1] [1]: http://msdn.microsoft.com/en-us/library/system.io.file.copy.aspx
I'd agree with John Topley - it depends on the application. There's a good article on quirksmode that discusses the advantages and disadvantages of each format that you might want to read: [http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html][1] [1]: http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html
Loading assemblies and its dependencies
|c#|.net|
My application dynamically loads assemblies at runtime from specific subfolders. These assemblies are compiled with dependencies to other assemblies. The runtime trys to load these from the application directory. But I want to put them into the modules directory. Is there a way to tell the runtime that the dlls are in a seperate subfolder? Thanks, Jens
|javascript|firebug|
I can easily set breakpoints in embedded JS functions, but I don't see any way of accessing extarnal JS scripts via Firebug unless I happen to enter them during a debug session. Is there a way to do this w/o having to 'explore' my way into the script?
|javascript|firebug|debugging|
|javascript|debugging|firebug|
I can easily set breakpoints in embedded JS functions, but I don't see any way of accessing extarnal JS scripts via Firebug unless I happen to enter them during a debug session. Is there a way to do this w/o having to 'explore' my way into the script? @Jason: This is a good point, but in my case I do not have easy access to the script. I am specifically talking about the client scripts which are invoked by the ASP.Net Validators that I would like to debug. I can access them during a debug session through entering the function calls, but I could not find a way to access them directly.
For me sticking with the Dialog returning the standard dialog responses and then accessing the results via properties is the way to go. Two good reasons from where I sit: 1. Consistency - you're always doing the same thing with a dialog and the very nature of the question suggests that patterns are good (-: Although equally the question is whether this is a good pattern? 2. It allows for return of multiple values from the dialog - ok there's whole new discussion here too but applied pragmatism means that this is what one wants in some circumstances its not always appropriate or desirable to package values up just so that you can pass them back in all in one go. The flow of logic is nice too: if (Dialog == Ok) { // Do Stuff with the entered values } else { // Respond appropriately to the user cancelling the dialog } Its a good question - we're supposed to question stuff like this - but for me the current pattern is a decent one. Murph
What happens if you remove the `Alias /` directive?
Protected member variables?
|c#|java|c++|coding-style|
Should you ever use protected member variables? What are the the advantages and what issues can this cause?
There is a good writeup on [Craig McMurtry's WebLog][1]. Its a couple of years old, but most of it is still relevant. As well as a decision tree to walk through the choices, he shows how to implement those changes using Windows Communication Foundation [1]: http://blogs.msdn.com/craigmcmurtry/archive/2006/07/23/676104.aspx
Tail recursion is well-described in previous answers, but I think an example in action would help to illustrate the concept. Consider a simple function that adds the first N integers. (e.g. `sum(5)=1+2+3+4+5=15`). Here is a simple Python implementation that uses recursion: def recsum(x): if x==1: return x else: return x+recsum(x-1) If you called `recsum(5)`, this is what the Python interpreter would evaluate. recsum(5) 5+recsum(4) 5+(4+recsum(3)) 5+(4+(3+recsum(2))) 5+(4+(3+(2+recsum(1)))) 5+(4+(3+(2+1))) 15 Note how every recursive call has to complete before the Python interpreter begins to actually do the work of calculating the sum. Here's a tail-recursive version of the same function: def tailrecsum(x,runningtotal=0): if x==0: return runningtotal else: return tailrecsum(x-1,runningtotal+x) Here's the sequence of events that would occur if you called `tailrecsum(5)`, (which would effectively be `tailrecsum(5,0)`, because of the default second argument). tailrecsum(5,0) tailrecsum(4,5) tailrecsum(3,9) tailrecsum(2,12) tailrecsum(1,14) tailrecsum(0,15) 15 In the tail-recursive case, with each evaluation of the recursive call, the `runningtotal` is updated.
try with addTab instead of loadOneTab, and remove the last parameter. Check out [this page][1] over at the Mozilla Development Center for information on how to open tabs. You could use this function, for example: function openAndReuseOneTabPerURL(url) { var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); var browserEnumerator = wm.getEnumerator("navigator:browser"); // Check each browser instance for our URL var found = false; while (!found && browserEnumerator.hasMoreElements()) { var browserInstance = browserEnumerator.getNext().getBrowser(); // Check each tab of this browser instance var numTabs = browserInstance.tabContainer.childNodes.length; for(var index=0; index<numTabs; index++) { var currentBrowser = browserInstance.getBrowserAtIndex(index); if ("about:blank" == currentBrowser.currentURI.spec) { // The URL is already opened. Select this tab. browserInstance.selectedTab = browserInstance.tabContainer.childNodes[index]; // Focus *this* browser browserInstance.focus(); found = true; break; } } } // Our URL isn't open. Open it now. if (!found) { var recentWindow = wm.getMostRecentWindow("navigator:browser"); if (recentWindow) { // Use an existing browser window recentWindow.delayedOpenTab(url, null, null, null, null); } else { // No browser windows are open, so open a new one. window.open(url); } } } [1]: http://developer.mozilla.org/en/Code_snippets/Tabbed_browser
You pointed to a breakpoint in the code. Since you are in the debugger, you could set a breakpoint on the constructor of the exception class, or set Visual Studio debugger to break on all thrown exceptions (Debug->Exceptions Click on C++ exceptions, select thrown and uncaught options)
It seems that lxml does not expose this libxml2 feature, grepping the source only turns up some #defines for the error handling: C:\Dev>grep -ir --include=*.px[id] catalog lxml-2.1.1/src | sed -r "s/\s+/ /g" lxml-2.1.1/src/lxml/dtd.pxi: catalog. lxml-2.1.1/src/lxml/xmlerror.pxd: XML_FROM_CATALOG = 20 # The Catalog module lxml-2.1.1/src/lxml/xmlerror.pxd: XML_WAR_CATALOG_PI = 93 # 93 lxml-2.1.1/src/lxml/xmlerror.pxd: XML_CATALOG_MISSING_ATTR = 1650 lxml-2.1.1/src/lxml/xmlerror.pxd: XML_CATALOG_ENTRY_BROKEN = 1651 # 1651 lxml-2.1.1/src/lxml/xmlerror.pxd: XML_CATALOG_PREFER_VALUE = 1652 # 1652 lxml-2.1.1/src/lxml/xmlerror.pxd: XML_CATALOG_NOT_CATALOG = 1653 # 1653 lxml-2.1.1/src/lxml/xmlerror.pxd: XML_CATALOG_RECURSION = 1654 # 1654 lxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG=20 lxml-2.1.1/src/lxml/xmlerror.pxi:WAR_CATALOG_PI=93 lxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG_MISSING_ATTR=1650 lxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG_ENTRY_BROKEN=1651 lxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG_PREFER_VALUE=1652 lxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG_NOT_CATALOG=1653 lxml-2.1.1/src/lxml/xmlerror.pxi:CATALOG_RECURSION=1654 From the [catalog implementation in libxml2 page][1] it seems possible that the 'transparent' handling through installation in /etc/xml/catalog may still work in lxml, but if you need more than that you can always abandon lxml and use the default python bindings, which do expose the catalog functions. [1]: http://xmlsoft.org/catalog.html
This is my install scrpt, I use it on debian servers, but it will work in Ubuntu (Ubuntu is built on Debian) apt-get -yq update apt-get -yq upgrade apt-get -yq install sudo apt-get -yq install gcc apt-get -yq install g++ apt-get -yq install make apt-get -yq install apache2 apt-get -yq install php5 apt-get -yq install php5-curl apt-get -yq install php5-mysql apt-get -yq install php5-gd apt-get -yq install mysql-common apt-get -yq install mysql-client apt-get -yq install mysql-server apt-get -yq install phpmyadmin apt-get -yq install samba echo '[global] workgroup = workgroup server string = %h server dns proxy = no log file = /var/log/samba/log.%m max log size = 1000 syslog = 0 panic action = /usr/share/samba/panic-action %d encrypt passwords = true passdb backend = tdbsam obey pam restrictions = yes ;invalid users = root unix password sync = no passwd program = /usr/bin/passwd %u passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n *password\supdated\ssuccessfully* . socket options = TCP_NODELAY [homes] comment = Home Directories browseable = no writable = no create mask = 0700 directory mask = 0700 valid users = %S [www] comment = WWW writable = yes locking = no path = /var/www public = yes' > /etc/samba/smb.conf (echo SAMBAPASSWORD; echo SAMBAPASSWORD) | smbpasswd -sa root echo 'NameVirtualHost * <VirtualHost *> ServerAdmin webmaster@localhost DocumentRoot /var/www/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined ServerSignature On </VirtualHost>' > /etc/apache2/sites-enabled/000-default /etc/init.d/apache2 stop /etc/init.d/samba stop /etc/init.d/apache2 start /etc/init.d/samba start edit: add this to set your MySQL password /etc/init.d/mysql stop echo "UPDATE mysql.user SET Password=PASSWORD('MySQLPasswrod') WHERE User='root'; FLUSH PRIVILEGES;" > /root/MySQLPassword mysqld_safe --init-file=/root/MySQLPassword & sleep 1 /etc/init.d/mysql stop sleep 1 /etc/init.d/mysql start end edit This is a bit specailised but you get the idea, if you save this to a file ('install' for example) all you have to do is: chmod +x install ./install Some of my apt-get commands are not necessary, because apt will automatically get the dependencies but I prefer to be specific, for my installs. If you want some 1 on 1 help just let me know: http://www.unkwndesign.com/?page=contact
This is my install scrpt, I use it on debian servers, but it will work in Ubuntu (Ubuntu is built on Debian) apt-get -yq update apt-get -yq upgrade apt-get -yq install sudo apt-get -yq install gcc apt-get -yq install g++ apt-get -yq install make apt-get -yq install apache2 apt-get -yq install php5 apt-get -yq install php5-curl apt-get -yq install php5-mysql apt-get -yq install php5-gd apt-get -yq install mysql-common apt-get -yq install mysql-client apt-get -yq install mysql-server apt-get -yq install phpmyadmin apt-get -yq install samba echo '[global] workgroup = workgroup server string = %h server dns proxy = no log file = /var/log/samba/log.%m max log size = 1000 syslog = 0 panic action = /usr/share/samba/panic-action %d encrypt passwords = true passdb backend = tdbsam obey pam restrictions = yes ;invalid users = root unix password sync = no passwd program = /usr/bin/passwd %u passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n *password\supdated\ssuccessfully* . socket options = TCP_NODELAY [homes] comment = Home Directories browseable = no writable = no create mask = 0700 directory mask = 0700 valid users = %S [www] comment = WWW writable = yes locking = no path = /var/www public = yes' > /etc/samba/smb.conf (echo SAMBAPASSWORD; echo SAMBAPASSWORD) | smbpasswd -sa root echo 'NameVirtualHost * <VirtualHost *> ServerAdmin webmaster@localhost DocumentRoot /var/www/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined ServerSignature On </VirtualHost>' > /etc/apache2/sites-enabled/000-default /etc/init.d/apache2 stop /etc/init.d/samba stop /etc/init.d/apache2 start /etc/init.d/samba start edit: add this to set your MySQL password /etc/init.d/mysql stop echo "UPDATE mysql.user SET Password=PASSWORD('MySQLPasswrod') WHERE User='root'; FLUSH PRIVILEGES;" > /root/MySQLPassword mysqld_safe --init-file=/root/MySQLPassword & sleep 1 /etc/init.d/mysql stop sleep 1 /etc/init.d/mysql start end edit This is a bit specailised but you get the idea, if you save this to a file ('install' for example) all you have to do is: chmod +x install ./install Some of my apt-get commands are not necessary, because apt will automatically get the dependencies but I prefer to be specific, for my installs.