Prompt stringlengths 10 31k | Chosen stringlengths 3 29.4k | Rejected stringlengths 3 51.1k | Title stringlengths 9 150 | Tags listlengths 3 7 |
|---|---|---|---|---|
Recently I have been having issues with Firefox 3 on Ubuntu Hardy Heron.
I will click on a link and it will hang for a while. I don't know if its a bug in Firefox 3 or a page running too much client side JavaScript, but I would like to try and debug it a bit.
So, my question is "is there a way to have some kind of pr... | It's probably the [awesome firefox3 fsync "bug"](http://shaver.off.net/diary/2008/05/25/fsyncers-and-curveballs/), which is a giant pile of fail.
In summary
* Firefox3 saves its bookmarks and history in an SQLite database
* Every time you load a page it writes to this database several times
* SQLite cares deeply that... | > So, my question is, is there a way to have some kind of process explorer, or task manager sort of thing for Firefox 3?
Because of the way Firefox is built this is not possible at the moment. But the new Internet Explorer 8 Beta 2 and the just announced Google Chrome browser are heading in that direction, so I suppos... | Some kind of task manager for JavaScript in Firefox 3? | [
"",
"javascript",
"firefox",
"memory",
"cpu",
""
] |
I've read some about .egg files and I've noticed them in my lib directory but what are the advantages/disadvantages of using then as a developer? | From the [Python Enterprise Application Kit community](http://peak.telecommunity.com/DevCenter/PythonEggs):
> *"Eggs are to Pythons as Jars are to Java..."*
>
> Python eggs are a way of bundling
> additional information with a Python
> project, that allows the project's
> dependencies to be checked and
> satisfied at ... | One egg by itself is not better than a proper source release. The good part is the dependency handling. Like debian or rpm packages, you can say you depend on other eggs and they'll be installed automatically (through [pypi.python.org](http://pypi.python.org)).
A second comment: the egg format itself is a binary packa... | What are the advantages of packaging your python library/application as an .egg file? | [
"",
"python",
"zip",
"packaging",
"software-distribution",
"egg",
""
] |
It strikes me that Properties in C# should be use when trying to manipulate a field in the class. But when there's complex calculations or database involved, we should use a getter/setter.
Is this correct?
When do you use s/getter over properties? | The .NET design guidelines provide some answers to this question in the [Properties vs. Methods](http://msdn.microsoft.com/en-us/library/bzwdh01d(VS.71).aspx#cpconpropertyusageguidelinesanchor1) section.
Basically, properties have the same semantics as a field. You shouldn't let a property throw exceptions, properties... | If your language supports properties, just use properties. | Convention question: When do you use a Getter/Setter function rather than using a Property | [
"",
"c#",
""
] |
I want to be able to play sound files in my program. Where should I look? | I wrote the following code that works fine. But I think it only works with `.wav` format.
```
public static synchronized void playSound(final String url) {
new Thread(new Runnable() {
// The wrapper thread is unnecessary, unless it blocks on the
// Clip finishing; see comments.
public void run() {
try ... | A bad example:
```
import sun.audio.*; //import the sun.audio package
import java.io.*;
//** add this into your application code as appropriate
// Open an input stream to the audio file.
InputStream in = new FileInputStream(Filename);
// Create an AudioStream object from the input stream.
AudioStream as = new ... | How can I play sound in Java? | [
"",
"java",
"audio",
""
] |
What are the best code snippets for C#? (using visual studio) VB has a lot that are pre-defined, but there are only a handful for C#. Do you have any really useful ones for C#?
Anyone want to post a good custom one you created yourself?
[Anyone?... Bueller?](http://en.wikipedia.org/wiki/Ferris_Bueller) | Microsoft have released a whole bunch of C# snippets that bring it up to parity with the ones for Visual Basic. You can download them here:
<http://msdn.microsoft.com/en-us/library/z41h7fat.aspx> | My absolute favorite is `cw`. | What are the most useful (custom) code snippets for C#? | [
"",
"c#",
"visual-studio",
"code-snippets",
""
] |
I'm wondering what the best practice is for handling the problem with having to "include" so many files in my PHP scripts in order to ensure that all the classes I need to use are accessible to my script.
Currently, I'm just using [include\_once](http://php.net/manual/en/function.include-once.php) to include the class... | I my applications I usually have `setup.php` file that includes all core classes (i.e. framework and accompanying libraries). My custom classes are loaded using autoloader aided by directory layout map.
Each time new class is added I run command line builder script that scans whole directory tree in search for model c... | You can define multiple autoloading functions with spl\_autoload\_register:
```
spl_autoload_register('load_controllers');
spl_autoload_register('load_models');
function load_models($class){
if( !file_exists("models/$class.php") )
return false;
include "models/$class.php";
return true;
}
function... | How to handle including needed classes in PHP | [
"",
"php",
"class",
"include",
"autoload",
""
] |
This is driving me crazy.
I have this one php file on a test server at work which does not work.. I kept deleting stuff from it till it became
```
<?
print 'Hello';
?>
```
it outputs
> Hello
if I create a new file and copy / paste the same script to it it works!
Why does this one file give me the strange charac... | That's the [BOM (Byte Order Mark)](http://en.wikipedia.org/wiki/Byte_Order_Mark) you are seeing.
In your editor, there should be a way to force saving without BOM which will remove the problem. | Found it, file -> encoding -> UTF8 with BOM , changed to to UTF :-)
I should ahve asked before wasing time trying to figure it out :-) | Strange characters in PHP | [
"",
"php",
"encoding",
""
] |
I'm using [Zend Studio](http://www.zend.com/en/products/studio/) to do remote debugging of my php scripts on a dev server. It works great for web code, but can I make it work with command line scripts?
I have several helper apps to make my application run. It would be really useful to fire up the remote debugger throu... | I was able to get [remote CLI debugging working in Eclipse](http://thenazg.blogspot.com/2008/12/remote-cli-debugging-via-eclipse-pdt.html), using xdebug, though I've not tried it with the zend debugger. I would assume this should work the same with ZSfE, if that's the "Zend Studio" you're using. | Since this is more along the lines of product support, your best bet is probably emailing the support people. We bought Zend Studio at my last job and they were always able to help us in a matter of hours.
Feel free to post the answer though, I am sure there are more people looking for it. :) | Remote Debugging PHP Command Line Scripts with Zend? | [
"",
"php",
"debugging",
"xdebug",
"zend-studio",
""
] |
Let's say you want to save a bunch of files somewhere, for instance in BLOBs. Let's say you want to dish these files out via a web page and have the client automatically open the correct application/viewer.
Assumption: The browser figures out which application/viewer to use by the mime-type (content-type?) header in t... | The python-magic method suggested by [toivotuo](https://stackoverflow.com/a/2133843/5337834) is outdated. [Python-magic's](http://github.com/ahupp/python-magic) current trunk is at Github and based on the readme there, finding the MIME-type, is done like this.
```
# For MIME types
import magic
mime = magic.Magic(mime=... | The [mimetypes module](https://docs.python.org/library/mimetypes.html) in the standard library will determine/guess the MIME type from a file extension.
If users are uploading files the HTTP post will contain the MIME type of the file alongside the data. For example, Django makes this data available as an attribute of... | How to find the mime type of a file in python? | [
"",
"python",
"mime",
""
] |
A very niche problem:
I sometimes (30% of the time) get an 'undefined handler' javascript error on line 3877 of the prototype.js library (version 1.6.0.2 from google: <http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js>).
Now on this page I have a Google Map and I use the Prototype Window library.
T... | I just found out this error also occurs if you accidentally leave on the parenthesis on your observer call:
```
Event.observe(document, 'myapp:application_ready', myapp.MyClass.initApp());
```
instead of
```
Event.observe(document, 'myapp:application_ready', myapp.MyClass.initApp);
``` | > I switched to a local version of prototypejs and added some debugging
> in the offending method (createWraper) but the debugging never appears
> before the error...
Actually the offending function being called when the error occurs is "wrapper" which is created inside createWrapper (but not called there). Basically ... | "undefined handler" from prototype.js line 3877 | [
"",
"javascript",
"google-maps",
"prototypejs",
""
] |
I have this idea for a free backup application.
The largest problem I need to solve at the moment is how to access files which are being used or are system files. I would like the application to be able to perform a full backup of files (i.e. not on a disk sector by sector level).
I'll turn the server part of the app... | What you're looking for regarding the files in use is the "[Volume Shadow Copy Service](http://msdn.microsoft.com/en-us/library/bb968832(VS.85).aspx "MSDN - Volume Shadow Copy Service")" which is available on Windows XP, Server 2003 and above. This will allow you to copy files even when they are in use.
I have found a... | Do a Google on HoboCopy. It is an open source backup tool for windows that can backup files that are in use using Windows Volume Shadow Service. | Reading files in use and system files on Windows XP & Vista using .NET | [
"",
"c#",
".net",
"windows",
""
] |
Has anybody out there used the [SWIG](http://www.swig.org/exec.html) library with C#? If you have, what pitfalls did you find and what is the best way to use the library? I am thinking about using it as a wrapper for a program that was written in C and I want to wrap the header files where I can use them in my .NET app... | I think the mistake the earlier posters did was read the docs and not look at the examples.
A few hours ago I needed to interface some C++ classes to C#. I looked in my Swig dir (I already had it for other work), found the directory `Examples/csharp/class`, browsed the code, loaded the solution, grokked it, copied it,... | For my last project, here's the entire C# SWIG configuration file:
```
%module mdProject
%{
#include "mdProject.h"
%}
```
I compiled it in SWIG with:
```
swig -csharp -c++ -I../../Include mdProject.i
```
This generated a Project.cxx which I compiled and linked directly into the 'main' DLL, so I didn't need a secon... | What are the best practices when using SWIG with C#? | [
"",
"c#",
"c",
"swig",
""
] |
I want to delete foo() if foo() isn't called from anywhere. | [Gendarme](http://www.mono-project.com/Gendarme) will detect private methods with no upstream callers. It is available cross platform, and the latest version handles "[AvoidUncalledPrivateCodeRule](http://www.mono-project.com/Gendarme.Rules.Performance)".
[FxCop](http://msdn.microsoft.com/en-us/library/bb429476(VS.80)... | [NDepend](http://www.ndepend.com) will also report on potentially unused code. | Is there a tool for finding unreferenced functions (dead, obsolete code) in a C# app? | [
"",
"c#",
".net",
"code-analysis",
""
] |
In the Full .NET framework you can use the Color.FromArgb() method to create a new color with alpha blending, like this:
```
Color blended = Color.FromArgb(alpha, color);
```
or
```
Color blended = Color.FromArgb(alpha, red, green , blue);
```
However in the Compact Framework (2.0 specifically), neither of those me... | Apparently, it's not quite that simple, but [still possible](http://blogs.msdn.com/chrislorton/archive/2006/04/07/570649.aspx), if you have Windows Mobile 5.0 or newer. | There is a [codeplex site](http://www.codeplex.com/alphamobilecontrols) out there that seems to do the heavy lifting of com interop for you: | Alpha blending colors in .NET Compact Framework 2.0 | [
"",
"c#",
".net",
"graphics",
"compact-framework",
""
] |
What are some reasons why PHP would force errors to show, no matter what you tell it to disable?
I have tried
```
error_reporting(0);
ini_set('display_errors', 0);
```
with no luck. | Note the caveat in the manual at <http://uk.php.net/error_reporting>:
> > Most of E\_STRICT errors are evaluated at the compile time thus such errors are not reported in the file where error\_reporting is enhanced to include E\_STRICT errors (and vice versa).
If your underlying system is configured to report E\_STRIC... | To prevent errors from displaying you can
* Write in a .htaccess: *php\_flag display\_errors 0*
* Split your code in separate modules where the
main (parent) PHP file only sets the
error\_logging and then include() the
other files. | What are the reasons why PHP would echo errors, even with error_reporting(0)? | [
"",
"php",
"error-reporting",
"ini-set",
""
] |
I need to get the first and last day of a month in the format YYYY-MM-DD given only the month and year. Is there a good, easy way to do this? | ```
$first = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year));
$last = date('Y-m-t', mktime(0, 0, 0, $month, 1, $year));
```
See [date()](https://www.php.net/date) in PHP documentation. | First day is always YYYY-MM-01, isn't it? Example: `date("Y-M-d", mktime(0, 0, 0, 8, 1, 2008))`
Last day is the previous day of the next month's first day:
```
$date = new DateTime("2008-09-01");
$date->modify("-1 day");
echo $date->format("Y-m-d");
``` | In PHP, is there an easy way to get the first and last date of a month? | [
"",
"php",
""
] |
I have a C# singleton class that multiple classes use. Is access through `Instance` to the `Toggle()` method thread-safe? If yes, by what assumptions, rules, etc. If no, why *and* how can I fix it?
```
public class MyClass
{
private static readonly MyClass instance = new MyClass();
public static MyClass Insta... | > Is access through 'Instance' to the 'Toggle()' class threadsafe? If yes, by what assumptions, rules, etc. If no, why and how can I fix it?
No, it's not threadsafe.
Basically, both threads can run the `Toggle` function at the same time, so this could happen
```
// thread 1 is running this code
if(value == 0... | The original impplementation is not thread safe, as Ben points out
A simple way to make it thread safe is to introduce a lock statement. Eg. like this:
```
public class MyClass
{
private Object thisLock = new Object();
private static readonly MyClass instance = new MyClass();
public static MyClass Instanc... | Thread-safe use of a singleton's members | [
"",
"c#",
".net",
"multithreading",
"singleton",
"thread-safety",
""
] |
How can I set the cookies in my `PHP apps` as `HttpOnly cookies`? | * For **your cookies**, see this answer.
* For **PHP's own session cookie** (`PHPSESSID`, by default), see [@richie's answer](https://stackoverflow.com/a/8726269/1820)
The [`setcookie()`](http://php.net/manual/en/function.setcookie.php) and [`setrawcookie()`](http://php.net/manual/en/function.setrawcookie.php) functio... | For PHP's own session cookies on Apache:
add this to your Apache configuration or `.htaccess`
```
<IfModule php5_module>
php_flag session.cookie_httponly on
</IfModule>
```
This can also be set within a script, as long as it is called before `session_start()`.
```
ini_set( 'session.cookie_httponly', 1 );
``` | How do you set up use HttpOnly cookies in PHP | [
"",
"php",
"security",
"cookies",
"xss",
"httponly",
""
] |
I have an activity that has a TabHost containing a set of TabSpecs each with a listview containing the items to be displayed by the tab. When each TabSpec is created, I set an icon to be displayed in the tab header.
The TabSpecs are created in this way within a `setupTabs()` method which loops to create the appropriat... | The short answer is, you're not missing anything. The Android SDK doesn't provide a direct method to change the indicator of a `TabHost` after it's been created. The `TabSpec` is only used to build the tab, so changing the `TabSpec` after the fact will have no effect.
I think there's a workaround, though. Call `mTabs.... | Just to confirm dominics answer, here's his solution in code (that actually works):
```
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
if (TAB_MAP.equals(tabId)) {
ImageView iv = (ImageView) tabHost.getTabWidget().getChildAt(0).findViewById(... | Updating Android Tab Icons | [
"",
"java",
"android",
"android-tabhost",
""
] |
I'm trying to use `jQuery` to format code blocks, specifically to add a `<pre>` tag inside the `<code>` tag:
```
$(document).ready(function() {
$("code").wrapInner("<pre></pre>");
});
```
Firefox applies the formatting correctly, but IE puts the entire code block on one line. If I add an alert
```
alert($("code")... | That's the difference between [block and inline](http://www.w3.org/TR/html4/struct/global.html#h-7.5.3) elements. [`pre` is a block level element](http://www.w3.org/TR/html4/sgml/dtd.html#block). It's not legal to put it inside a `code` tag, which [can only contain inline content](http://www.w3.org/TR/html4/struct/text... | Btw I don't know if it is related but pre tags inside code tags will not validate in strict mode. | How do I add a pre tag inside a code tag with jQuery? | [
"",
"javascript",
"jquery",
"html",
"internet-explorer",
""
] |
Specifically, is the following legal C++?
```
class A{};
void foo(A*);
void bar(const A&);
int main(void)
{
foo(&A()); // 1
bar(A()); // 2
}
```
It appears to work correctly, but that doesn't mean it's necessarily legal. Is it?
*Edit - changed `A&` to `const A&`* | 1: Taking the address of a temporary is not allowed. Visual C++ allows it as a language extension (language extensions are on by default).
2: This is perfectly legal. | No, it's against the standard to pass a non-const reference to a temporary object. You can use a const reference:
```
class A{};
void bar(const A&);
int main(void)
{
bar(A()); // 2
}
```
So while some compliers will accept it, and it would work as long as don't use the memory after the semicolon, a conforming ... | Is it legal to pass a newly constructed object by reference to a function? | [
"",
"c++",
""
] |
Is there some way I can use URLs like:
*<http://www.blog.com/team-spirit/>*
instead of
*<http://www.blog.com/?p=122>*
in a Windows hosted PHP server? | This is how I did it with WordPress on IIS 6.0
<http://www.coderjournal.com/2008/02/url-rewriter-reverse-proxy-iis-wordpress/>
However it all depends on what version of IIS you are using. If you are lucky enough to use IIS 7.0 you don't really have to worry about pretty urls because everything is supported out of the... | [Isapi Rewrite Filter on CodePlex](http://www.codeplex.com/IIRF) - actively developed, free ("DonationWare"), open source. | How to make 'pretty urls' work in php hosted in IIS? | [
"",
"php",
"iis",
""
] |
I'd like to add a method to my existing server's CORBA interface. Will that require recompiling all clients?
I'm using TAO. | Recompilation of clients is not required (and should not be, regardless of the ORB that you use). As Adam indicated, lookups are done by operation name (a straight text comparison).
I've done what you're describing with our ACE/TAO-based system, and encountered no issues (servers were in ACE/TAO C++, clients were ACE/... | Assuming that the clients and servers are communicating via IIOP, no recompilation is required. An IIOP message contains the name of the interface, the name of the method, and the parameters. If none of those things have changed, then everything should remain compatible. Adding another method to the interface won't cha... | Changing a CORBA interface without recompiling | [
"",
"c++",
"corba",
"idl",
"tao",
""
] |
In the transition to newforms admin I'm having difficulty figuring out how specify core=False for ImageFields.
I get the following error:
```
TypeError: __init__() got an unexpected keyword argument 'core'
```
[Edit] However, by just removing the core argument I get a "This field is required." error in the admin int... | To get rid of "This field is required," you need to make it not required, by using blank=True (and possibly null=True as well, if it's not a CharField). | The `core` attribute isn't used anymore.
From [Brian Rosner's Blog](http://oebfare.com/blog/2008/jul/20/newforms-admin-migration-and-screencast/):
> You can safely just remove any and all `core` arguments. They are no longer used. *newforms-admin* now provides a nice delete checkbox for exisiting instances in inlines... | Django ImageField core=False in newforms admin | [
"",
"python",
"django",
"django-models",
""
] |
The XML Schema Part 2 specifies that an instance of a datatype that is defined as boolean can have the following legal literals {true, false, 1, 0}.
The following XML, for example, when deserialized, sets the boolean property "Emulate" to `true`.
```
<root>
<emulate>1</emulate>
</root>
```
However, when I seriali... | You can implement IXmlSerializable which will allow you to alter the serialized output of your class however you want. This will entail creating the 3 methods GetSchema(), ReadXml(XmlReader r) and WriteXml(XmlWriter r). When you implement the interface, these methods are called instead of .NET trying to serialize the o... | You can also do this by using some XmlSerializer attribute black magic:
```
[XmlIgnore]
public bool MyValue { get; set; }
/// <summary>Get a value purely for serialization purposes</summary>
[XmlElement("MyValue")]
public string MyValueSerialize
{
get { return this.MyValue ? "1" : "0"; }
set { this.MyValue = ... | XML Serialize boolean as 0 and 1 | [
"",
"c#",
"xml",
"serialization",
"schema",
"constraints",
""
] |
I'm curious about people's approaches to using stored procedures in a database that is accessed by many applications. Specifically, do you tend to keep different sets of stored procedures for each application, do you try to use a shared set, or do you do a mix?
On the one hand, reuse of SPs allows for fewer changes wh... | It all depends on your abstraction strategy. Are the stored procedures treated as a discrete point of abstraction, or are they treated as just another part of the application that calls them.
The answer to that will tell you how to manage them. If they are a discrete abstraction, they can be shared, as if you need new... | Stored procedures should be created based on the data you intend to return, not the application making the request. If you have a stored procedure that is GetAllItems, it should return all of the items in the database. If one of the applications would like to get all of the items by category, create GetAllItemsByCatego... | Reuse of SQL stored procedures across applications | [
"",
"sql",
"architecture",
"stored-procedures",
"code-reuse",
""
] |
Has anyone encountered this oddity?
I'm checking for the existence of a number of directories in one of my unit tests. `is_dir` is reporting true (1) in spite of the folder not existing at the time it is called. The code looks like this (with a few extraneous intermediate vars to ease debugging):
```
foreach($userfol... | I don't think this would cause your problem, but $path does have the trailing slash, correct? | For what its worth, `is_readable` can be used as a work around. | php is_dir returns true for non-existent folder | [
"",
"php",
""
] |
At the beginning of all my executable Python scripts I put the [shebang](http://en.wikipedia.org/wiki/Shebang_(Unix)) line:
```
#!/usr/bin/env python
```
I'm running these scripts on a system where `env python` yields a Python 2.2 environment. My scripts quickly fail because I have a manual check for a compatible Pyt... | "env" simply executes the first thing it finds in the PATH env var. To switch to different python, prepend the directory for that python's executable to the path before invoking your script. | Pretty hackish solution - if your check fails, use this function (which probably could be significantly improved) to determine the best interpreter available, determine if it is acceptable, and if so relaunch your script with os.system or something similar and your sys.argv using the new interpreter.
```
import os
imp... | Python deployment and /usr/bin/env portability | [
"",
"python",
"executable",
"environment",
"shebang",
""
] |
What do `*args` and `**kwargs` mean in these function definitions?
```
def foo(x, y, *args):
pass
def bar(x, y, **kwargs):
pass
```
---
See [What do \*\* (double star/asterisk) and \* (star/asterisk) mean in a function call?](https://stackoverflow.com/questions/2921847) for the complementary question about ... | The `*args` and `**kwargs` are common idioms to allow an arbitrary number of arguments to functions, as described in the section [more on defining functions](http://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions) in the Python tutorial.
The `*args` will give you all positional arguments [as a t... | It's also worth noting that you can use `*` and `**` when calling functions as well. This is a shortcut that allows you to pass multiple arguments to a function directly using either a list/tuple or a dictionary. For example, if you have the following function:
```
def foo(x,y,z):
print("x=" + str(x))
print("y... | What does ** (double star/asterisk) and * (star/asterisk) do for parameters? | [
"",
"python",
"syntax",
"parameter-passing",
"variadic-functions",
"argument-unpacking",
""
] |
I'm using [jQuery](http://jquery.com/) and [SimpleModal](http://www.ericmmartin.com/projects/simplemodal/) in an ASP.Net project to make some nice dialogs for a web app. Unfortunately, any buttons in a modal dialog can no longer execute their postbacks, which is not really acceptable.
There is one source I've found wi... | Both of you were on the right track. What I realized is that SimpleModal appends the dialog to the body, which is outside ASP.Net's `<form>`, which breaks the functionality, since it can't find the elements.
To fix it, I just modified the SimpleModal source to append eveything to `'form'` instead of `'body'`. When I c... | All standard ASP.NET postbacks work by calling a \_\_doPostBack javascript method on the page. That function submits the form (ASP.NET only really likes one form per page) which includes some hidden input field in which all the viewstate and other goodness lives.
On the face of it I can't see anything in SimpalModal t... | SimpleModal breaks ASP.Net Postbacks | [
"",
"asp.net",
"javascript",
"jquery",
"postback",
"simplemodal",
""
] |
I would like to use `as` and `is` as members of an enumeration. I know that this is possible in VB.NET to write it like this:
```
Public Enum Test
[as] = 1
[is] = 2
End Enum
```
How do I write the equivalent statement in C#?
The following code does not compile:
```
public enum Test
{
as = 1,
is = 2
}... | Prefixing reserved words in C# is done with @.
```
public enum Test
{
@as = 1,
@is = 2
}
``` | You will need to prefix them with the @ symbol to use them. Here is the [msdn page](https://msdn.microsoft.com/en-us/library/x53a06bb.aspx) that explains it. | Reserved Keyword in Enumeration in C# | [
"",
"c#",
"vb.net",
".net-2.0",
""
] |
More out of interest than anything else, but can you compile a DirectX app under linux?
Obviously there's no official SDK, but I was thinking it might be possible with wine.
Presumably wine has an implementation of the DirectX interface in order to run games? Is it possible to link against that? (edit: This is called... | I've had some luck with this. I've managed to compile [this simple Direct3D example](http://www.directxtutorial.com/Tutorial9/B-Direct3DBasics/dx9B5.aspx).
I used winelib for this (wine-dev package on Ubuntu). Thanks to [alastair](https://stackoverflow.com/users/9554/alastair) for pointing me to winelib.
I modified t... | If this is not about porting but creating, you should really consider OpenGL as this API is as powerful as DirectX and much easier to port to Mac or Linux.
I don't know your requirements so better mention it. | Is it possible to develop DirectX apps in Linux? | [
"",
"c++",
"linux",
"directx",
"mingw",
"wine",
""
] |
What is the best way to create a fixed width file in C#. I have a bunch of fields with lengths to write out. Say 20,80.10,2 etc all left aligned. Is there an easy way to do this? | You can use string.Format to easily pad a value with spaces
e.g.
```
string a = String.Format("|{0,5}|{1,5}|{2,5}", 1, 20, 300);
string b = String.Format("|{0,-5}|{1,-5}|{2,-5}", 1, 20, 300);
// 'a' will be equal to "| 1| 20| 300|"
// 'b' will be equal to "|1 |20 |300 |"
``` | This is a system I made for a configurable Fixed Width file writing module. It's configured with an XML file, the relevant part looking like this:
```
<WriteFixedWidth Table="orders" StartAt="1" Output="Return">
<Position Start="1" Length="17" Name="Unique Identifier"/>
<Position Start="18" Length="3" Name="Error ... | Creating a fixed width file in C# | [
"",
"c#",
""
] |
Would it not make sense to support a set of languages (Java, Python, Ruby, etc.) by way of a standardized virtual machine hosted in the browser rather than requiring the use of a specialized language -- really, a specialized paradigm -- for client scripting only?
To clarify the suggestion, a web page would contain byt... | Well, yes. Certainly if we had a time machine, going back and ensuring a lot of the Javascript features were designed differently would be a major pastime (that, and ensuring the people who designed IE's CSS engine never went into IT). But it's not going to happen, and we're stuck with it now.
I suspect, in time, it w... | I think JavaScript is a good language, but I would love to have a choice when developing client-side web applications. For legacy reasons we're stuck with JavaScript, but there are projects and ideas looking for changing that scenario:
1. [Google Native Client](http://code.google.com/p/nativeclient/): technology for r... | Why JavaScript rather than a standard browser virtual machine? | [
"",
"javascript",
""
] |
Does anyone know how to print a barcode to the Intermec PB20 bluetooth printer from a Windows Compact Framework application? We are currently using the Intermec LinePrinter API but have been unable to find a way to print a barcode.
| Thank you all for your thoughts. Printing directly to the serial port is likely the most flexible method. In this case we didn't want to replicate all of the work that was already built into the Intermec dll for handling the port, printer errors, etc. We were able to get this working by sending the printer the appropri... | Last time I had to print Barcode (despite the printer or framework) I resorted to use a True Type font with the Barcode I needed. (In my case was EAN-13 something), an european barcode.
There are fonts where you simply write numbers (and/or letters when supported) and you get a perfect barcode any scanner can read :)
... | Print a barcode to a Intermec PB20 via the LinePrinter API | [
"",
"c#",
"windows-mobile",
""
] |
I've found [an article](http://blogs.msdn.com/priozersk/archive/2007/08/06/implementing-mvc-pattern-in-net-cf-applications-part-1.aspx) on this subject by a Microsoft employee, but has anyone implemented a more robust framework for this? Is there a lightweight framework for WinForms that could be ported easily? I'd lik... | I personally think that the Mobile Software Factory doesn't hold much joy for CF.
We still use one part of it (EventBroker) at work and I'd like to even remove that part if possible (as it doesn't support generic events and you have to cast the arguments into their strong types from EventArgs). A sister project at work... | Neither of you (davidg or Kevin Pang) paid attention to the fact that he's interested in *WinForms*, not *Web Forms*. He wants a framework that pushes the Model-View-Controller design pattern (davidg, MVC isn't just the name of an ASP.NET framework) in a WinForms project using the .NET Compact Framework. He asked his q... | Compact Framework - Is there an MVC framework/library available? | [
"",
"c#",
"model-view-controller",
"windows-mobile",
"compact-framework",
"design-patterns",
""
] |
I'm just getting into creating some WCF services, but I have a requirement to make them backward compatible for legacy (.NET 1.1 and 2.0) client applications.
I've managed to get the services to run correctly for 3.0 and greater clients, but when I publish the services using a basicHttpBinding endpoint (which I believ... | OK, we needed to resolve this issue in the short term, and so we came up with the idea of a "interop", or compatibility layer.
Baiscally, all we did was added a traditional ASMX web service to the project, and called the WCF service from that using native WCF calls. We were then able to return the appropriate types ba... | Ah, this is killing me! I did this at work about 3 months ago, and now I can't remember all the details.
I do remember, however, that you need basicHttpBinding, and you can't use the new serializer (which is the default); you have to use the "old" XmlSerializer.
Unfortunately, I don't work at the place where I did th... | WCF Service - Backward compatibility issue | [
"",
"c#",
".net",
"wcf",
"web-services",
"backwards-compatibility",
""
] |
I have a script that checks responses from HTTP servers using the PEAR HTTP classes. However, I've recently found that the script fails on FTP servers (and probably anything that's not HTTP or HTTPS). I tried Google, but didn't see any scripts or code that returned the server status code from servers other than HTTP se... | HTTP works slightly differently than FTP though unfortunately. Although both may look the same in your browser, HTTP works off the basis of URI (i.e. to access resource A, you have an identifier which tells you how to access that).
FTP is very old school server driven. Even anonymous FTP is a bit of a hack, since you ... | Wouldn't it be simpler to use the built-in PHP FTP\* functionality than trying to roll your own? If the URI is coming from a source outside your control, you would need to check the protocal definition (http:// or ftp://, etc) in order to determine which functionality to use, but that is fairly trivial. If there is now... | Checking FTP status codes with a PHP script | [
"",
"php",
"http",
"ftp",
"pear",
"server-response",
""
] |
I would like to reload an `<iframe>` using JavaScript. The best way I found until now was set the iframe’s `src` attribute to itself, but this isn’t very clean. Any ideas? | ```
document.getElementById('some_frame_id').contentWindow.location.reload();
```
be careful, in Firefox, `window.frames[]` cannot be indexed by id, but by name or index | ```
document.getElementById('iframeid').src = document.getElementById('iframeid').src
```
It will reload the `iframe`, even across domains!
Tested with IE7/8, Firefox and Chrome.
**Note:** As mentioned by @user85461, this approach **doesn't work** if the iframe src URL has a hash in it (e.g. `http://example.com/#some... | What’s the best way to reload / refresh an iframe? | [
"",
"javascript",
"iframe",
""
] |
I have an application that works pretty well in Ubuntu, Windows and the Xandros that come with the Asus EeePC.
Now we are moving to the [Acer Aspire One](http://en.wikipedia.org/wiki/Aspire_One) but I'm having a lot of trouble making php-gtk to compile under the Fedora-like (Linpus Linux Lite) Linux that come with it. | Hi Guys well I finally got this thing to work the basic workflow was this:
```
#!/bin/bash
sudo yum install yum-utils
#We don't want to update the main gtk2 by mistake so we download them
#manually and install with no-deps[1](and forced because gtk version
#version of AA1 and the gtk2-devel aren't compatible).
sudo yu... | I managed to get all components needed for Phoronix test suite installed on Fedora but still have one issue.
```
# phoronix-test-suite gui
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
pwd: error retrieving current directory: getcwd: cannot access p... | How to install php-gtk in the Acer Aspire One? | [
"",
"php",
"fedora",
"php-gtk",
""
] |
It's been mentioned to me that I'll be the sole developer behind a large new system. Among other things I'll be designing a UI and database schema.
I'm sure I'll receive some guidance, but I'd like to be able to knock their socks off. What can I do in the meantime to prepare, and what will I need to keep in mind when ... | Do you know much about OOP? If so, look into Spring and Hibernate to keep your implementation clean and [orthogonal](http://codebetter.com/blogs/jeremy.miller/archive/2007/01/08/Orthogonal-Code.aspx). If you get that, you should find TDD a good way to keep your design compact and lean, especially since you have "automa... | This sounds very much like my first job. Straight out of university, I was asked to design the database and business logic layer, while other people would take care of the UI. Meanwhile the boss was looking over my shoulder, unwilling to let go of what used to be his baby and was now mine, and poking his finger in it. ... | How do you begin designing a large system? | [
"",
"java",
"oop",
"architecture",
""
] |
Does anybody know a "technique" to discover memory leaks caused by smart pointers? I am currently working on a large project written in **C++** that heavily uses smart pointers with reference counting. Obviously we have some memory leaks caused by smart pointers, that are still referenced somewhere in the code, so that... | Note that one source of leaks with **reference-counting smart pointers** are pointers with **circular dependancies**. For example, A have a smart pointer to B, and B have a smart pointer to A. Neither A nor B will be destroyed. You will have to find, and then break the dependancies.
If possible, use boost smart pointe... | The way I do it is simply:
- on every AddRef() record call-stack,
- matching Release() removes it.
This way at the end of the program I'm left with AddRefs() without maching Releases. No need to match pairs, | Find memory leaks caused by smart pointers | [
"",
"c++",
"pointers",
"memory-leaks",
"smart-pointers",
""
] |
The company I just started working for is using [Stripes](http://www.stripesframework.org/display/stripes/Home) for parts of its web page development these days, and while it seems to be a nice enough web framework it no one really uses it-- it is almost non existent on the 'net. It's not even first in it's [google sea... | I've never used (or even heard of) Stripes.
Regardless, there's a book from [The Pragmatic Bookshelf](http://www.pragprog.com/) called [Stripes: ...and Java web development is fun again](http://www.pragprog.com/titles/fdstr/stripes) that may be worth checking out. You could also check out the Stripes [mailing list arc... | I recommend checking out the book referenced by jko:
> a book from The Pragmatic Bookshelf called [Stripes: ...and Java web development is fun again](http://www.pragprog.com/titles/fdstr/stripes)
Whilst still in 'beta' the book covers everything very well.
Another good place to start is [this ONJava article](http://... | Good Stripes tutorials / examples? | [
"",
"java",
"stripes",
""
] |
I am familiar with nunit for unit testing of the business layer however I am looking now to automate the test of the win forms gui layer.
I have seen [watin](http://watin.sourceforge.net/) and the watin recorder for automating tests on web application by accessing the controls and automating them. However I am struggl... | Check out <http://www.codeplex.com/white> and <http://nunitforms.sourceforge.net/>. We've used the White project with success.
*Same Answer to a previous question*
**Edit**
The White project has moved, and is now located on [GitHub](https://github.com/TestStack/White) as part of TestStack. | [AutomatedQA's TestComplete](http://www.automatedqa.com/products/testcomplete/index.asp) is a good testing application to automate GUI testing. It supports more than just Windows Forms also, so you can reuse it for other applications. It is not open source and this is the best that I have found. I haven't seen an open ... | Is there any way to automate windows forms testing? | [
"",
"c#",
".net",
"vb.net",
"winforms",
"automated-tests",
""
] |
I am trying to find a generic way of accessing a set of containers. I have a standard vector and list in addition to another custom list.
The custom list defines an iterator;
```
class Iterator: public std::iterator<std::forward_iterator_tag, T> {
// ...
}
Iterator begin() {
return (Iterator(root));
}
Itera... | Here are some articles you might find of interest
[Giving STL Iterators a Base Class](http://accu.org/index.php/journals/479)
[Type Erasure for C++ Iterators](http://thbecker.net/free_software_utilities/type_erasure_for_cpp_iterators/start_page.html)
[any\_iterator Class Reference](http://stlab.adobe.com/classadobe_... | Better late than never...
The latest issue of [C-Vu](http://accu.org/index.php/aboutus/aboutjournals) turned up and guess what was in it: That's right, iterators that do *exactly* what you wanted.
Unfortunately you need to become a member of the [ACCU](http://accu.org/) to view the magazine (the article references th... | Generic iterator | [
"",
"c++",
"generics",
"iteration",
"containers",
""
] |
I've been trying to wrap my head around how threads work in Python, and it's hard to find good information on how they operate. I may just be missing a link or something, but it seems like the official documentation isn't very thorough on the subject, and I haven't been able to find a good write-up.
From what I can te... | Yes, because of the Global Interpreter Lock (GIL) there can only run one thread at a time. Here are some links with some insights about this:
* <http://www.artima.com/weblogs/viewpost.jsp?thread=214235>
* <http://smoothspan.wordpress.com/2007/09/14/guido-is-right-to-leave-the-gil-in-python-not-for-multicore-but-for-ut... | Python's a fairly easy language to thread in, but there are caveats. The biggest thing you need to know about is the Global Interpreter Lock. This allows only one thread to access the interpreter. This means two things: 1) you rarely ever find yourself using a lock statement in python and 2) if you want to take advanta... | How do threads work in Python, and what are common Python-threading specific pitfalls? | [
"",
"python",
"multithreading",
""
] |
I have a string that has some Environment.Newline in it. I'd like to strip those from the string and instead, replace the Newline with something like a comma.
What would be, in your opinion, the best way to do this using C#.NET 2.0? | Why not:
```
string s = "foobar\ngork";
string v = s.Replace(Environment.NewLine,",");
System.Console.WriteLine(v);
``` | Like this:
```
string s = "hello\nworld";
s = s.Replace(Environment.NewLine, ",");
``` | What would be the fastest way to remove Newlines from a String in C#? | [
"",
"c#",
".net",
"string",
"replace",
""
] |
How do you automatically set the focus to a textbox when a web page loads?
Is there an HTML tag to do it or does it have to be done via Javascript? | If you're using jquery:
```
$(function() {
$("#Box1").focus();
});
```
or prototype:
```
Event.observe(window, 'load', function() {
$("Box1").focus();
});
```
or plain javascript:
```
window.onload = function() {
document.getElementById("Box1").focus();
};
```
though keep in mind that this will replace othe... | In HTML there's an [`autofocus` attribute](http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#autofocusing-a-form-control) to all form fields. There's a good tutorial on it in [Dive Into HTML 5](http://diveintohtml5.info/forms.html#autofocus). Unfortunately it's currently not [supported](http://www.... | How do you automatically set the focus to a textbox when a web page loads? | [
"",
"javascript",
"html",
""
] |
In the STL almost all containers have an erase function. The question I have is in a vector, the erase function returns an iterator pointing to the next element in the vector. The map container does not do this. Instead it returns a void. Anyone know why there is this inconsistancy? | See <http://www.sgi.com/tech/stl/Map.html>
> Map has the important property that
> inserting a new element into a map
> does not invalidate iterators that
> point to existing elements. Erasing an
> element from a map also does not
> invalidate any iterators, except, of
> course, for iterators that actually
> point to ... | `erase` returns an `iterator` in C++11. This is due to [defect report 130](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2728.html#130):
> Table 67 (23.1.1) says that container::erase(iterator) returns an iterator. Table 69 (23.1.2) says that in addition to this requirement, associative containers also say ... | STL vector vs map erase | [
"",
"c++",
"stl",
""
] |
I'm a longtime Java programmer working on a PHP project, and I'm trying to get PHPUnit up and working. When unit testing in Java, it's common to put test case classes and regular classes into separate directories, like this -
```
/src
MyClass.java
/test
MyClassTest.java
```
and so on.
When unit testing with... | I think it's a good idea to keep your files separate. I normally use a folder structure like this:
```
/myapp/src/ <- my classes
/myapp/tests/ <- my tests for the classes
/myapp/public/ <- document root
```
In your case, for including the class in your test file, why not just pass the the whole path... | You need to modify PHP's include\_path so that it knows where to find MyClass.php when you `include()` it in your unit test.
You could have something like this at the top of your test file (preceding your include):
```
set_include_path(get_include_path() . PATH_SEPARATOR . "../src");
```
This appends your `src` dire... | Directory layout for PHPUnit tests? | [
"",
"php",
"unit-testing",
"phpunit",
""
] |
Does anyone know of an open source module or a good method for handling application errors and e-mailing them to an admin and/or saving to a database? | [ELMAH](http://code.google.com/p/elmah/) is a great drop-in tool for this. DLL in the bin directory, and some markup to add to the web.config and you're done. | [log4net](http://logging.apache.org/log4net/index.html) can save errors to a database or send emails. We use this at my job (despite the fact it caused Jeff Atwood much stress in the SO beta). Catch the errors in the global.asax page in the Application Error method. | Error handling reporting methods with ASP.NET 2.0 / C# | [
"",
"c#",
"asp.net",
""
] |
This is a question I asked on another forum which received some decent answers, but I wanted to see if anyone here has more insight.
The problem is that you have one of your pages in a web application timing out when it gets to a stored procedure call, so you use Sql Profiler, or your application trace logs, to find t... | This is what I've learned so far from my research.
.NET sends in connection settings that are not the same as what you get when you log in to management studio. Here is what you see if you sniff the connection with Sql Profiler:
```
-- network protocol: TCP/IP
set quoted_identifier off
set arithabort off
set nu... | I've had similar problems. Try setting the with "WITH RECOMPILE" option on the sproc create to force the system to recompute the execution plan each time it is called. Sometimes the Query processor gets confused in complex stored procedures with lots of branching or case statements and just pulls a really sub-optimal e... | Query times out from web app but runs fine from management studio | [
"",
"sql",
"sql-server",
"sql-server-2005",
""
] |
I have a Monthly Status database view I need to build a report based on. The data in the view looks something like this:
```
Category | Revenue | Yearh | Month
Bikes 10 000 2008 1
Bikes 12 000 2008 2
Bikes 12 000 2008 3
Bikes 15 000 2008 1
Bikes ... | The Case Statement is my best sql friend. You also need a table for time to generate your 0 rev in both months.
Assumptions are based on the availability of following tables:
> sales: Category | Revenue | Yearh |
> Month
and
> tm: Year | Month (populated with all
> dates required for reporting)
Example 1 without e... | @Christian -- markdown editor -- UGH; especially when the preview and the final version of your post disagree...
@Christian -- full outer join -- the full outer join is overruled by the fact that there are references to SP1 in the WHERE clause, and the WHERE clause is applied after the JOIN. To do a full outer join wit... | SQL query to compare product sales by month | [
"",
"sql",
"sql-server",
"sql-server-2005",
"reporting",
""
] |
If you are working in PHP (or I guess any programming language) and using subversion as your source control, is there a way to take your project (for example):
> C:\Projects\test\.svn
> C:\Projects\test\docs\
> C:\Projects\test\faq.php
> C:\Projects\test\guestbook.php
> C:\Projects\test\index.php
> C:\Projec... | If you use TortoiseSVN, you can use the export feature to automatically strip out all of the .svn files. I think other svn things have the same feature.
Right click the root project folder, then select `TortoiseSVN > Export`, and tell it where you want the `.svn` free directory. | Copy all the files manually or using your existing method for the first time. Then, since I take it you're on a Windows platform, install [SyncToy](http://www.microsoft.com/downloads/details.aspx?FamilyId=E0FC1154-C975-4814-9649-CCE41AF06EB7&displaylang=en) and configure it in the [subscribe method](http://en.wikipedia... | Making a production build of a PHP project with Subversion | [
"",
"php",
"svn",
"scripting",
"tortoisesvn",
"build-process",
""
] |
I'm really beginning to understand what people mean when they say that C++'s error messages are pretty terrible in regards to templates. I've seen horrendously long errors for things as simple as a function not matching its prototype.
Are there any tricks to deciphering these errors?
EDIT: I'm using both gcc and MSVC... | You can try the following tool to make things more sane:
<http://www.bdsoft.com/tools/stlfilt.html> | I sure as hell can't. Small errors explode into pages and pages of unreadable junk. Usually early in the morning, before coffee. :(
My only advice is to take a deep breath, start at the top and try and parse the important pieces of information. (I know, easier said than done, right?). | Deciphering C++ template error messages | [
"",
"c++",
"templates",
"compiler-errors",
""
] |
How can I set, clear, and toggle a bit? | ### Setting a bit
Use the bitwise OR operator (`|`) to set `n`th bit of `number` to `1`.
```
// Can be whatever unsigned integer type you want, but
// it's important to use the same type everywhere to avoid
// performance issues caused by mixing integer types.
typedef unsigned long Uint;
// In C++, this can be templ... | Using the Standard C++ Library: [`std::bitset<N>`](http://en.cppreference.com/w/cpp/utility/bitset).
Or the [Boost](http://en.wikipedia.org/wiki/Boost_%28C%2B%2B_libraries%29) version: [`boost::dynamic_bitset`](http://www.boost.org/doc/libs/release/libs/dynamic_bitset/dynamic_bitset.html).
There isn't any need to rol... | How to set, clear, and toggle a single bit | [
"",
"c++",
"c",
"bit-manipulation",
"bitwise-operators",
""
] |
If one wants to paginate results from a data source that supports pagination we have to go to a process of:
1. defining the page size - that is the number of results to show per page;
2. fetch each page requested by the user using an offset = page number (0 based) \* page size
3. show the results of the fetched page.
... | There are a few schools of thought o this.
1. data gets updated let it be
2. You could implement some sort of caching method that will hold the
entire result set (This might not be
an option if working with really
large Datasets)
3. You could do a comparison on each page operation and notify the
user if th... | If the updates you are concerned with are primarily new insertions (for example, StackOverflow itself seems to suffer from this problem when paging through questions and new questions come in) one way to handle it is to capture a timestamp when you issue the first pagination query, and then limit the results of request... | Keep pagination repeatable if change operations are performed | [
"",
"sql",
"pagination",
""
] |
I've opened an old workspace that is a library and its test harness. It used to work fine but now doesn't and older versions of the code don't work either with the same errors. I've tried recreating the project and that causes the same errors too. Nothing seems out of order in project settings and the code generated wo... | One possibility lies with Win32 ANSI/Unicode "name-mangling", which turns the symbol `GetMessage` into either `GetMessageA` or `GetMessageW`. There are three possibilities:
1. Windows.h hasn't been loaded, so `GetMessage` stays `GetMessage`
2. Windows.h was loaded with symbols set for ANSI, so `GetMessage` becomes `Ge... | @Curt: I think you came the closest. I haven't tested this but I think I sort of gave the answer in my original question.
[GetMessage](http://msdn.microsoft.com/en-us/library/ms644936.aspx) is a define in Windows.h wrapped in a ifndef block to switch between Ansi (GetMessageA) and Unicode (GetMessageW). | Link issues (VC6) | [
"",
"c++",
"visual-c++",
"linker",
"visual-c++-6",
""
] |
I have created a UserControl that has a `ListView` in it. The ListView is publicly accessible though a property. When I put the UserControl in a form and try to design the `ListView` though the property, the `ListView` stays that way until I compile again and it reverts back to the default state.
How do I get my desig... | You need to decorate the ListView property with the DesignerSerializationVisibility attribute, like so:
```
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ListView MyListView { get { return this.listView1; } }
```
This tells the designer's code generator to output code for it. | [Fredrik](https://stackoverflow.com/questions/15716/design-problems-with-net-usercontrol#15803) is right, basically, when you need to enable the designer to persist the property to page so it can be instantiated at run time. There is only one way to do this, and that is to write its values to the ASPX page, which is th... | Design problems with .Net UserControl | [
"",
"c#",
"user-controls",
".net-2.0",
""
] |
Has anybody used the MS Project Gantt chart control in C#?
If yes, can you share some resources regarding this? | You could also check [Gantt Chart Library](http://DlhSoft.com/GanttChart) for WPF or Windows Forms, they do not require Microsoft Project installed on the client computer, but provide similar UI for project and related Gantt Charts. | Try these links for a start.
<http://www.ilog.com/products/ganttnet/>
<http://www.netronic.com/products-for-developers/gantt-charts.html?gclid=COLdutasoZUCFQunQwodoWOPkw> | MS Project Gantt chart control usage in C# | [
"",
"c#",
".net-2.0",
"controls",
"ms-project",
"gantt-chart",
""
] |
Looking for an example that:
1. Launches an EXE
2. Waits for the EXE to finish.
3. Properly closes all the handles when the executable finishes. | Something like this:
```
STARTUPINFO info={sizeof(info)};
PROCESS_INFORMATION processInfo;
if (CreateProcess(path, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
{
WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
``` | There is an example at [<http://msdn.microsoft.com/en-us/library/ms682512(VS.85).aspx>](http://msdn.microsoft.com/en-us/library/ms682512(VS.85).aspx)
Just replace the `argv[1]` with your constant or variable containing the program.
```
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
void _tmain( int argc,... | How do I call ::CreateProcess in c++ to launch a Windows executable? | [
"",
"c++",
"windows",
"winapi",
""
] |
I want to be able to make an HTTP call updating some select boxes after a date is selected. I would like to be in control of updating the textbox so I know when there has been a "true" change (in the event the same date was selected). Ideally, I would call a function to pop-up the calendar and be able to evaluate the d... | JQuery's [datepicker](http://docs.jquery.com/UI/Datepicker) is an extremely flexible tool. With the ability to attach handlers prior to opening or after date selection, [themes](http://marcgrabanski.com/article/jquery-ui-datepicker-themes), range selection and a variety of other incredibly useful options, I've found th... | I've been playing with the jquery datePicker script - you should be able to do everything you need to with this. | What is the best calendar pop-up to populate a web form? | [
"",
"javascript",
"calendar",
""
] |
I've read that Lambda Expressions are an incredibly powerful addition to C#, yet I find myself mystified by them. How can they improve my life or make my code better? Can anyone point to a good resource for learning such expressions?
They seem cool as hell, but how do they relate to my day-to-day life as an asp.net de... | > : are lambda expressions useful for anything other than querying
Lamba expressions are nothing much other than a convenient way of writing a function 'in-line'.
So they're useful any place you wanted a bit of code which can be called as though it's a separate function but which is actually written inside its caller... | Lambdas bring functional programing to C#.
They are anonymous functions that can be passed as values to certain other functions. Used most in LINQ.
Here is a contrived example:
```
List<int> myInts = GetAll();
IEnumerable<int> evenNumbers = myInts.Where(x => x % 2 == 0);
```
Now when you foreach through evenNumbers ... | What is appliance and how to use lambda expressions? | [
"",
"c#",
"lambda",
""
] |
I have a .NET 2.0 Windows Forms application. Where is the best place the store user settings (considering Windows guidelines)?
Some people pointed to `Application.LocalUserAppDataPath`. However, that creates a folder structure like:
> C:\Documents and Settings\user\_name\Local Settings\Application
> Data\company\_nam... | I love using the built-in [Application Settings](http://msdn.microsoft.com/en-us/library/a65txexh.aspx). Then you have built in support for using the settings designer if you want at design-time, or at runtime to use:
```
// read setting
string setting1 = (string)Settings.Default["MySetting1"];
// save setting
Setting... | .NET applications have a built-in settings mechanism that is easy to use. The problem with it, in my opinion, is that it stores those settings off into a rather obscure directory and end users will not be able to find it. Moreover, just switching from debug to release build changes the location of this directory, meani... | What is the best way to store user settings for a .NET application? | [
"",
"c#",
".net",
""
] |
I have the following code:
```
$bind = new COM("LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local");
```
When I execute it from a command-prompt, it runs fine. When it runs under IIS/PHP/ISAPI, it barfs.
```
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `LDAP:/... | Since you're using Windows Authentication in IIS, you may have some security events in the Windows Event log. I would check the Event log for Security Events as well as Application Events and see if you're hitting any sort of permissions issues.
Also, since you're basically just communicating to AD via LDAP...you migh... | It seems to be working now.
I enabled "Trust this computer for delegation" for the computer object in Active Directory. Normally IIS cannot both authenticate you and then subsequently impersonate you across the network (in my case to a domain controller to query Active Directory) without the delegation trust enabled.
... | How To Read Active Directory Group Membership From PHP/IIS using COM? | [
"",
"php",
"iis",
"com",
"adsi",
""
] |
To make it short: hibernate doesn't support projections and query by example? I found this post:
The code is this:
```
User usr = new User();
usr.setCity = 'TEST';
getCurrentSession().createCriteria(User.class)
.setProjection( Projections.distinct( Projections.projectionList()
.add( Projections.property("name"), "nam... | Can I see your User class? This is just using restrictions below. I don't see why Restrictions would be really any different than Examples (I think null fields get ignored by default in examples though).
```
getCurrentSession().createCriteria(User.class)
.setProjection( Projections.distinct( Projections.projectionList... | The problem seems to happen when you have an alias the same name as the objects property. Hibernate seems to pick up the alias and use it in the sql. I found this documented [here](http://opensource.atlassian.com/projects/hibernate/browse/HHH-3371;jsessionid=aLJbC8zJhKhanJbr49?page=com.atlassian.jira.plugin.system.issu... | Hibernate Query By Example and Projections | [
"",
"java",
"hibernate",
"criteria",
"projection",
""
] |
I'm writing a Spring web application that requires users to login. My company has an Active Directory server that I'd like to make use of for this purpose. However, I'm having trouble using Spring Security to connect to the server.
I'm using Spring 2.5.5 and Spring Security 2.0.3, along with Java 1.6.
If I change the... | I had the same banging-my-head-against-the-wall experience you did, and ended up writing a custom authentication provider that does an LDAP query against the Active Directory server.
So my security-related beans are:
```
<beans:bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurity... | For reference, Spring Security 3.1 has an authentication provider [specifically for Active Directory](http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#ldap-active-directory). | How do you authenticate against an Active Directory server using Spring Security? | [
"",
"java",
"spring",
"active-directory",
"ldap",
""
] |
If I have 2 query sources how do I find ones that are in one that are not in the other?
example of join to find items in both:
```
var results = from item1 in qs1.Items
join item2 in qs2 on item1.field1 equals item2.field2
select item1;
```
So what would the linq code be to return the items in qs1 that are not... | Darren Kopp's [answer](https://stackoverflow.com/questions/50702/linq-how-do-you-do-a-query-for-items-in-one-query-source-that-are-not-in-anothe/50724#50724):
```
var excluded = items1.Except(items2);
```
is the best solution from a performance perspective.
*(NB: This true for at least regular LINQ, perhaps LINQ to ... | From [Marco Russo](http://programminglinq.com/blogs/marcorusso/archive/2008/01/14/the-not-in-clause-in-linq-to-sql.aspx)
```
NorthwindDataContext dc = new NorthwindDataContext();
dc.Log = Console.Out;
var query =
from c in dc.Customers
where !(from o in dc.Orders
select o.CustomerID)
.Co... | linq - how do you do a query for items in one query source that are not in another one? | [
"",
"c#",
".net",
"linq",
".net-3.5",
""
] |
ASP.NET 2.0 provides the `ClientScript.RegisterClientScriptBlock()` method for registering JavaScript in an ASP.NET Page.
The issue I'm having is passing the script when it's located in another directory. Specifically, the following syntax does not work:
```
ClientScript.RegisterClientScriptBlock(this.GetType(), "scr... | What you're after is:
```
ClientScript.RegisterClientScriptInclude(this.GetType(), "scriptName", "../dir/subdir/scriptName.js")
``` | use: ClientScript.RegisterClientScriptInclude(key, url); | How do I use RegisterClientScriptBlock to register JavaScript? | [
"",
"javascript",
"asp.net",
""
] |
I'm mainly a C# developer, but I'm currently working on a project in Python.
How can I represent the equivalent of an Enum in Python? | [Enums](https://docs.python.org/3/library/enum.html) have been added to Python 3.4 as described in [PEP 435](http://www.python.org/dev/peps/pep-0435/). It has also been [backported to 3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4](https://pypi.python.org/pypi/enum34) on pypi.
For more advanced Enum techniques try the [aenum l... | Before PEP 435, Python didn't have an equivalent but you could implement your own.
Myself, I like keeping it simple (I've seen some horribly complex examples on the net), something like this ...
```
class Animal:
DOG = 1
CAT = 2
x = Animal.DOG
```
---
In Python 3.4 ([PEP 435](http://www.python.org/dev/peps... | How can I represent an 'Enum' in Python? | [
"",
"python",
"python-3.x",
"enums",
""
] |
I would like to replicate this in python:
```
gvimdiff <(hg cat file.txt) file.txt
```
(hg cat file.txt outputs the most recently committed version of file.txt)
I know how to pipe the file to gvimdiff, but it won't accept another file:
```
$ hg cat file.txt | gvimdiff file.txt -
Too many edit arguments: "-"
```
Ge... | It can be done. As of Python 2.5, however, this mechanism is Linux-specific and not portable:
```
import subprocess
import sys
file = sys.argv[1]
p1 = subprocess.Popen(['hg', 'cat', file], stdout=subprocess.PIPE)
p2 = subprocess.Popen([
'gvimdiff',
'/proc/self/fd/%s' % p1.stdout.fileno(),
file])
p2.wait()... | There is also the commands module:
```
import commands
status, output = commands.getstatusoutput("gvimdiff <(hg cat file.txt) file.txt")
```
There is also the popen set of functions, if you want to actually grok the data from a command as it is running. | Redirect command to input of another in Python | [
"",
"python",
"bash",
"redirect",
"diff",
"vimdiff",
""
] |
The eval function is a powerful and easy way to dynamically generate code, so what are the caveats? | 1. Improper use of **eval** opens up your
code for injection attacks
2. **Debugging** can be more challenging
(no line numbers, etc.)
3. eval'd code executes slower (no opportunity to compile/cache eval'd code)
Edit: As @Jeff Walden points out in comments, #3 is less true today than it was in 2008. However, whil... | eval isn't always evil. There are times where it's perfectly appropriate.
However, eval is currently and historically massively over-used by people who don't know what they're doing. That includes people writing JavaScript tutorials, unfortunately, and in some cases this can indeed have security consequences - or, mor... | Why is using the JavaScript eval function a bad idea? | [
"",
"javascript",
"security",
"eval",
""
] |
What are the performance, security, or "other" implications of using the following form to declare a new class instance in PHP
```
<?php
$class_name = 'SomeClassName';
$object = new $class_name;
?>
```
This is a contrived example, but I've seen this form used in Factories (OOP) to avoid having a big if/switch sta... | One of the issues with the resolving at run time is that you make it really hard for the opcode caches (like APC). Still, for now, doing something like you describe in your question is a valid way if you need a certain amount of indirection when instanciating stuff.
As long as you don't do something like
```
$classna... | It looks you can still pass arguments to the constructor, here's my test code:
```
<?php
class Test {
function __construct($x) {
echo $x;
}
}
$class = 'Test';
$object = new $class('test'); // echoes "test"
?>
```
That is what you meant, right?
So the only other problem you mentioned and that I can... | Implications of Instantiating Objects with Dynamic Variables in PHP | [
"",
"php",
"performance",
"oop",
""
] |
As a classic `ASP developer` about once a year since `ASP.NET` came out I decide I really gotta buckle down and learn this fancy new `ASP.NET`. A few days in and messing with code-behinds and webforms and all this other stuff.
I decide the new fancy stuff is whack and go find something else to learn (`PHP and Ruby and... | For a classic ASP developer moving to ASP.NET MVC you are looking at learning a new language (C# or VB.NET), a new database layer (ADO.NET), and a new framework (ASP.NET MVC).
That's a lot of new technologies to wrap your head around all at once.
Also, I don't think it is so much that ASP.NET MVC is so much better th... | Not too experienced with Microsoft's web stack, so I can't speak to that.
But I will say I as a web developer I was pretty disappointed by CakePHP. What especially bothers me about it is that because it forces itself to be backward compatible with PHP4, therefore, it lacks much of the oop design and structure I am use... | How do the CakePHP and codeigniter frameworks compare to the ASP.NET MVC framework? | [
"",
"php",
"asp.net-mvc",
"cakephp",
"asp-classic",
""
] |
We have our own ORM we use here, and provide strongly typed wrappers for all of our db tables. We also allow weakly typed ad-hoc SQL to be executed, but these queries still go through the same class for getting values out of a data reader.
In tweaking that class to work with Oracle, we've come across an interesting qu... | I find it better to use null, instead of DB null.
The reason is because, as you said, you're separating yourself from the DB world.
It is generally good practice to check reference types to ensure they aren't null anyway. You're going to be checking for null for things other than DB data, and I find it is best to kee... | If you've written your own ORM, then I would say just use null, since you can use it however you want. I believe DBNull was originally used only to get around the fact that value types (int, DateTime, etc.) could not *be* null, so rather than return some value like zero or DateTime.Min, which would *imply* a null (bad,... | C# Database Access: DBNull vs null | [
"",
"c#",
"orm",
"null",
"dbnull",
""
] |
I understand how JS is run and I think I understand most of the DOM but I've no idea about animation. Does anybody here know of a good guide that can explain to me how it's done in Javascript?
In addition, should I even consider Javascript for animation? Should I instead be looking to learn flash? | Avoid flash, its a horrible requirement, uncrawlable by Google, unsopported by a bunch of browsers and systems (eg iPhone) and most importantly: it forces you to reinvent web standards (e.g. scroll bars and whatnot), Javascript on the other hand is easier to maintain and code for in the noscript case.
try [scriptaculo... | if your animation is simple, change colors over time, move from x to y in 3 seconds. Javascript is fine. If you want all kinds of wizbang buttons and coordinated rotation of the screen, straight up js + dhtml will be clunky at best. Silverlight vs Flash are you questions at that point. Interestingly enough, you program... | Animation in javascript, a starting point | [
"",
"javascript",
"animation",
""
] |
Trying to keep all the presentation stuff in the xhtml on this project and I need to format some values in a selectItem tag have a BigDecimal value and need to make it look like currency. Is there anyway to apply a `<f:convertNumber pattern="$#,##0.00"/>` Inside a `<f:selectItem>` tag?
Any way to do this or a work aro... | After doing some more research here I'm pretty convinced this isn't possible with the current implementation of JSF. There just isn't an opportunity to transform the value.
<http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/f/selectItem.html>
The tld shows the `itemLabel` property as being a `ValueExpressio... | being a beginner to jsf i had a similar problem, maybe my solution is helpful, maybe its not in the "jsf spirit"
i just created a custom taglib and extended the class (in my case org.apache.myfaces.component.html.ext.HtmlCommandButton) and overrided the setters to apply custom parameters.
so instead of `<t:commandBut... | JSF selectItem label formatting | [
"",
"java",
"jsf",
""
] |
Can someone explain the mechanics of a jump table and why is would be needed in embedded systems? | A jump table can be either an array of pointers to functions or an array of machine code jump instructions. If you have a relatively static set of functions (such as system calls or virtual functions for a class) then you can create this table once and call the functions using a simple index into the array. This would ... | A jump table, also known as a branch table, is a series of instructions, all unconditionally branching to another point in code.
You can think of them as a switch (or select) statement where all the cases are filled:
```
MyJump(int c)
{
switch(state)
{
case 0:
goto func0label;
case 1:
... | What is a jump table? | [
"",
"c++",
"c",
"memory",
"embedded",
""
] |
I'm trying to rebuild an old metronome application that was originally written using `MFC` in C++ to be written in `.NET` using `C#`. One of the issues I'm running into is playing the midi files that are used to represent the metronome "clicks".
I've found a few articles online about playing `MIDI` in .NET, but most o... | I think you'll need to p/invoke out to the windows api to be able to play midi files from .net.
This codeproject article does a good job on explaining how to do this:
[vb.net article to play midi files](http://www.codeproject.com/KB/audio-video/vbnetSoundClass.aspx)
To rewrite this is c# you'd need the following impo... | I'm working on a C# MIDI application at the moment, and the others are right - you need to use p/invoke for this. I'm rolling my own as that seemed more appropriate for the application (I only need a small subset of MIDI functionality), but for your purposes the [C# MIDI Toolkit](http://www.codeproject.com/KB/audio-vid... | Best way to play MIDI sounds using C# | [
"",
"c#",
".net",
"midi",
""
] |
What's the best way to make a linked list in Java? | The obvious solution to developers familiar to Java is to use the **LinkedList** class already provided in **java.util**. Say, however, you wanted to make your own implementation for some reason. Here is a quick example of a linked list that inserts a new link at the beginning of the list, deletes from the beginning of... | Java has a [LinkedList](http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedList.html) implementation, that you might wanna check out. You can download the JDK and it's sources at [java.sun.com](http://java.sun.com/javase/downloads/index.jsp). | How do I create a Linked List Data Structure in Java? | [
"",
"java",
"data-structures",
"linked-list",
""
] |
I am using [js2-mode](http://code.google.com/p/js2-mode/) to edit Javascript in Emacs, but I can't seem to get it to stop using tabs instead of spaces for indentation. My other modes work fine, just having issues w/ js2. | Do you have
```
(setq-default indent-tabs-mode nil)
```
in your .emacs? It works fine for me in emacs 23.0.60.1 when I do that. js2-mode uses the standard emacs function indent-to, which respects indent-tabs-mode, to do its indenting. | Add this to your `.emacs` file somewhere after you load js2 mode:
```
(setq js2-mode-hook
'(lambda () (progn
(set-variable 'indent-tabs-mode nil))))
``` | How do I get js2-mode to use spaces instead of tabs in Emacs? | [
"",
"javascript",
"emacs",
"ide",
"js2-mode",
""
] |
I'm writing a wizard for an Eclipse RCP application. After doing some processing on a file and taking some user input, I don't want to let the user go back to make changes. At this point they must either accept or reject the changes they are about to make to the system.
What I can't seem to find is a method call that ... | You can return null from the getPreviousPage() method in your wizard page implementation. | Expanding on jodonell's answer:
Disabling the back button is harder than it should be, due to non-intuitive behavior in the default implementation of WizardPage.getPreviousPage(). You can call setPreviousPage( null ), and getPreviousPage() still returns the previous page. You need to override the implementation of get... | Can you disable the back button in a JFace wizard? | [
"",
"java",
"eclipse",
"rcp",
"jface",
"wizard",
""
] |
I was wondering if anyone that has experience in both this stuff can shed some light on the *significant* difference between the two if any?
Any specific strength of each that makes it suitable for any specific case? | This question is quite dated but as it is still getting traffic and answers I though I state my point here again even so I already did it on some other (newer) questions.
I'm ***really really*** baffled that SimpleTest **still** is considered an alternative to phpunit. Maybe i'm just misinformed but as far as I've see... | I prefer PHPUnit now, but when I started out I used SimpleTest as I didn't always have access to the command line. SimpleTest is nice, but the only thing it really has over PHPUnit, in my opinion, is the web runner.
The reasons I like PHPUnit are that it integrates with other PHP developer tools such as [phing](http:/... | SimpleTest vs PHPunit | [
"",
"php",
"unit-testing",
"phpunit",
"simpletest",
""
] |
How do you give a C# auto-property an initial value?
I either use the constructor, or revert to the old syntax.
**Using the Constructor:**
```
class Person
{
public Person()
{
Name = "Initial Name";
}
public string Name { get; set; }
}
```
**Using normal property syntax** (with an initial v... | In C# 5 and earlier, to give auto implemented properties an initial value, you have to do it in a constructor.
Since [C# 6.0](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-60), you can specify initial value in-line. The syntax is:
```
public int X { get; set; } = x; // C# ... | **C# 6** :
With C# 6 you can initialize auto-properties directly (finally!), there are now other answers that describe that.
**C# 5 and below**:
Though the intended use of the attribute is not to actually set the values of the properties, you can use reflection to always set them anyway...
```
public class DefaultV... | What is the best way to give a C# auto-property an initial value? | [
"",
"c#",
"constructor",
"getter",
"setter",
"automatic-properties",
""
] |
This is an Eclipse question, and you can assume the Java package for all these Eclipse classes is `org.eclipse.core.resources`.
I want to get an `IFile` corresponding to a location `String` I have:
```
"platform:/resource/Tracbility_All_Supported_lib/processes/gastuff/globalht/GlobalHTInterface.wsdl"
```
I have the... | org.eclipse.core.runtime.Path implements IPath.
```
IPath p = new Path(locationString);
IWorkspaceRoot.getFileForLocation(p);
```
This would have worked had the location string not been a URL of type "platform:"
For this particular case, notes in org.eclipse.core.runtime.Platform javadoc indicate that the "correct" ... | ```
String platformLocationString = portTypeContainer
.getLocation();
String locationString = platformLocationString
.substring("platform:/resource/".length());
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot workspaceRoot = workspace.getRoot();
IFile wSDLFile = (IFile) workspaceRo... | Get IFile from IWorkspaceRoot and location String | [
"",
"java",
"eclipse",
""
] |
Some Eclipse plugins are mandated by your environment. The appropriate source code management plugin, for example - and I'm not interested in those.
Some provide useful enhancements, but in a specific niche. I'm not interested in those.
Some are great, but cost money. I'm not interested in those.
Some were really us... | Findbugs saved me doing something silly twice today.
<http://findbugs.sourceforge.net/>
Eclipse update site is: <http://findbugs.cs.umd.edu/eclipse/> | Answering my own question with my current favourite, Jadclipse, which works with jad to disassemble class files from third party libraries.
<http://jadclipse.sourceforge.net/> | What is the single best free Eclipse plugin for a Java developer | [
"",
"java",
"ide",
"eclipse-plugin",
""
] |
I am looking for an efficient way to pull the data I want out of an array called $submission\_info so I can easily auto-fill my form fields. The array size is about 120.
I want to find the field name and extract the content. In this case, the field name is **loanOfficer** and the content is **John Doe**.
```
Output o... | You're probably best off going through each entry and creating a new associative array out of it.
```
foreach($submission_info as $elem) {
$newarray[$elem["field_name"]] = $elem["content"];
}
```
Then you can just find the form fields by getting the value from $newarray[*<field you're filling in>*]. Otherwise, yo... | Not sure if this is the optimal solution:
```
foreach($submission_info as $info){
if($info['field_name'] == 'loanOfficer'){ //check the field name
$content = $info['content']; //store the desired value
continue; //this will stop the loop after the desired item is found
}
}
```
Next time:
Questions are mor... | How do I efficiently search an array to fill in form fields? | [
"",
"php",
"arrays",
""
] |
I currently use the following function to do a simple HTTP GET.
```
public static String download(String url) throws java.io.IOException {
java.io.InputStream s = null;
java.io.InputStreamReader r = null;
//java.io.BufferedReader b = null;
StringBuilder content = new StringBuilder();
try {
... | In this case, I would do as you are doing (use a byte array for buffering and not one of the stream buffers).
There are exceptions, though. One place you see buffers (output this time) is in the servlet API. Data isn't written to the underlying stream until *flush()* is called, allowing you to buffer output but then d... | You are correct, if you use BufferedReader for reading HTTP content and headers you will want InputStreamReader so you can read byte for byte.
BufferedReader in this scenario sometimes does weird things...escpecially when it comes to reading HTTP POST headers, sometimes you will be unable to read the POST data, if you... | Is there a reason to use BufferedReader over InputStreamReader when reading all characters? | [
"",
"java",
"performance",
"http",
"io",
"buffer",
""
] |
I see many similar questions, however I want to find the Username of the currently logged in user using Java.
Its probably something like:
```
System.getProperty(current.user);
```
But, I'm not quite sure. | You're actually really close. This is what you're looking for:
```
System.getProperty("user.name")
``` | The commonly available system properties are documented in the [`System.getProperties()`](http://java.sun.com/javase/6/docs/api/java/lang/System.html#getProperties%28%29) method.
As Chris said `"user.name"` is the property to get the user running your app. | Java: Programatic Way to Determine Current Windows User | [
"",
"java",
"windows",
""
] |
I am reviewing a big java application to see if there are any performance bottlenecks. The real problem is that I cannot pinpoint the performance issues to any single module. The whole application is slow as such.
Is there some tool/technique I can use to help me out in this? | Try using a profiler on your running code. It should help you identify the bottlenecks. Try [jprofiler](http://www.ej-technologies.com/products/jprofiler/overview.html) or [Netbeans profiler](http://www.netbeans.org/features/java/profiler.html) | I'm often happy enough using `Java -Xprof`. This gives you a sorted list of the functions your code spends most of its time in. | How to test java application for performance bottlenecks? | [
"",
"java",
"performance",
""
] |
I'm new to NHibernate (my 1st big project with it).
I had been using a simple method of data access by creating the ISession object within a using block to do my grab my Object or list of Objects, and in that way the session was destroyed after exiting the code block.
This doesn't work in a situation where lazy-load... | Session management:
<http://code.google.com/p/dot-net-reference-app/source/browse/trunk/src/Infrastructure/Impl/HybridSessionBuilder.cs>
Session per request:
<http://code.google.com/p/dot-net-reference-app/source/browse/trunk/src/Infrastructure/Impl/NHibernateSessionModule.cs> | check out the [SummerOfNHibernate](http://www.SummerOfNHibernate.com) webcasts for a great tutorial... What you're looking for specifically doesn't come until webisode 5 or 6. | Best way to manage session in NHibernate? | [
"",
"c#",
".net",
"nhibernate",
""
] |
I'm trying to find the latitude and longitude of the corners of my map while in birdseye view. I want to be able to plot pins on the map, but I have hundreds of thousands of addresses that I want to be able to limit to the ones that need to show on the map.
In normal view, VEMap.GetMapView().TopLeftLatLong and .Bottom... | Here's the code for getting the Center Lat/Long point of the map. This method works in both Road/Aerial and Birdseye/Oblique map styles.
```
function GetCenterLatLong()
{
//Check if in Birdseye or Oblique Map Style
if (map.GetMapStyle() == VEMapStyle.Birdseye || map.GetMapStyle() == VEM... | It always seems to me that the example solutions for this issue only find the centre of the current map on the screen, as if that is always the place you're going to click! Anyway, I wrote this little function to get the actual pixel location that you clicked on the screen and return a VELatLong for that. So far it see... | How do I find the the exact lat/lng coordinates of a birdseye scene in Virtual Earth? | [
"",
"javascript",
"virtual-earth",
""
] |
I want to create a Java program that can be extended with plugins. How can I do that and where should I look for?
I have a set of interfaces that the plugin must implement, and it should be in a jar. The program should watch for new jars in a relative (to the program) folder and registered them somehow.
---
Although... | I've done this for software I've written in the past, it's very handy. I did it by first creating an Interface that all my 'plugin' classes needed to implement. I then used the Java [ClassLoader](http://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html) to load those classes and create instances of them.
On... | Look into [OSGi](http://www.osgi.org).
On one hand, OSGi provides all sorts of infrastructure for managing, starting, and doing lots of other things with modular software components. On the other hand, it could be too heavy-weight for your needs.
Incidentally, Eclipse uses OSGi to manage its plugins. | How to create a pluginable Java program? | [
"",
"java",
"plugins",
"plugin-architecture",
""
] |
On my side job as programmer, I am to write a program in C++ to convert audio files from/to various formats. Probably, this will involve building a simple GUI.
Will it be a great effort to build seperate GUIs for Mac and Windows using Cocoa and WinForms instead of a cross-platform toolkit like Qt or GTK?
(I will ha... | If you have the expertise, use native frontends, it'll effectively double the job you have to do for UI but from my experience non-native UI is a little bit clunkier than their native counterparts. | Have you looked at [wxWidgets](http://www.wxwidgets.org/)? Cross platform native controls. | Should I use a cross-platform GUI-toolkit or rely on the native ones? | [
"",
"c++",
"user-interface",
"cross-platform",
""
] |
In [another question](https://stackoverflow.com/questions/32404/can-i-run-a-python-script-as-a-service-in-windows-how "Python scripts as Windows service") I posted yesterday, I got very good advice on how a Python script could be run as a service in Windows. What I'm left wondering is: How is Windows aware of the servi... | As with most "aware" things in Windows, the answer is "Registry".
Take a look at this Microsoft Knowledge Base article: <http://support.microsoft.com/kb/103000>
Search for "A Win32 program that can be started by the Service Controller and that obeys the service control protocol." This is the kind of service you're in... | Don't muck with the registry directly. User the SC command-line tool. Namely, SC CREATE
```
DESCRIPTION:
SC is a command line program used for communicating with the
NT Service Controller and services.
USAGE:
sc [command] [service name] ...
The option has the form "\\ServerN... | How do I make Windows aware of a service I have written in Python? | [
"",
"python",
"windows",
"cross-platform",
""
] |
I read somewhere once that the modulus operator is inefficient on small embedded devices like 8 bit micro-controllers that do not have integer division instruction. Perhaps someone can confirm this but I thought the difference is 5-10 time slower than with an integer division operation.
Is there another way to do this... | Ah, the joys of bitwise arithmetic. A side effect of many division routines is the modulus - so in few cases should division actually be faster than modulus. I'm interested to see the source you got this information from. Processors with multipliers have interesting division routines using the multiplier, but you can g... | If you are calculating a number mod some power of two, you can use the bit-wise and operator. Just subtract one from the second number. For example:
```
x % 8 == x & 7
x % 256 == x & 255
```
A few caveats:
1. This **only works** if the second number is a power of two.
2. It's only equivalent if the modulus is always... | Is there any alternative to using % (modulus) in C/C++? | [
"",
"c++",
"c",
"modulo",
"embedded",
""
] |
We're currently using Lucene 2.1.0 for our site search and we've hit a difficult problem: one of our index fields is being ignored during a targeted search. Here is the code for adding the field to a document in our index:
```
// Add market_local to index
contactDocument.add(
new Field(
"market_local"
... | For debugging Lucene, the best tool to use is [Luke](http://www.getopt.org/luke/), which lets you poke around in the index itself to see what got indexed, carry out searches, etc. I recommend downloading it, pointing it at your index, and seeing what's in there. | The [section on "Why am I getting no hits?"](http://wiki.apache.org/lucene-java/LuceneFAQ#head-3558e5121806fb4fce80fc022d889484a9248b71) in the Lucene FAQ has some suggestions you might find useful. You're using Field.Index.UN\_TOKENIZED, so no Analyzer will be used for indexing (I think). If you're using an Analyzer w... | Troubleshoot Java Lucene ignoring Field | [
"",
"java",
"lucene",
""
] |
We are producing a portable code (win+macOs) and we are looking at how to make the code more rubust as it crashes every so often... (overflows or bad initializations usually) :-(
I was reading that Google Chrome uses a process for every tab so if something goes wrong then the program does not crash compleatelly, only ... | I've developed on numerous multi-platform C++ apps (the largest being 1.5M lines of code and running on 7 platforms -- AIX, HP-UX PA-RISC, HP-UX Itanium, Solaris, Linux, Windows, OS X). You actually have two entirely different issues in your post.
1. Instability. Your code is not stable. Fix it.
* Use unit tests t... | The Chrome answer is more about failure mitigation and not about code quality. Doing what Chrome is doing is admitting defeat.
1. Better QA that is more than just programmer testing their own work.
2. Unit testing
3. Regression testing
4. Read up on best practices that other
companies use.
To be blunt, if your sof... | Super Robust as chrome c++ and portable - tips - help - comments | [
"",
"c++",
"boost",
"google-chrome",
"portability",
"robust",
""
] |
I have been using Castle MonoRail for the last two years, but in a new job I am going to be the one to bring in ASP.NET MVC with me.
I understand the basics of views, actions and the like.
I just need a good sample for someone with MVC experience.
Any good links besides Scott's Northwind traders sample? | [CodeCampServer](http://code.google.com/p/codecampserver/) - Built with ASP.NET MVC, pretty light and small project. No cruft at all.
@lomaxx - Just FYI, most of what Troy Goode wrote is now part of [ASP.NET MVC as of Preview 4](http://weblogs.asp.net/scottgu/archive/2008/07/14/asp-net-mvc-preview-4-release-part-1.asp... | [Rob Conery's MVC Storefront project](http://blog.wekeroad.com/mvc-storefront/) is a good from-the-ground-up step-by-step series on how to put up an ASP.NET MVC site. | Where can I find a good ASP.NET MVC sample? | [
"",
"c#",
"asp.net",
"asp.net-mvc",
""
] |
Should I use Named Pipes, or .NET Remoting to communicate with a running process on my machine? | WCF is the best choice. It supports [a number of different transport mechanisms](https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-3.0/ms733769%28v=vs.85%29) ([including](https://web.archive.org/web/20121019154711/http://blogs.charteris.com:80/blogs/chrisdi/archive/2008/05/19/exploring-the-wcf-nam... | If it's on a single machine, Named Pipes gives you better performance and can be implemented with the [remoting infrastructure](https://web.archive.org/web/20081023122612/http://ivanweb.com/articles/namedpipes/index.cfm) as well as WCF. Or you can just directly use [System.IO.Pipes](https://web.archive.org/web/20081028... | What is the best choice for .NET inter-process communication? | [
"",
"c#",
".net",
"process",
"ipc",
""
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.