instruction
stringlengths
0
30k
You'll want to use the MySQL password recovery process. Follow [these instructions](http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-windows), except replace the password reset query with a query to [add a new user](http://dev.mysql.com/doc/refman/5.0/en/adding-users.html). The ne...
Usually it simply makes the code less readable. And often times people will reuse a property or field of a class without declaring it as a variable, which is generally a bad idea because often times one doesn't know how that field or property is returned. For example, it may be calculated each time, or it may be calcul...
DECLARE @Books TABLE ( [ID] INT IDENTITY(1,1) NOT NULL PRIMARY KEY, [Title] NVARCHAR(MAX) NOT NULL, [Description] NVARCHAR(MAX) NOT NULL, [Date] DATETIME NOT NULL ) INSERT INTO @Books SELECT 'War and Peace','A Russian Epic','2008-01-01' UNION SELECT 'Dogs of Wa...
Generate an array of random floats or ints of the same length. Sort that array, and do corresponding swaps on your target array. This yields a truly independent sort.
Randomizing the array is intensive as you have to shift around a bunch of strings. Why not just randomly read from the array? In the worst case you could even create a wrapper class with a getNextString(). If you really do need to create a random array then you could do something like for i = 0 -> i= array.le...
List<string> stringlist = new List<string>(); // add your values to stringlist Random r = new Random(); List<string> res = new List<string>(); while (stringlist.Length >0) { int i = r.GetNext(stringlist.Length); res.Add(stringlist[i]); stringl...
Running code in the context of a java WAR from the command line
|java|security|tomcat|war|servlets|
How would I go about writing some code to allow access to a Java class in my webapp from the command line. E.g. I have a java class with command line interface, that can runs code in the context of the webapp, with access to the DB etc. I want to log on the machine hosting my WARred app in tomcat and be able to inte...
I think you should put the cast in. Consider that there are three locations for types: T1 *p; p = (T2*) malloc(sizeof(T3)); The two lines of code might be widely separated. Therefore it's good that the compiler will [enforce][1] that T1 == T2. It is easier to visually verify that T2 == T3. If you miss...
Just thinking off the top of my head, you could do this: public string[] Randomize(string[] input) { List<string> inputList = input.ToList(); string[] output = new string[input.Length]; Random randomizer = new Random(); int i = 0; while (inputList.Count > 0) {...
The the C language, before C++, there was no such thing as a boolean. Conditionals were done by testing ints. Zero meant false and any non-zero meant true. So you could write if (2) { alwaysDoThis(); } else { neverDothis(); } Fortunately C++ allowed a dedicated boolean type.
For measuring cyclomatic complexity, there's a nice tool available at [traceback.org][1]. The page also gives a good overview of how to interpret the results. +1 for [pylint][2]. It is great at verifying adherence to coding standards (be it [PEP8][3] or your own organization's variant), which can in the end help t...
Private Function IsLetter(Char As String) As Boolean IsLetter = UCase(Char) Like "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]" End Function
C pointer Q: malloc inside a fn call appears to be getting freed on return of fn?
One way to do this is as follows: **Step #1** Setup the Data Adapter, Data Grid etc: // the data grid DataGridView dataGrid; // create a new data table DataTable table = new DataTable(); // create the data adapter SqlDataAdapter dataAdapter = new SqlDataAda...
By default h1 is a block element and will render on the line after the first img, and will cause the second img to appear on the line following the block. To stop this from occurring you can set the h1 to have inline flow behaviour: div.header > h1 { display: inline; } As for absolutely positioning the img...
By default h1 is a block element and will render on the line after the first img, and will cause the second img to appear on the line following the block. To stop this from occurring you can set the h1 to have inline flow behaviour: #header > h1 { display: inline; } As for absolutely positioning the img *i...
By default h1 is a block element and will render on the line after the first img, and will cause the second img to appear on the line following the block. To stop this from occurring you can set the h1 to have inline flow behaviour: #header > h1 { display: inline; } As for absolutely positioning the img *i...
Usually it just makes the code less readable. And often, when people use this "inlining", they'll re-access a property or field of a class multiple times instead of getting it just once and storing in a local variable. This is generally a bad idea because one doesn't usually know how that field or property is return...
Usually it just makes the code less readable. And often, when people use this "inlining" (i.e. chaining), they'll re-access a property or field of a class multiple times instead of getting it just once and storing in a local variable. This is generally a bad idea because one doesn't usually know how that field or pr...
You can go through the proper channels ask the makers/admins of the software for a mysql account. Ask the mysql admins themselves too. In essence if you hack your way into the database they will shut you down once they find out so might as well ensure you have the proper rights first.
If you don't dispose something, it'll be cleaned up when the garbage collector notices that there are no more references to it in your code, which may be after some time. For something like that, it doesn't really matter, but for an open file it probably does. In general, if something has a Dispose method, you shou...
Here's something I do often, it's not pretty, but it's simple and useful. I often work with template containers that implement an interface, imagine something like template<class T> class MyVector : public ContainerInterface ... Where ContainerInterface has basic useful stuff, but that's all. ...
Go into SQL Server Management Studio and right-click the database. Select Tasks->Generate Scripts. Click Next twice. On the Options window choose set it to generate CREATE statements only, and put everything to False except for the Foreign Keys. Click Next. Select Tables and Click Next again. Click the "Select All" but...
Pick a random number, check if it already exists, if so then keep trying until you hit one that doesn't.
Pick a random number, check if it already exists, if so then keep trying until you hit one that doesn't. Edit: Or better yet, skip the check and just try to insert the row with different IDs until it works.
The DataTrigger is firing but the Text field for your second TextBlock is hard-coded as "items selected" so it won't be able to change. To see it firing, you can remove Text="items selected". Your problem is a good candidate for using a **ValueConverter** instead of **DataTrigger**. Here's how to create and use the ...
I like [Pivotal Tracker][1]. It's a story-based project planning tool that allows teams to collaborate in real-time [1]: http://www.pivotaltracker.com/signup
In ASP.Net, during which page lifecycle event does viewstate get loaded?
|asp.net|viewstate|page-lifecycle|
I know it happens sometime before Load, but during what event exactly?
How are you implementing your data access? If your using NHibernate, I would suggest caching here. NHibernate comes with cache strategies for the .NET built-in cache, memcached (via NMemcachD) and Velocity. I've used memcached extensivly for enterprise level applications and have not had a problem with it. An int...
It's loaded into memory between init and load. See t[his article][1] for a full break down of the page lifecycle. [1]: http://msdn.microsoft.com/en-us/library/ms178472.aspx
I think that what you do is "distribution". At any rate, the support of a lawyer is important in this case.
The [Boost Format Library][1] provides a type-safe, object-oriented alternative for printf-style string formatting and is a complement to iostreams that does not suffer from the usual verbosity issues due to the clever use of operator%. I recommend considering it over using plain C printf if you dislike formatting with...
As Brett said, its better to use a vb component to create collections. Dictionary objects are not very commonly used in ASP unless for specific need based applications.
Usually people refer to something as legacy code when no one is still around that is familiar with or feels comfortable maintaining the code. Unit tests make it easier for people unfamiliar with code to dig into it, so the theory is it helps prevent code from becoming "legacy".
So apparently there are tricks to do this... but it may not be so efficient. 32-bit x86 processors are generally <b>slow</b> at manipulating 16-bit data in general purpose registers. You ought to benchmark it if performance is important. Unless this is (a) performance critical and (b) proves to be much faster, I w...
Debugging Websites in Internet Explorer
|internet-explorer|profiling|
I have a Website that is really slow and "feels" really bad when using it. The server is fine, it's a clientside issue, I assume because too much JavaScript or Image Requests, but since it's not my own Website, I wonder if there is a way to show and profile the Page from within IE. In Firefox, I would use Firebug, Y...
I have a Website that is really slow and "feels" really bad when using it. The server is fine, it's a clientside issue, I assume because too much JavaScript or Image Requests, but since it's not my own Website, I wonder if there is a way to show and profile the Page from within IE. In Firefox, I would use Firebug, Y...
For end-user view i prefer "about-us" or "about us" not "about_us"
I use iostreams, mainly because that makes it easier to fiddle with the stream later on (if I need it). For example, you could find out that you want to display the output in some trace window -- this is relatively easy to do with cout and cerr. You can, off course, fiddle with pipes and stuff on unix, but that is not ...
One thing that comes in mind is sniffing the database communication and hope it's not encrypted. If it is encrypted try changing the configuration not to use SSL and restart mysql. A good sniffer that I use is [Wireshark][1] From [mysql 5.0 documentation][2]: > MySQL supports secure (encrypted) > connection...
You can go through the proper channels ask the makers/admins of the software for a mysql account. Ask the mysql admins themselves too. In essence if you hack your way into the database they will shut you down once they find out so might as well ensure you have the proper rights first. Edit: if you have full acce...
You can easily find yourself in a situation when you need more than one level. For example, your company has a giant namespace for all of its code to separate it from third party code, and you are writing a library which you want to put in its own namespace. Generally, whenever you have a very large and complex syste...
Seam/JSF form submit firing button onclick event
|java|html|firefox|jsf|seam|
I have a search form with a query builder. The builder is activated by a button. Something like this <h:form id="search_form"> <h:outputLabel for="expression" value="Expression"/> <h:inputText id="expression" required="true" value="#{searcher.expression}"/> <button onclick="openBuilder(); re...
1. Avoid identical error messages coming from different places; parametrize with file:line if possible, or use other context that lets you, the developer, uniquely identify where the error occurred. 2. Design the mechanism to allow easy localization, especially if it is a commercial product. 3. If the error messag...
I think you must use [ and ] instead of ": SELECT customers.[Street 1] FROM customers WHERE ...
Shorter messages may actually be read. The longer your error message, the less the user will read. That being said, try to refactor the code so you can eliminate exceptions if there is an obvious response. Try to only have exceptions that happen based on things beyond your user or your code's control. The best e...
If it's managed (i.e. part of the framework) you don't need to worry about it. If it implements IDisposable just wrap it in a `using` block. If you want to use unmanaged resources then you need to read up on finalisers and implementing IDisposable yourself. There's a lot more detail under [this question](http://s...
Ruby/GNOME2 works pretty well. You can use Glade to drag and drop window elemtns and load it the UI from your Ruby app.
We've used [js_compactor][1] and [JavaScriptLint][2] to "compile" and compress our JavaScript in our automated build process. A further build step would take the compress JavaScript and combine related files into a single package. The performance boost was significant, but be aware that you are away trading the abili...
SQLExplorer is a great Eclipse plugin or standalone interface that works with many different database systems, either with dedicated drivers or with ODBC.
something stupid. It's getting the value of the selected item and taking the everything after the first two characters. If that is only one character, then it adds a '0' to the beginning of it, and if it is zero characters, the it returns '00'. The reason I say this is stupid is because if you need the value to be t...
Is it vain to suggest my own? It's not perfect, but I think it's a good mix of simple, friendly, and optionally thorough: [https://www.woot.com/User/Register.aspx][1] [1]: https://www.woot.com/User/Register.aspx
If you only have a small number of possible tuple values it would make sense to write some sort of hashing function which could turn them into integer indexes for quick searching. If there are < 32 values you could do something with bitmasks: unsigned int hash(char *value){...} typedef struct _touple {...
If you only have a small number of possible tuple values it would make sense to write some sort of hashing function which could turn them into integer indexes for quick searching. If there are < 32 values you could do something with bitmasks: unsigned int hash(char *value){...} typedef struct _touple {...
If you only have a small number of possible tuple values it would make sense to write some sort of hashing function which could turn them into integer indexes for quick searching. If there are < 32 values you could do something with bitmasks: unsigned int hash(char *value){...} typedef struct _tuple { ...
You can simply include this as a normal HTML form in a mime part. See http://abiglime.com/webmaster/articles/cgi/010698.htm for how to do that. However, many email clients will not display this. For example, in Thunderbird, there are settings for displaying message: "Original HTML", "Simple HTML", "Plain text". It w...
How do you visualize logfiles?
|logging|statistics|visualization|
Sometimes it might be useful, but mostly just looking cool or impressive to visualize log files (anything from http requests and to bandwith usage to cups of coffee drunk per day). I know about [Visitorville][1] which I think look a bit silly, and then there's [gltail][2]. How do you "visualize" your log files? ...
How do you visualize logfiles in realtime?
|statistics|logging|visualization|
Sometimes it might be useful, but mostly just looking cool or impressive to visualize log files (anything from http requests and to bandwith usage to cups of coffee drunk per day). I know about [Visitorville][1] which I think look a bit silly, and then there's [gltail][2]. How do you "visualize" your log files in...
If the types you're switching on are primitive .NET types you can use Type.GetTypeCode(Type), but if they're custom types they will all come back as TypeCode.Object. A dictionary with delegates or handler classes might work as well. Dictionary<Type, HandlerDelegate> handlers = new Dictionary<Type, HandlerDe...
It sounds like there are 3 fundamental techniques that have been suggested so far. 1. Derive from the Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase class and set the IsSingleInstance property to true. (I believe a caveat here is that this won't work with WPF applications, will it?) 2. Use a ...
If you just want to play around why not use the netbeans IDE to generate your ear files. If you create an enterprise project it will automatically generate the ant files for you. Good for prototyping and just getting started :-) There is even a was plugin which allows automated deployment however this seems very sha...
See also the answers to the closely related question "choosing a c++ unit testing tool/framework", [here][1] [1]: http://stackoverflow.com/questions/13699/choosing-a-c-unit-testing-toolframework#113686
No. This would be a massive security hole if it were possible... not to mention annoying. My browser wont even let you do this in popups... which can be annoying aswell!
It really depends on what you want to do. WIA is primarily for capturing stills from imaging devices, and DirectShow (used either through [directshow.net][1] or managed DirectX) is for access to fuller video features. The other option is to create a WPF application. It has a huge amount of built in support for video...
Hiding toolbar / status bar with javascript in CURRENT browser window?
|javascript|
Is there some way to hide the browser toolbar / statusbar etc in current window via javascript? I know I can do it in a popup with window.open () but i need to do it this way. Is it possible at all?
|javascript|user-interface|
Just as an addition to this, I thought I would say I have put a [blog post][1] up on my thoughts on getting started with testing (following this discussion and my own research), since it may be useful to people viewing this thread. "[TDD – Getting Started with Test-Driven Development][1]" - I have got some great fee...
How not to repeat yourself across projects and/or languages
|maintainability|dry|
I'm working on several distinct but related projects in different programming languages. Some of these projects need to parse filenames written by other projects, and expect a certain filename pattern. This pattern is now hardcoded in several places and in several languages, making it a maintenance bomb. It is fairl...
Marijn: ok thanks. This is for an intranet site and we display InfoPath forms as separate, no-toolbar, no-statusbar windows. This is a client requirement, I'm not trying to do evil ;)
I believe this is not possible. And anyway, just don't do it. Your page can do what it wants with the rendering area, but the rest of the browser belongs to the user and websites have not business messing with it.
do you mean something like [PG Admin][1] for administration? [1]: http://www.pgadmin.org/
How do I get a string type of a hex value that represents an upper ascii value character
|c#|rtf|
Part of our app parses RTF documents and we've come across a special character that is not translating well. When viewed in Word the character is an elipsis (...), and it's encoded in the RTF as ('85). In our vb code we converted the hex (85) to int(133) and then did Chr(133) to return (...) Here's the code in C...
Josh Bloch and Bill Pugh refer to this issue in "Java Puzzlers IV: The Phantom Reference Menace, Attack of the Clone, and Revenge of The Shift" ([Google TechTalk](http://video.google.com/videoplay?docid=9214177555401838409")). Josh Bloch says (6:41) that they attempted to generify the get method of Map, remov...
If you don't know where to begin, start small. Sit a friend down at your computer. Explain that you want them to accomplish a task using software, and watch everything they do. It helps to remain silent while they are actually working. Write everything down. `"John spent 15 seconds looking at the screen before a...
We've used [js_compactor][1] and [JavaScriptLint][2] to "compile" and compress our JavaScript in our automated build process. A further build step would take the compress JavaScript and combine related files into a single package. The performance boost was significant, but be aware that you are away trading the abili...
We've used [js_compactor][1] and [JavaScriptLint][2] to "compile" and compress our JavaScript in our automated build process. A further build step would take the compress JavaScript and combine related files into a single package. The performance boost was significant, but be aware that you are away trading the abili...
Error *handling* is always better than error *reporting*, but since you are retrofitting the error messages and not necessarily the code here's a couple of suggestions: Users want solutions, not problems. Help them know what to do after an error, even if the message is as simple as "Please close the current window a...
How do display a form in any site's pages using a bookmarklet (like Note in Google Reader)?
|javascript|bookmarklet|js|browser|
If you are using C# the code and connection string is: using System.Data.SqlClient; ... SqlConnection oSQLConn = new SqlConnection(); oSQLConn.ConnectionString = "Data Source=(local);" + "Initial Catalog=myDatabaseName;" + "Integrated Security=SSPI"; //Or ...
If you are using C# the code and connection string is: using System.Data.SqlClient; ... SqlConnection oSQLConn = new SqlConnection(); oSQLConn.ConnectionString = "Data Source=(local);" + "Initial Catalog=myDatabaseName;" + "Integrated Security=SSPI"; //Or ...
This gives info on query analyzers in Rails [http://ronnyml.wordpress.com/2008/07/03/query-analyzer-for-rails/][1] [1]: http://ronnyml.wordpress.com/2008/07/03/query-analyzer-for-rails/