instruction
stringlengths
0
30k
Here's what you can do, you have 2 options: select * FROM users u LEFT JOIN organizations o ON (u.idorg = o.id); This way you will get extra data on each row - full organization info you don't really need. Or you can do: select o.*, group_concat(u.name) FROM users u ...
You have to explicitly set the position of the parent container along with the position of the child container. The typical way to do that is something like this: div.parent { position: relative; left: 0px; // stick it wherever it was positioned by default top: 0px; } ...
Just use ActiveRecord and a simple Rakefile. For example, if you put your migrations in a `db/migrate` directory and have a `database.yml` file that has your db config, this simple Rakefile should work: **Rakefile:** require 'active_record' require 'yaml' desc "Migrate the database through script...
I've done it both ways.. IMO it depends on the complexity of the initialization. If it is simple 2 or 3 properties I will initialize on one line generally, but if i'm setting up an object with values for insertion into a database or something that has alot of properties i'll break it out like your second example. ...
It's more important to be consistent than anything, so pick something you and your teammates can agree upon and stick with it. And if the language you're coding in has a convention, you should try to stick to it. Nothing's more confusing than a code base that follows a prefixing rule inconsistently. For c++, there...
It looks like you're opening it as a class variable... so the proper way would be to do... class Foo def initialize @@log = Syslog.open("foo") end def Foo.finalize(id) @@log.close if @@log end end Though this is not necesssarily predictable or support...
For my own projects I use _ as a postfix (as Martin York noted above, _ as a prefix is reserver by the C/C++ standard for compiler implementations) and i when working on [Symbian projects](http://www.symbian.com/developer/techlib/v70sdocs/doc_source/DevGuides/EssentialIdioms/NamingConvs.guide.html).
Both notations are fine. I would simply suggest to use the first (1-line) notation whenever your line stay within 100 characters, and switch to the second (multi-line) notation whenever the expression is longer.
Well, I assume you are working with a very large set of data, and thus are using virtual mode to implement your own data binding. If that is the case here is a link that demonstrates the process: [http://msdn.microsoft.com/en-us/library/2b177d6d.aspx][1] It primarily involves implementing an event handler for ...
Best practice for naming convention of UI controls for referencing in code-behind?
|report|naming-conventions|
What is the best practice for naming UI controls (textboxes, drop-downs, etc.) on forms and reports for reference in the code-behind pages? I develop a lot of reports and forms in my office. I have several web applications providing about 80+ "live" reports being generated from various and multiple data sources (Ac...
![alt text][1] (Providing a picture of the behaviour to help you get a better answer). For those with a theory, you can try this out in Excel as well (not just Reporting Services). You mentioned adding points in your question, but it seems like adding in interpolated points near the problem area has the desir...
I think it's a myth that forms are "difficult" to layout nicely with good HTML and CSS. The level of control that CSS gives you over your layout goes way beyond what any clunky table-based layout ever would. This isn't a new idea, as [this Smashing Magazine article][1] from way back in 2006 shows. I tend to use vari...
I believe it's just something Gmail does when mail is sent through its SMTP, as it was mentioned that they do this on a tutorial about using their SMTP to send mail.
Yes, I have started to pay very good attention to Google Chrome for my applications. Recent analytics show that between 6%-15% of my users are accessing my applications (varies between 6 to 15 in different applications) on Chrome. And, this number looks on an upward trend. Thus, I can't really ignore it for testing ...
The main reason to unit test code in the first place is to validate the design of your code. It's possible to gain 100% code coverage, but not without using mock objects or some form of isolation or dependency injection. Remember, unit tests aren't for users, they are for developers and build systems to use to vali...
If you have no programming experience, then creating a native iPhone application will be a daunting task. Developing for the iPhone is much like developing for the desktop mac, it's a very complete and mature system. I'd honestly say, stick with doing a web-app for the iPhone. Mobile Safari makes available some spec...
Just use ActiveRecord and a simple Rakefile. For example, if you put your migrations in a `db/migrate` directory and have a `database.yml` file that has your db config, this simple Rakefile should work: **Rakefile:** require 'active_record' require 'yaml' desc "Migrate the database through script...
Any reason not to just include that in the testing of one of the instances? If that doesn't work, you could probably create a subclass just for testing with no unique functionality of its own.
SQL Query Help: Selecting Rows That Appear A Certain Number Of Times
|sql|query|date|select|
I have a table with a "Date" column. Each Date may appear multiple times. How do I select only the dates that appear < k number of times?
The first thing that comes to mind is to test those methods in a concrete child class.
I've used 2 profiling tools before - RedGate's ANTS profiler, and the built in profiler found in Visual Studio Team System. It's been some time since I used RedGate's (http://www.red-gate.com/products/ants_profiler/index.htm) profiler, though I used the built in in Visual Studio 2008 fairly recently. That being s...
I've used 2 profiling tools before - RedGate's ANTS profiler, and the built in profiler found in Visual Studio Team System. It's been some time since I used RedGate's (http://www.red-gate.com/products/ants_profiler/index.htm) profiler, though I used the built in in Visual Studio 2008 fairly recently. That being s...
It depends. This is one of those issues that must be decided pragmatically. Suppose I had a class for representing a point. I could have getters and setters for the X and Y coordinates, or I could just make them both public and allow free read/write access to the data. In my opinion, this is OK because the class is ...
Factor out common sequences of actions and just put them in one subtest each. Run only the subtests you need for any given feature.
Encapsulation is important when at least one of these holds: 1. Anyone but you is going to use your class (or they'll break your invariants because they don't read the documentation). 2. Anyone who doesn't read the documentation is going to use your class (or they'll break your carefully documented invariants). N...
A great piece of advice I got from *The Pragmatic Programmer* was something along the lines of "your program should be able to perform all its main functionality without using exceptions at all".
Alternately, you can maintain a separate table containing a buffer of generated, known to be unique account numbers. This table should have an auto-incrementing integer id. When you want an account number, simply pull the record with the lowest index in the buffer and remove it from that table. Have some process that r...
Alternately, you can maintain a separate table containing a buffer of generated, known to be unique account numbers. This table should have an auto-incrementing integer id. When you want an account number, simply pull the record with the lowest index in the buffer and remove it from that table. Have some process that r...
Excel Macro Language
|excel|vb|macros|
I have an old Excel 4 Macro that I use to run monthly invoices. It is about 3000 lines and has many Excel 5 Dialog Box sheets (for dialog boxes). I would like to know what the easiest way would be to change it into Visual Basic and if it is worth it. I would also like to know how, if once I have converted it to VBA,...
|excel|vba|macros|
Closing/cleaning up "mixed" file descriptors / sockets.
|c|sockets|io|file-descriptor|
When I create a socket using accept() and make a FILE out of it using fdopen(), what do I have to do to clean everything up? Do I need to do fclose() on the FILE, shutdown() and close() on the socket, or only the shutdown() and or close() or fclose()? If I don't do fclose(), do I have to free() the FILE pointer manuall...
You might want to create your own iterator class that iterate over those files. Say, make a XMLContentEnumerator : IEnumerable. that would iterate over files in a specific directory and parse its content, and then you would be able to make a normal LINQ filtering query such as: var xc = new XMLContentEnumerat...
How can I refresh all the pivot tables in my excel workbook with a macro?
|excel|vb|macros|pivot-table|
I have a workbook with 20 different pivot tables. Is there any easy way to find all the pivot tables and refresh them in VB?
|excel|vba|macros|pivot-table|
If you are using .Net 3.5, this is extremely easy with LINQ: //get the files XElement xe1 = XElement.Load(string_file_path_1); XElement xe2 = XElement.Load(string_file_path_2); //Give me all XML that has a filter of 'filter'. var filter_elements1 = from p in xe1.Descendants("filter") se...
- I recommend the asynchronous model for most applications, especially if you want performance or applications that don't hang as soon there is a network problem. For this the MSDN articles on [Socket.BeginConnect][2] and [Socket.BeginReceive][3] are good places to start. - The following link is not .NET, but many of...
There isn't a standardized way. I assume this is because the C++ standardization group didn't want to assume that a file handle can be represented as a fd. Most platforms do seem to provide some non-standard way to do this. http://www.ginac.de/~kreckel/fileno/ provides a good writeup of the situation and provide...
A form is not "presentation", you ask for data, you do not usually present data. I use a lot of inline editing in tabular data. Obviousely i use the datacells - td as holders for the input elements when switching from presentation to input.
It could be that your "path" environment variable does not contain the path to the folder where cl.exe is located. Another possible reason could be that when installing VS2008, you did not select the option to install the Win32 tools (which include the command line compiler). In any case, you may want to try to...
This page has an exhaustive example of setting up a dynamic column ("crosstab"-type) report in Access. http://www.blueclaw-db.com/report_dynamic_crosstab_field.htm (From google search: access transform query report)
How can I programatically manage iptables rules on the fly?
|linux|api|kernel|iptables|netfilter|
I need to query existing rules, as well as being able to easily add and delete rules. I haven't found any APIs for doing this, is there something that I'm missing? The closest I've come to a solution is using `iptables-save | iptables-xml` for querying, and manually calling the iptables command itself to add/delete ...
This is most likely to stop people trying to send email from addresses that Google can't verify that the sender owns. This is fairly common amongst mail providers, and is probably a safeguard to stop people using Google's services for sending spam.
As Baltimark said, this is basically a Linear programming problem. If only the coefficients for the shippers (1 for included, 0 for not included) were not (binary) integers for each leg, this would be more easily solveable. Now you need to find some (binary) integer linear programming (ILP) heuristics as the problem i...
Absolute positioning positions an element relative to its nearest positioned ancestor. So put `position: relative` on the container, then for child elements, `top` and `left` will be relative to the top-left of the container so long as the child elements have `position: absolute`. More information is available in <a ...
Determining JIT time for weighing NGEN feasibility is certainly a good starting point. I also would agree with those who look to fudge the load time by using another entry point to then load the assemblies. Often it's the ***appearance of speed*** versus ***actual speed*** that improves the user experience.
Please explain thread local storage for Python.
|python|multithreading|
In Python specifically, how do variables get shared between threads? Although I have used threading.Thread before I never really understood or saw examples of how variables got shared. Are they shared between the main thread and the children or only among the children? I have seen many warnings about synchronizi...
Pass the person when you create the command object: ICommand command = new DeletePersonCommand(person); so that when you execute the command, it already knows everything that it needs to know. class DeletePersonCommand : ICommand { private Person person; public DeletePersonComma...
One thing I fear about exceptions is that throwing an exception will screw up code flow. For example if you do void foo() { MyPointer* p = NULL; try{ p = new PointedStuff(); //I'm a module user and I'm doing stuff that might throw or not } catch(...) ...
My tendency is to try to make everything private if possible. This keeps object boundaries as clearly defined as possible and keeps the objects as decoupled as possible. I like this because when I have to rewrite an object that I botched the first (second, fifth?) time, it keeps the damage contained to a smaller number...
I prefer to use exceptions for error handling and return values (or parameters) as the normal result of a function. This gives an easy and consistent error-handling scheme and if done correctly it makes for much cleaner looking code.
I prefer to keep members private as long as possible and only access em via getters, even from within the very same class. I also try to avoid setters as a first draft to promote value style objects as long as it is possible. Working with deendency injection a lot you often have setters but no getters, as clients shoul...
C# Properties 'simulate' public fields. Looks pretty cool and the syntax really speeds up creating those get/set methods
The [Community Wiki link][1] has good answers for everything except - **Do abstract classes simply have a NULL for the function pointer of at least one entry?** The answer for that is that it is unspecified - calling the pure virtual function results in undefined behavior if it is not defined (which it usually ...
<p>It depends entirely on the phone. If you want to support every single device out there, don't even bother with CSS or JavaScript since neither will work (or will do something completely non-standard) on 99% of devices. If you are only targeting high-end devices, like the iPhone or the latest Series 60 Nokias, you sh...
C# VB.NET Conversion
|c#|.net|vb.net|
Which tools do you use to convert between C# an VB.Net?
This kind of problem are usually resolved with recursion. In ruby, one (quick and dirty) solution would be @values = Hash.new([]) @values["0"] = ["N"] @values["1"] = ["L"] @values["2"] = ["T"] @values["3"] = ["D"] @values["4"] = ["R"] @values["5"] = ["V","F"] ...
Getting started with WAS ND can be a bit overwhelming. The redbooks mentioned above to give you a good introduction, especially the first few chapters but they are often over 500 pages long. IBM also provides an educational assistant which is a presentation style overview and that may give a good point to start with....
JSTL collection iteration
|java|jsp|jstl|jsp-tags|
I have a java bean like this: class Person { int age; String name; } I'd like to iterate over a collection of these beans in a JSP, showing each person in a HTML table row, and in the last row of the table I'd like to show the total of all the ages. The code to generate the table rows wi...
How can I find last row that contains data in the excel sheet with a macro?
|excel|vb|macros|
How can I find the last row that contains data in a specific column and on a specific sheet?
|excel|vba|macros|
Can I just check: You made the addition of sproc2? Prior to that it was working fine for ages. Could you not change where you call sproc2 from? Rather than calling it from inside sproc1, can you call it from the ASP? That way you control the authentication to SQL in the code, and don't have to rely on setting up any...
Try [SPAW Editor][1]. File Manager is included. Editor is generated from server side code, meaning it's lighter on client side processing. [1]: http://spaweditor.com "SPAW Editor"
MOSS 2007: BDC permisson problem - no BDC application is listed in the web part's configuration menu
|sharepoint|moss|bdc|
I'm actually working at MOSS 2007 project where I have to import data from an external data source (WebService) via an application in the Business Data Catalog. The application definition was created with BDC Meta Man and was imported successfully into the Business Data Catalog without any errors. I've first tested...
We use [Codejock][1]. It's not cheap, but I guess I've come to find that good controls usually are :-). They are fairly responsive in the tech support department (although we haven't had need to use that recently). We are buidling a whole suite of tools using these controls and have always had what we've needed, inc...
The term is so new that there's no accepted definition, particularly since Dell (!) failed to trademark the term. Essentially the idea is similar to that of a utility - you want electricity, but you don't care which power station supplies it because there's a network supplying electricity to everyone, and you can ju...
You have to create a subclass that implements the abstract methods (with empty methods), but none of the concrete ones. This subclass should be for testing only (it should never go into your production code). Just ignore the overridden abstract methods in your unit tests and concentrate on the concrete methods.
It is tough not to be tempted to want to learn it all, but I try not to jump into anything that is 'too new' I seem to end up with a lot of frustration with not a lot of sources out there to help. While someone does have to take the dive head first and I respect those people (I guess that's the life of a beta tester) ...
I Always use Stub/Mock object
Use the COUNT aggregate: SELECT Date FROM SomeTable GROUP BY Date HAVING COUNT(*) < @k
SELECT date, COUNT(date) FROM table GROUP BY date HAVING COUNT(date) < k And then to get the original data back: SELECT table.* FROM table INNER JOIN ( SELECT date, COUNT(date) FROM table GROUP BY date HAVING COUNT(date) < k) dates ON table.date = date...
In this case, what we've done with our Command objects is to create a Context object which is essentially a map. The map contains name value pairs where the keys are constants and the values are parameters that are used by the Command implementations. Especially useful if you have a Chain of Commands where later comm...
You have to define and create a concrete test class that inhereits from the abstract. Typically it will be a light shim that does nothing but pass through calls.
Assuming you are using Oracle, and k = 5:- select date_col,count(*) from your_table group by date_col having count(*) < 5; If your date column has time filled out as well, and you want to ignore it, modify the query so it looks as follows:- select trunc(date_col) as date_col,count(*) ...
select dates from table t group by dates having count(dates) < k ; Hopefully, it works for ORACLE. HTH
How should a blog be structured to easily extract its data?
|data-structures|wordpress|blogs|bloatware|
I'm currently using Wordpress to run my website. However, with each new release I become more concerned with software bloat and the convoluted table structures used to store my data. Maybe this is a fruitless pursuit. Features are always added to blogging software until it claims to be a CMS--and at that point your ...
There is deliberately no API to manage these rules. You're not supposed to want to do so. Or something. If you need rules which are sufficiently dynamic you care about the performance of executing /sbin/iptables, there are other ways to do it: * Using something like the "recent" match or ip set matching, you can ...