instruction stringlengths 0 30k ⌀ |
|---|
I disagree with [Yaakov Ellis' answer.][1] The Common Language Specification guarantees that "a type initializer shall run exactly once for any given type, unless explicitly called by user code." (Section 9.5.3.1.) So unless you have some whacky IL on the loose calling Singleton::.cctor directly (unlikely) your static ... |
I disagree with [Yaakov Ellis' answer.][1] The [Common Language Infrastructure specification][2] guarantees that "a type initializer shall run exactly once for any given type, unless explicitly called by user code." (Section 9.5.3.1.) So unless you have some whacky IL on the loose calling Singleton::.cctor directly (un... |
http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeProjectManagement/090_Running_Programs/chapter_11_section_3.html
asm {trap} ; Halts a program running on PPC32 or PPC64.
__asm {int 3} ; Halts a program running on IA-32. |
> [@Jorge](#37302) wrote: If you want to process your code in a different way the use a preprocessor directive but if you just want a code snippet then find another way because the preprocessor wasn't meant to do that.
Interesting. I don't really consider a preprocessor to necessarily work this way. In the example p... |
I assume that you followed the [dijit.Tree and dojo.data in Dojo 1.1][1] tutorial which directed you to pass the data to the tree control using a data store. That had me banging my head of a brick wall for a while.
Its not really a great approach and the alternative is not really well documented. You need to create... |
What's the best way to persist data in a Java Desktop Application? |
|java|persistence|desktop|oop| |
I have a large tree of Java Objects in my Desktop Application and am trying to decide on the best way of persisting them as a file to the file system.
Some thoughts I've had were:
- **Roll my own serializer using DataOutputStream**: This would give me the greatest control of what was in the file, but at the cost... |
After installing the DEB that John pointed to, my app crashes... Is this because the deb is for the wrong Ubuntu (8.08 rather than 8.04)? It appears to be the correct version of libgluezilla for the version of Mono (everything is. 1.9.1)...
Here is what I get when I try to run the application with
<pre>
$MONO... |
The least painful and indeed Django-recommended way of doing this is through a ForeignKey(User) property.
That said, extending django.contrib.auth.models.User also works better now -- ever since the refactoring of Django's inheritance code in the models API.
I would definitely stay away from changing the actual U... |
This is true. It's the way [FogCreek Copilot][1] works
Take a look at item 2 on Joel's [Copilot 2.0 post][2].
[1]: https://www.copilot.com/
[2]: http://www.joelonsoftware.com/items/2007/01/26.html |
Real-time wmv video encoding in C# |
|video|encoding|.net| |
How to encode video on the fly and send it trough the network from C#?
Can't find a suitable library. I need to encode in WMV and don't mind if the actual encoding is made in C++ as long as the library has a .NET dll available.
Thanks |
|video|encoding|.net|c#| |
|video|encoding|.net| |
How to encode video on the fly and send it trough the network from C#?
Can't find a suitable library. I need to encode in WMV and don't mind if the actual encoding is made in C++ as long as the library has a .NET assembly available.
Thanks |
PHP variables are assigned by value, passed to functions by value, and when containing/representing objects are passed by reference.
Assigned by value/reference example:
$var1 = "test";
$var2 = $var1;
$var2 = "new test";
$var3 = &$var2;
$var3 = "final test";
print ("var1: $var1,... |
PHP variables are assigned by value, passed to functions by value, and when containing/representing objects are passed by reference. You can force variables to pass by reference using an &
Assigned by value/reference example:
$var1 = "test";
$var2 = $var1;
$var2 = "new test";
$var3 = &$var2;
... |
You can upgrade 6.5 to SQL Server 2000. You may have an easier time getting a hold of SQL Server or the 2000 version of the MSDE. Microsoft has a page on [going from 6.5 to 2000][1]. Once you have the database in 2000 format, SQL Server 2005 will have no trouble upgrading it to the 2005 format.
If you don't hav... |
@Goyuix -- that's excellent for something written from memory.
tested it here -- found the connection wasn't opened. Otherwise very nice.
using System.Data.OleDb;
...
using (OleDbConnection conn = new OleDbConnection())
{
conn.ConnectionString = "Provider=sqloledb;Data Source=yourServe... |
you'll have to split the file by linebreaks,
then loop thru each line and apply the following logic
$seat = 0;
$name = 1;
$chips = 2;
foreach( $string in $file ) {
if (preg_match("Seat ([1-0]): ([A-Za-z_0-9]*) \(([1-0]*) in chips\)", $string, $matches)) {
echo "Seat: " .... |
I always use the preg_ set of function for REGEX in PHP because the PERL-compatible expressions have much more capability. That extra capability doesn't necessarily come into play here, but they are also supposed to be faster, so why not use them anyway, right?
For an expression, try this:
/Seat (\d+): ([^ ]+... |
I always use the preg_ set of function for REGEX in PHP because the PERL-compatible expressions have much more capability. That extra capability doesn't necessarily come into play here, but they are also supposed to be faster, so why not use them anyway, right?
For an expression, try this:
/Seat (\d+): ([^ ]+... |
I think that some of the confusion comes from the difference between the concept of a tag and the implementation in SVN. To SVN a tag is a branch which is a copy. Modifying tags is considered wrong and in fact tools like TortoiseSVN will warn you if you attempt to modify anything with ../tags/.. in the path. |
I would highly recommend picking up a copy of Effective Java and reading through item 7 obeying the [equals contract][2]. You need to be careful if you are overriding equals for mutable objects, as many of the collections such as Maps and Sets use equals to determine equivalence, and mutating an object contained in a c... |
I would highly recommend picking up a copy of Effective Java and reading through item 7 obeying the [equals contract][1]. You need to be careful if you are overriding equals for mutable objects, as many of the collections such as Maps and Sets use equals to determine equivalence, and mutating an object contained in a c... |
Here's what I'm currently using:
preg_match("/(Seat \d+: [A-Za-z0-9 _-]+) \((\d+) in chips\)/",$line) |
|java|desktop|oop|persistence| |
I have a large tree of Java Objects in my Desktop Application and am trying to decide on the best way of persisting them as a file to the file system.
Some thoughts I've had were:
- **Roll my own serializer using DataOutputStream**: This would give me the greatest control of what was in the file, but at the cost... |
First of all, you can find out which version of Windows you are using with the [OperatingSystem.Platform][1] property in the System library.
Second, it is possible that you may put your font settings in Resource files, and determine which resource file to use depending on certain conditions (e.g., your operating sys... |
Not really, at least, not last time I looked. I mean, boost::thread_group might make things marginally tidier in places, but not so as would make much of a difference, I don't think.
Boost's thread support seems marginally useful when writing something that's cross-platform, but given that what you're writing is go... |
Your implementation looks good enough -- what I do want to know is why you want to do this in the first place? Won't it be preferrable for the focus to cycle back to the first entry? Is the data in the last text box so malleable that once they click the button it is "remembered"? Or do you have some sort of operation t... |
I think what you're doing is fine. The only thing I could think of to improve it would be to store each control into a stack as they are accessed. That would give you a complete time line of what was accessed. |
Encoding flash video is actually very easy with ffmpeg. You can use one command to convert from just about any video format, ffmpeg is smart enough to figure the rest out, and it'll use every processor on your machine. Invoking it is easy:
ffmpeg -i input.avi output.flv
ffmpeg will guess at the bitrate you ... |
The database will do this for you. Look at "select ... for update", which is designed just for this kind of thing. It will give you a write lock on the selected rows, which you can then commit or roll back. |
In Python monkey patching generally works by overwriting a class or functions signature with your own. Below is an example from the [Zope Wiki][1]:
from SomeOtherProduct.SomeModule import SomeClass
def speak(self):
return "ook ook eee eee eee!"
SomeClass.speak = speak
That code will overwrit... |
is this a console app or a winforms app? If it's a .NET 1.1 console app this is, sadly, by design -- it's confirmed by a MSFT dev in the [second blog post you referenced](http://www.codinghorror.com/blog/archives/000216.html):
> BTW, on my 1.1 machine the example from MSDN does have the expected output; it's just th... |
It's a WinForms app. The exceptions that are caught by Application.ThreadException work fine, and I don't get the ugly .NET exception box (OK to terminate, cancel to debug? who came up with that??).
I was getting some exceptions that weren't being caught by that and ended up going to the AppDomain.UnhandledException... |
get root permissions on a file inside of vi? |
|c#|.net|video|encoding| |
That's very likely. This was pretty much what we assumed (browser problem, not necessarily Ajax).
Our problem is now, with this application being accessed by many people via a Citrix environment, with each page continually creating DOM objects and not releasing them, the Citrix environment starts thrashing after so... |
I don't have any experience with it, but [SupoSE][1] (open source, written in Java) is a tool designed to do exactly this.
[1]: http://supose.soebes.de/ |
Use the [UNION][1] operator:
SELECT ColumnA FROM Table1
UNION
SELECT ColumnA FROM Table2
[1]: http://msdn.microsoft.com/en-us/library/ms180026.aspx |
Your friend might be referring to VIP's (Virtual IP's). From my understanding a VIP is usually controlled by a piece of hardware like a router and then redirects to one of your 2 private IP's. We use this with a cluster of machines behind a VIP. I'm not a network guy so that's pretty much the extent of my knowledge. |
You can use a union select:
Select columnA from table1 union select columnA from table2
|
SELECT Table1.*, Table2.d, Table2.e, Table2.f
FROM Table1 JOIN Table2 ON Table1.a = Table2.a
Or am I misunderstanding your question?
Edit: It appears I did.
|
I believe it's:
SELECT columna FROM table1 UNION SELECT columnb FROM table2; |
I have been looking for something similar. The best I have come up with is [OpenGrok][1]. I have not tried to implement it yet, but sounds promising.
[1]: http://opensolaris.org/os/project/opengrok/ "OpenGrok" |
How do I best generate a CSV (comma-delimited text file) for download with ASP.NET? |
|asp.net|vb.net|file-io|csv| |
This is what I've got. It works. But, is there a simpler or better way?
One an ASPX page, I've got the download link...
<asp:HyperLink ID="HyperLinkDownload" runat="server" NavigateUrl="~/Download.aspx">Download as CSV file</asp:HyperLink>
And then I've got the Download.aspx.vb Code Behind...
Public... |
You should "never" override equals & getHashCode for mutable objects - this goes for .net and Java both. If you do, and use such an object as the key in f.ex a dictionary and then *change* that object, you'll be in trouble because the dictionary relies on the hashcode to find the object.
Here's a good article on the... |
Check out [preg_match][1].
Probably looking for something like...
<?php
$str = 'Seat 1: fabulous29 (835 in chips)';
preg_match('/Seat (?<seatNo>\d+): (?<name>\w+) \((?<chipCnt>\d+) in chips\)/', $str, $matches);
print_r($matches);
?>
*It's been a while since I did php, so this *could* be ... |
I think you need to elaborate on your needs if you want useful answers.
Generally speaking, though, I get the impression that NAnt offers more flexibility compared to MSBuild, whereas (with my relatively simple needs) I've been fine with the latter so far. |
I think you need to elaborate on your needs if you want useful answers.
Generally speaking, though, I get the impression that NAnt offers more flexibility compared to MSBuild, whereas (with my relatively simple needs) I've been fine with the latter so far.
**Edit:** Sorry, I wasn't trying to be harsh. I see other... |
When we used to work in MSSQL 2000, we did what we called the "triple-flip":
SELECT * FROM
(
SELECT TOP (pagesize) FROM
(
SELECT TOP (n * pagesize) FROM X ORDER BY (column) ASC
) AS t1 ORDER BY (column) DESC
) AS t2 ORDER BY (column) ASC
It wasn't elegant, and... |
I suspect this is wildly inefficient but is quite a simple approach, which worked on a small dataset that I tried it on.
select top 1 field
from table
where field in (select top 1 field from table order by field asc)
order by field desc
SQL server only (I think) but should work on older version... |
I suspect this is wildly inefficient but is quite a simple approach, which worked on a small dataset that I tried it on.
select top 1 field
from table
where field in (select top 5 field from table order by field asc)
order by field desc
This would get the 5th item, change the second top number ... |
[@cmcculloh](http://stackoverflow.com/questions/16155/making-one-interface-overwrite-a-method-it-inherits-from-another-interface-in-p#16196) Yeah, in Java you don't define constructors in Interfaces. This allows you to both extend interfaces and also have a class that implements multiple interfaces (both allowed, and ... |
[@cmcculloh](http://stackoverflow.com/questions/16155/making-one-interface-overwrite-a-method-it-inherits-from-another-interface-in-p#16196) Yeah, in Java you don't define constructors in Interfaces. This allows you to both extend interfaces and also have a class that implements multiple interfaces (both allowed, and ... |
> Virtual functions in constructors, why do languages differ?
Because there's no one good behaviour. I find the C++ behaviour makes more sense (since base class c-tors are called first, it stands to reason that they should call base class virtual functions--after all, the derived class c-tor hasn't run yet, so it m... |
How do you return the focus to the last used control after clicking a button in a winform app? |
|c#|winforms| |
I'm working on a windows forms application (C#) where a user is entering data in a form. At any point while editing the data in the form the user can click one of the buttons on the form to perform certain actions. By default the focus goes to the clicked button so the user has to click back on to the control they wa... |
|c#|.net|winforms| |
Instead of that macro, might I suggest this one:
template<typename T, int N>
inline size_t array_size(T(&)[N])
{
return N;
}
#define ARRAY_SIZE(X) (sizeof(array_size(X)) ? (sizeof(X) / sizeof((X)[0])) : -1)
1) We want to use a macro to make it a compile-time constant; the funct... |
The [Common Language Infrastructure specification][2] guarantees that "a type initializer shall run exactly once for any given type, unless explicitly called by user code." (Section 9.5.3.1.) So unless you have some whacky IL on the loose calling Singleton::.cctor directly (unlikely) your static constructor will run ex... |
The C99 standard has a number of standard sized-integer types. If you can use a compiler that supports C99 (gcc does), you'll find these in `<stdint.h>` and you can just use them in your projects.
Also, it can be especially important in embedded projects to use types as a sort of "safety net" for things like unit c... |
Debugging Javascript in Internet Explorer and Safari |
|javascript|safari|explorer| |
Currently, I don't really have a good method of debugging javascript in internet explorer and safari. In Firefox, you can use Firebug's [Logging feature][1] and [Command Line functions][2]. However, this doesn't help me when I move to other browsers.
[1]: http://getfirebug.com/logging.html
[2]: http://getfire... |
*string* is an alias for *System.String*. So technically, there is no difference. It's like *int* vs. *System.UInt32*.
As far as guidelines, use *string* any time you would you're referring to an object. Use *String* if you need to refer specifically to the class. |
*string* is an alias for *System.String*. So technically, there is no difference. It's like *int* vs. *System.UInt32*.
As far as guidelines, I think it's generally recommended to use *string* any time you would you're referring to an object. e.g.
string place = "world";
Likewise, I think it's generally ... |
|linux|unix|vi| |
Often while editing config files, I'll open one with vi and then when I go to save it realize that I didn't type
sudo vi filename
Is there any way to give vi sudo privileges to save the file? I seem to recall seeing something about this while looking up some stuff about vi a while ago, but now I can't find it... |
A quick Google seems to give this advice:
1. Don't try to edit if it's read-only.
1. You might be able to change the permissions on the file. (Whether or not it will let you save is up to experimentation.)
1. If you still edited anyway, save to a temporary file and then move it.
<http://ubuntuforums.org/showthr... |
Ryan's advice is generally good, however, if following step 3, don't move the temporary file; it'll have the wrong ownership and permissions. Instead, `sudoedit` the correct file and read in the contents (using `:r` or the like) of the temporary file.
If following step 2, use `:w!` to force the file to be written. |
How to get the value of built, encoded ViewState? |
|c#|asp.net| |
I need to grab the base64-encoded representation of the ViewState. Obviously this would not be available until fairly late in the request lifecycle, which is OK.
For example, if the output of the page includes:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJODU0Njc5MD...==" />
I ne... |
I need to grab the base64-encoded representation of the ViewState. Obviously this would not be available until fairly late in the request lifecycle, which is OK.
For example, if the output of the page includes:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJODU0Njc5MD...==" />
I ne... |
Oh, in WinForms you definitely should be able to get it to work. The only thing you have to watch out for is things happening on different threads.
I have an old CodeProject article here which should help:
<http://www.codeproject.com/KB/exception/ExceptionHandling.aspx> |
That's definitely a good way to do it. But you if you happen to be using a database that supports LINQ to SQL, it can be a lot more fun. It can look something like this:
MyDB db = new MyDB("Data Source=...");
var q = from db.MyTable
select c;
foreach (var c in q)
Console.WriteLine... |
The CCNetArtifactDirectory is passed to the MSBuild by default, so you dont need to worry about it. MSBuild will place the build output in the "bin location" relevant to the working directory that you have specified.
<executable>c:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<workingDirec... |
Your approach looks good. If you want to avoid having to add an the event handler to every control you add, you could create a recursive routine to add a [GotFocus][1] listener to every control in your form. This will work for any type of control in your form, however you could adjust it to meet your needs.
pr... |
How to deal with "java.lang.OutOfMemoryError: Java heap space" error (64MB heap size) |
|java|jvm|heap|tuning|out-of-memory| |
I am writing a client-side Swing application (graphical font designer) on Java 5. Recently, I am running into "java.lang.OutOfMemoryError: Java heap space" error because I am not being conservative on memory usage. The user can open unlimited number of files, and the program keeps the opened objects in the memory. Afte... |
For a bit of 'simplicity' maybe try.
public Form1()
{
InitializeComponent();
foreach (Control ctrl in Controls)
{
if (ctrl is TextBox)
{
ctrl.Enter += delegate(object sender, EventArgs e)
... |
Wordpress Wiki Integration |
|wordpress|php|mysql|wiki| |
I am running a WordPress blog right now on my own LAMP hosting. I really want to add some basic Wiki functionality to my site. Ideally just the ability to have some posts or pages that users with certain roles / capabilities could edit. The latest version of WordPress has edit revisions, so it would seem like I coul... |
[@cmcculloh](http://stackoverflow.com/questions/16155/making-one-interface-overwrite-a-method-it-inherits-from-another-interface-in-p#16196) Yeah, in Java you don't define constructors in Interfaces. This allows you to both extend interfaces and also have a class that implements multiple interfaces (both allowed, and ... |
Validation Patterns for Custom XML Documents |
|c#|visual-studio|xml|schema| |
I have a web application that generates a medium sized XML dataset to be consumed by a third party. I thought it would be a good idea to provide some form of schema document for the XML that I generate so I pasted the XML into Visual Studio and got it to generate an XSD. The annoying thing is that my XML doesn't valida... |
Overriding the equals method is necessary if you want to test equivalence in standard library classes (for example, ensuring a java.util.Set contains unique elements or using objects as keys in java.util.Map objects).
Note, if you override equals, ensure you honour the API contract as described in the documentation.... |
Do you care if you get dups or not?
UNION will be slower than UNION ALL because UNION will filter out dups |
In Oracle (at least) there is UNION and UNION ALL, UNION ALL will return all results from both sets even if there are duplicates, where as UNION will return the distinct results from both sets. |