source_id
int64 1
74.7M
| question
stringlengths 0
40.2k
| response
stringlengths 0
111k
| metadata
dict |
---|---|---|---|
73,162 | Is there an API call in .NET or a native DLL that I can use to create similar behaviour as Windows Live Messenger when a response comes from someone I chat with? | FlashWindowEx is the way to go. See here for MSDN documentation [DllImport("user32.dll")][return: MarshalAs(UnmanagedType.Bool)]static extern bool FlashWindowEx(ref FLASHWINFO pwfi);[StructLayout(LayoutKind.Sequential)]public struct FLASHWINFO{ public UInt32 cbSize; public IntPtr hwnd; public UInt32 dwFlags; public UInt32 uCount; public UInt32 dwTimeout;}public const UInt32 FLASHW_ALL = 3; Calling the Function: FLASHWINFO fInfo = new FLASHWINFO();fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));fInfo.hwnd = hWnd;fInfo.dwFlags = FLASHW_ALL;fInfo.uCount = UInt32.MaxValue;fInfo.dwTimeout = 0;FlashWindowEx(ref fInfo); This was shamelessly plugged from Pinvoke.net | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/73162",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6896/"
]
} |
73,227 | I get asked this question a lot and I thought I'd solicit some input on how to best describe the difference. | They are actually two very different things. "Delegate" is actually the name for a variable that holds a reference to a method or a lambda, and a lambda is a method without a permanent name. Lambdas are very much like other methods, except for a couple subtle differences. A normal method is defined in a "statement" and tied to a permanent name, whereas a lambda is defined "on the fly" in an "expression" and has no permanent name. Some lambdas can be used with .NET expression trees, whereas methods cannot. A delegate is defined like this: delegate Int32 BinaryIntOp(Int32 x, Int32 y); A variable of type BinaryIntOp can have either a method or a labmda assigned to it, as long as the signature is the same: two Int32 arguments, and an Int32 return. A lambda might be defined like this: BinaryIntOp sumOfSquares = (a, b) => a*a + b*b; Another thing to note is that although the generic Func and Action types are often considered "lambda types", they are just like any other delegates. The nice thing about them is that they essentially define a name for any type of delegate you might need (up to 4 parameters, though you can certainly add more of your own). So if you are using a wide variety of delegate types, but none more than once, you can avoid cluttering your code with delegate declarations by using Func and Action. Here is an illustration of how Func and Action are "not just for lambdas": Int32 DiffOfSquares(Int32 x, Int32 y){ return x*x - y*y;}Func<Int32, Int32, Int32> funcPtr = DiffOfSquares; Another useful thing to know is that delegate types (not methods themselves) with the same signature but different names will not be implicitly casted to each other. This includes the Func and Action delegates. However if the signature is identical, you can explicitly cast between them. Going the extra mile.... In C# functions are flexible, with the use of lambdas and delegates. But C# does not have "first-class functions". You can use a function's name assigned to a delegate variable to essentially create an object representing that function. But it's really a compiler trick. If you start a statement by writing the function name followed by a dot (i.e. try to do member access on the function itself) you'll find there are no members there to reference. Not even the ones from Object. This prevents the programmer from doing useful (and potentially dangerous of course) things such as adding extension methods that can be called on any function. The best you can do is extend the Delegate class itself, which is surely also useful, but not quite as much. Update: Also see Karg's answer illustrating the difference between anonymous delegates vs. methods & lambdas. Update 2: James Hart makes an important, though very technical, note that lambdas and delegates are not .NET entities (i.e. the CLR has no concept of a delegate or lambda), but rather they are framework and language constructs. | {
"score": 8,
"source": [
"https://Stackoverflow.com/questions/73227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1538/"
]
} |
73,308 | I am trying to implement a request to an unreliable server. The request is a nice to have, but not 100% required for my perl script to successfully complete. The problem is that the server will occasionally deadlock (we're trying to figure out why) and the request will never succeed. Since the server thinks it is live, it keeps the socket connection open thus LWP::UserAgent's timeout value does us no good what-so-ever. What is the best way to enforce an absolute timeout on a request? FYI, this is not an DNS problem. The deadlock has something to do with a massive number of updates hitting our Postgres database at the same time. For testing purposes, we've essentially put a while(1) {} line in the servers response handler. Currently, the code looks like so: my $ua = LWP::UserAgent->new;ua->timeout(5); $ua->cookie_jar({});my $req = HTTP::Request->new(POST => "http://$host:$port/auth/login");$req->content_type('application/x-www-form-urlencoded');$req->content("login[user]=$username&login[password]=$password");# This line never returns $res = $ua->request($req); I've tried using signals to trigger a timeout, but that does not seem to work. eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm(1); $res = $ua->request($req); alarm(0);};# This never runsprint "here\n"; The final answer I'm going to use was proposed by someone offline, but I'll mention it here. For some reason, SigAction works while $SIG(ALRM) does not. Still not sure why, but this has been tested to work. Here are two working versions: # Takes a LWP::UserAgent, and a HTTP::Request, returns a HTTP::Requestsub ua_request_with_timeout { my $ua = $_[0]; my $req = $_[1]; # Get whatever timeout is set for LWP and use that to # enforce a maximum timeout per request in case of server # deadlock. (This has happened.) use Sys::SigAction qw( timeout_call ); our $res = undef; if( timeout_call( 5, sub {$res = $ua->request($req);}) ) { return HTTP::Response->new( 408 ); #408 is the HTTP timeout } else { return $res; }}sub ua_request_with_timeout2 { print "ua_request_with_timeout\n"; my $ua = $_[0]; my $req = $_[1]; # Get whatever timeout is set for LWP and use that to # enforce a maximum timeout per request in case of server # deadlock. (This has happened.) my $timeout_for_client = $ua->timeout() - 2; our $socket_has_timedout = 0; use POSIX; sigaction SIGALRM, new POSIX::SigAction( sub { $socket_has_timedout = 1; die "alarm timeout"; } ) or die "Error setting SIGALRM handler: $!\n"; my $res = undef; eval { alarm ($timeout_for_client); $res = $ua->request($req); alarm(0); }; if ( $socket_has_timedout ) { return HTTP::Response->new( 408 ); #408 is the HTTP timeout } else { return $res; }} | You might try LWPx::ParanoidAgent , a subclass of LWP::UserAgent which is more cautious about how it interacts with remote webservers. Among other things, it allows you to specify a global timeout. It was developed by Brad Fitzpatrick as part of the LiveJournal project. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/73308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12628/"
]
} |
73,319 | How do I duplicate a whole line in Vim in a similar way to Ctrl + D in IntelliJ IDEA/ Resharper or Ctrl + Alt + ↑ / ↓ in Eclipse ? | y y or Y to copy the line (mnemonic: y ank ) or d d to d elete the line (Vim copies what you deleted into a clipboard-like "register", like a cut operation) then p to p aste the copied or deleted text after the current line or P to p aste the copied or deleted text before the current line | {
"score": 13,
"source": [
"https://Stackoverflow.com/questions/73319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11439/"
]
} |
73,468 | I'm coding the shutdown of a multithreaded server.If everything goes as it should all the threads exit by their own, but there's a small chance that a thread gets stuck.In this case it would be convenient to have a non-blocking join so I could do. Is there a way of doing a non-blocking pthread_join?Some sort of timed join would be good too. something like this: foreach thread do nb_pthread_join(); if still running pthread_cancel(); I can think more cases where a a non-bloking join would be useful. As it seems there is no such a function so I have already coded a workaround, but it's not as simple as I would like. | If you are running your application on Linux, you may be interested to know that: int pthread_tryjoin_np(pthread_t thread, void **retval);int pthread_timedjoin_np(pthread_t thread, void **retval, const struct timespec *abstime); Be careful, as the suffix suggests it, "np" means "non-portable". They are not POSIX standard, gnu extensions, useful though. link to man page | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/73468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12661/"
]
} |
73,515 | I am getting some errors thrown in my code when I open a Windows Forms form in Visual Studio's designer. I would like to branch in my code and perform a different initialization if the form is being opened by designer than if it is being run for real. How can I determine at run-time if the code is being executed as part of designer opening the form? | To find out if you're in "design mode": Windows Forms components (and controls) have a DesignMode property. Windows Presentation Foundation controls should use the IsInDesignMode attached property. | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/73515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12717/"
]
} |
73,527 | There are several plugin options for building a search engine into your Ruby on Rails application. Which of these is the best? Thinking Sphinx UltraSphinx Sphincter acts_as_sphinx acts_as_ferret Ferret acts_as_xapian acts_as_solr Hyper Estraier | Thinking Sphinx has more concise syntax to define which fields and which models are indexed. Both UltraSphinx and Thinking Sphinx (recently) have ultra-cool feature which takes into account geographical proximity of objects. UltraSphinx has annoying problems with how it loads models (it does not load entire Rails stack, so you could get strange and hard to diagnose errors, which are handled by adding explicit require statements). We use Thinking Sphinx on new projects, and UltraSphinx on projects which use geo content. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/73527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9594/"
]
} |
73,536 | I'm developing a client/server app that will communicate via rest. Some custom request data will be stored in the header of the request. Both the server sending the request and the receiving server have an SSL certificate - will the headers be encrypted, or just the content? | SSL encrypts the entire communications path from the client to the server and back, so yes - the headers will be encrypted. By the way, if you develop networked applications and care about data security, the least you should do is read a book like Practical Cryptography, by Niels Ferguson and Bruce Schneier, and probably further reading that's more focused on web application security would be a good idea. If I may make an observation - and please, I don't mean that as a personal criticism - your question indicates a fundamental lack of understanding of very basic web security technologies, and that's never a good sign. Also, it's never a bad idea to confirm that data which is assumed to be encrypted is indeed encrypted. You can use a network analyzer to monitor traffic on the wire and watch out for anything sensitive being sent in the clear. I've used Wireshark to do this before - the results can be surprising, sometimes. | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/73536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12280/"
]
} |
73,542 | I have an List and I'd like to wrap it into an IQueryable. Is this possible? | List<int> list = new List<int>() { 1, 2, 3, 4, };IQueryable<int> query = list.AsQueryable(); If you don't see the AsQueryable() method, add a using statement for System.Linq . | {
"score": 8,
"source": [
"https://Stackoverflow.com/questions/73542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11835/"
]
} |
73,580 | Possible Duplicate: How do you send email from a Java app using Gmail? How do I send an SMTP Message from Java? | Here's an example for Gmail smtp: import java.io.*;import java.net.InetAddress;import java.util.Properties;import java.util.Date;import javax.mail.*;import javax.mail.internet.*;import com.sun.mail.smtp.*;public class Distribution { public static void main(String args[]) throws Exception { Properties props = System.getProperties(); props.put("mail.smtps.host","smtp.gmail.com"); props.put("mail.smtps.auth","true"); Session session = Session.getInstance(props, null); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress("[email protected]"));; msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]", false)); msg.setSubject("Heisann "+System.currentTimeMillis()); msg.setText("Med vennlig hilsennTov Are Jacobsen"); msg.setHeader("X-Mailer", "Tov Are's program"); msg.setSentDate(new Date()); SMTPTransport t = (SMTPTransport)session.getTransport("smtps"); t.connect("smtp.gmail.com", "[email protected]", "<insert password here>"); t.sendMessage(msg, msg.getAllRecipients()); System.out.println("Response: " + t.getLastServerResponse()); t.close(); }} Now, do it this way only if you would like to keep your project dependencies to a minimum, otherwise i can warmly recommend using classes from apache http://commons.apache.org/email/ Regards Tov Are Jacobsen | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/73580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2443/"
]
} |
73,629 | I have a string that is like below. ,liger, unicorn, snipe in other languages I'm familiar with I can just do a string.trim(",") but how can I do that in c#? Thanks. There's been a lot of back and forth about the StartTrim function. As several have pointed out, the StartTrim doesn't affect the primary variable. However, given the construction of the data vs the question, I'm torn as to which answer to accept. True the question only wants the first character trimmed off not the last (if anny), however, there would never be a "," at the end of the data. So, with that said, I'm going to accept the first answer that that said to use StartTrim assigned to a new variable. | string sample = ",liger, unicorn, snipe";sample = sample.TrimStart(','); // to remove just the first comma Or perhaps: sample = sample.Trim().TrimStart(','); // to remove any whitespace and then the first comma | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/73629",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/730/"
]
} |
73,663 | How do I exit a script early, like the die() command in PHP? | import syssys.exit() details from the sys module documentation : sys. exit ([ arg ]) Exit from Python. This is implemented by raising the SystemExit exception, so cleanup actions specified by finally clausesof try statements are honored, and it is possible to intercept theexit attempt at an outer level. The optional argument arg can be an integer giving the exit status(defaulting to zero), or another type of object. If it is an integer,zero is considered “successful termination” and any nonzero value isconsidered “abnormal termination” by shells and the like. Most systemsrequire it to be in the range 0-127, and produce undefined resultsotherwise. Some systems have a convention for assigning specificmeanings to specific exit codes, but these are generallyunderdeveloped; Unix programs generally use 2 for command line syntaxerrors and 1 for all other kind of errors. If another type of objectis passed, None is equivalent to passing zero, and any other object isprinted to stderr and results in an exit code of 1. In particular, sys.exit("some error message") is a quick way to exit a program whenan error occurs. Since exit() ultimately “only” raises an exception, it will only exitthe process when called from the main thread, and the exception is notintercepted. Note that this is the 'nice' way to exit. @ glyphtwistedmatrix below points out that if you want a 'hard exit', you can use os._exit(*errorcode*) , though it's likely os-specific to some extent (it might not take an errorcode under windows, for example), and it definitely is less friendly since it doesn't let the interpreter do any cleanup before the process dies. On the other hand, it does kill the entire process, including all running threads, while sys.exit() (as it says in the docs) only exits if called from the main thread, with no other threads running. | {
"score": 12,
"source": [
"https://Stackoverflow.com/questions/73663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1384652/"
]
} |
73,667 | How can I start an interactive console for Perl, similar to the irb command for Ruby or python for Python? | You can use the perl debugger on a trivial program, like so: perl -de1 Alternatively there's Alexis Sukrieh 's Perl Console application, but I haven't used it. | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/73667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5475/"
]
} |
73,686 | #include <iostream>using namespace std;int main(){ double u = 0; double w = -u; cout << w << endl; return 0;} Why does this great piece of code output -0 and not 0 , as one would expect? | The IEEE 754 standard for floating-point numbers has the sign bit separate from the mantissa, which allows for zero to be negative. Wikipedia should be able to help explain this. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/73686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6922/"
]
} |
73,713 | The following will cause infinite recursion on the == operator overload method Foo foo1 = null; Foo foo2 = new Foo(); Assert.IsFalse(foo1 == foo2); public static bool operator ==(Foo foo1, Foo foo2) { if (foo1 == null) return foo2 == null; return foo1.Equals(foo2); } How do I check for nulls? | Use ReferenceEquals : Foo foo1 = null;Foo foo2 = new Foo();Assert.IsFalse(foo1 == foo2);public static bool operator ==(Foo foo1, Foo foo2) { if (object.ReferenceEquals(null, foo1)) return object.ReferenceEquals(null, foo2); return foo1.Equals(foo2);} | {
"score": 8,
"source": [
"https://Stackoverflow.com/questions/73713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12767/"
]
} |
73,751 | I've heard people referring to this table and was not sure what it was about. | It's a sort of dummy table with a single record used for selecting when you're not actually interested in the data, but instead want the results of some system function in a select statement: e.g. select sysdate from dual; See http://www.adp-gmbh.ch/ora/misc/dual.html As of 23c, Oracle supports select sysdate /* or other value */ , without from dual , as has been supported in MySQL for some time already. | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/73751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3208/"
]
} |
73,781 | If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process? Better yet, is there a good library that abstracts the whole 'sendmail -versus- smtp' choice? I'll be running this script on a bunch of unix hosts, only some of which are listening on localhost:25; a few of these are part of embedded systems and can't be set up to accept SMTP. As part of Good Practice, I'd really like to have the library take care of header injection vulnerabilities itself -- so just dumping a string to popen('/usr/bin/sendmail', 'w') is a little closer to the metal than I'd like. If the answer is 'go write a library,' so be it ;-) | Header injection isn't a factor in how you send the mail, it's a factor in how you construct the mail. Check the email package, construct the mail with that, serialise it, and send it to /usr/sbin/sendmail using the subprocess module: import sysfrom email.mime.text import MIMETextfrom subprocess import Popen, PIPEmsg = MIMEText("Here is the body of my message")msg["From"] = "[email protected]"msg["To"] = "[email protected]"msg["Subject"] = "This is the subject."p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)# Both Python 2.X and 3.Xp.communicate(msg.as_bytes() if sys.version_info >= (3,0) else msg.as_string()) # Python 2.Xp.communicate(msg.as_string())# Python 3.Xp.communicate(msg.as_bytes()) | {
"score": 8,
"source": [
"https://Stackoverflow.com/questions/73781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12779/"
]
} |
73,785 | I need to simply go through all the cells in a Excel Spreadsheet and check the values in the cells. The cells may contain text, numbers or be blank. I am not very familiar / comfortable working with the concept of 'Range'. Therefore, any sample codes would be greatly appreciated. (I did try to google it, but the code snippets I found didn't quite do what I needed) Thank you. | If you only need to look at the cells that are in use you can use: sub IterateCells() For Each Cell in ActiveSheet.UsedRange.Cells 'do some stuff NextEnd Sub that will hit everything in the range from A1 to the last cell with data (the bottom right-most cell) | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/73785",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5899/"
]
} |
73,797 | How do I tell Subversion (svn) to treat a file as a binary file? | It is possible to manually identify a file located within a repository as binary by using: svn propset svn:mime-type application/octet-stream <filename> This is generally not necessary, as Subversion will attempt to determine whether a file is binary when the file is first added. If Subversion is incorrectly tagging a certain type as "text" when it should be treated as binary, it is possible to configure Subversion's auto-props feature to automatically tag that file with a non-text MIME type. Regardless of the properties configured on the file, Subversion still stores the file in a binary format within the repository. If Subversion identifies the MIME type as a "text" type, it enables certain features which are not available on binary files, such as svn diff and svn blame . It also allows for automatic line ending conversion, which is configurable on a client-by-client basis. For more information, see How does Subversion handle binary files? | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/73797",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5222/"
]
} |
73,833 | I want to search for files containing DOS line endings with grep on Linux. Something like this: grep -IUr --color '\r\n' . The above seems to match for literal rn which is not what is desired. The output of this will be piped through xargs into todos to convert crlf to lf like this grep -IUrl --color '^M' . | xargs -ifile fromdos 'file' | grep probably isn't the tool you want for this. It will print a line for every matching line in every file. Unless you want to, say, run todos 10 times on a 10 line file, grep isn't the best way to go about it. Using find to run file on every file in the tree then grepping through that for "CRLF" will get you one line of output for each file which has dos style line endings: find . -not -type d -exec file "{}" ";" | grep CRLF will get you something like: ./1/dos1.txt: ASCII text, with CRLF line terminators./2/dos2.txt: ASCII text, with CRLF line terminators./dos.txt: ASCII text, with CRLF line terminators | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/73833",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10245/"
]
} |
73,883 | I understand the difference between String and StringBuilder ( StringBuilder being mutable) but is there a large performance difference between the two? The program I’m working on has a lot of case driven string appends (500+). Is using StringBuilder a better choice? | Yes, the performance difference is significant. See the KB article " How to improve string concatenation performance in Visual C# ". I have always tried to code for clarity first, and then optimize for performance later. That's much easier than doing it the other way around! However, having seen the enormous performance difference in my applications between the two, I now think about it a little more carefully. Luckily, it's relatively straightforward to run performance analysis on your code to see where you're spending the time, and then to modify it to use StringBuilder where needed. | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/73883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12623/"
]
} |
73,889 | What's the best framework for writing modules -- ExtUtils::MakeMaker (h2xs) or Module::Build ? | NOTE This advice is out of date. Module::Build has been removed from the Perl core but lives on as a CPAN module. The pros and cons still stand, and my opinions about MakeMaker still stand. As the former maintainer of ExtUtils::MakeMaker, I like to recommend Module::Build because MakeMaker is a horror show. Module::Build is so much better put together. But those aren't your concerns and I'll present my "least hassle for you" answer. Executive Summary: Because Module::Build support is not 100% in place through all of Perl, start with MakeMaker. If you want to do any customization at all, switch to Module::Build. Since their basic layout, options and interface are almost identical this will be painless. As seductive as it looks, avoid Module::Install. Fortunately, Module::Build can emulate MakeMaker which helps some, but doesn't help if you're going to do any customization. See Module::Build::Compat . For CPAN releases using Module::Build is fine. There's enough Module::Build stuff on CPAN now that everyone's dealt with getting it bootstrapped already. Finally, the new configure_requires option lets CPAN shells know to install Module::Build before they can start building the module. Unfortunately only the latest CPAN shells know about configure_requires. Oh, whatever you do don't use h2xs (unless you're writing XS code... and even then think about it). MakeMaker Pros: Comes with Perl and used by the Perl core (therefore it is activelymaintained and will remain so forever) Everything knows what to do with a Makefile.PL. Most module authoring documentation will cover MakeMaker. Uses make (those who know make can debug and patch the buildprocess) MakeMaker Cons: Requires make (think Windows) Difficult to customize Even harder to customize and make cross platform Difficult to debug when something goes wrong (unless you understand make) Module::Build Pros: Easier to customize/subclass Pure Perl Easier to debug (it's Perl) Can emulate MakeMaker in several ways The CPAN shell will install Module::Build for you Module::Build Cons: The Module::Build maintainers (and indeed all of the Perl Toolchain Gang) hate it Older versions of CPAN clients (including CPANPLUS) don't know anything about Module::Build. Module::Install Pros: Slick interface Bundles itself, you have a known version Everything knows how to deal with a Makefile.PL Module::Install Cons: Requires make Always uses bundled version, vulnerable to external breakage Difficult to customize outside its interface Mucks with the guts of MakeMaker so a new MakeMaker release will eventually break it. Does not know how to generate a META file using the v2 meta-spec(increasingly a problem with newer tools) | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/73889",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8233/"
]
} |
73,947 | I'm talking about an action game with no upper score limit and no way to verify the score on the server by replaying moves etc. What I really need is the strongest encryption possible in Flash/PHP, and a way to prevent people calling the PHP page other than through my Flash file. I have tried some simple methods in the past of making multiple calls for a single score and completing a checksum / fibonacci sequence etc, and also obfuscating the SWF with Amayeta SWF Encrypt, but they were all hacked eventually. Thanks to StackOverflow responses I have now found some more info from Adobe - http://www.adobe.com/devnet/flashplayer/articles/secure_swf_apps_12.html and https://github.com/mikechambers/as3corelib - which I think I can use for the encryption. Not sure this will get me around CheatEngine though. I need to know the best solutions for both AS2 and AS3, if they are different. The main problems seem to be things like TamperData and LiveHTTP headers, but I understand there are more advanced hacking tools as well - like CheatEngine (thanks Mark Webster) | This is a classic problem with Internet games and contests. Your Flash code works with users to decide a score for a game. But users aren't trusted, and the Flash code runs on the user's computer. You're SOL. There is nothing you can do to prevent an attacker from forging high scores: Flash is even easier to reverse engineer than you might think it is, since the bytecodes are well documented and describe a high-level language (Actionscript) --- when you publish a Flash game, you're publishing your source code, whether you know it or not. Attackers control the runtime memory of the Flash interpreter, so that anyone who knows how to use a programmable debugger can alter any variable (including the current score) at any time, or alter the program itself. The simplest possible attack against your system is to run the HTTP traffic for the game through a proxy, catch the high-score save, and replay it with a higher score. You can try to block this attack by binding each high score save to a single instance of the game, for instance by sending an encrypted token to the client at game startup, which might look like: hex-encoding( AES(secret-key-stored-only-on-server, timestamp, user-id, random-number)) (You could also use a session cookie to the same effect). The game code echoes this token back to the server with the high-score save. But an attacker can still just launch the game again, get a token, and then immediately paste that token into a replayed high-score save. So next you feed not only a token or session cookie, but also a high-score-encrypting session key. This will be a 128 bit AES key, itself encrypted with a key hardcoded into the Flash game: hex-encoding( AES(key-hardcoded-in-flash-game, random-128-bit-key)) Now before the game posts the high score, it decrypts the high-score-encrypting-session key, which it can do because you hardcoded the high-score-encrypting-session-key-decrypting-key into the Flash binary. You encrypt the high score with this decrypted key, along with the SHA1 hash of the high score: hex-encoding( AES(random-128-bit-key-from-above, high-score, SHA1(high-score))) The PHP code on the server checks the token to make sure the request came from a valid game instance, then decrypts the encrypted high score, checking to make sure the high-score matches the SHA1 of the high-score (if you skip this step, decryption will simply produce random, likely very high, high scores). So now the attacker decompiles your Flash code and quickly finds the AES code, which sticks out like a sore thumb, although even if it didn't it'd be tracked down in 15 minutes with a memory search and a tracer ("I know my score for this game is 666, so let's find 666 in memory, then catch any operation that touches that value --- oh look, the high score encryption code!"). With the session key, the attacker doesn't even have to run the Flash code; she grabs a game launch token and a session key and can send back an arbitrary high score. You're now at the point where most developers just give up --- give or take a couple months of messing with attackers by: Scrambling the AES keys with XOR operations Replacing key byte arrays with functions that calculate the key Scattering fake key encryptions and high score postings throughout the binary. This is all mostly a waste of time. It goes without saying, SSL isn't going to help you either; SSL can't protect you when one of the two SSL endpoints is evil. Here are some things that can actually reduce high score fraud: Require a login to play the game, have the login produce a session cookie, and don't allow multiple outstanding game launches on the same session, or multiple concurrent sessions for the same user. Reject high scores from game sessions that last less than the shortest real games ever played (for a more sophisticated approach, try "quarantining" high scores for game sessions that last less than 2 standard deviations below the mean game duration). Make sure you're tracking game durations serverside. Reject or quarantine high scores from logins that have only played the game once or twice, so that attackers have to produce a "paper trail" of reasonable looking game play for each login they create. "Heartbeat" scores during game play, so that your server sees the score growth over the lifetime of one game play. Reject high scores that don't follow reasonable score curves (for instance, jumping from 0 to 999999). "Snapshot" game state during game play (for instance, amount of ammunition, position in the level, etc), which you can later reconcile against recorded interim scores. You don't even have to have a way to detect anomalies in this data to start with; you just have to collect it, and then you can go back and analyze it if things look fishy. Disable the account of any user who fails one of your security checks (for instance, by ever submitting an encrypted high score that fails validation). Remember though that you're only deterring high score fraud here. There's nothing you can do to prevent if. If there's money on the line in your game, someone is going to defeat any system you come up with. The objective isn't to stop this attack; it's to make the attack more expensive than just getting really good at the game and beating it. | {
"score": 10,
"source": [
"https://Stackoverflow.com/questions/73947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11911/"
]
} |
73,960 | In IE, the dropdown-list takes the same width as the dropbox (I hope I am making sense) whereas in Firefox the dropdown-list's width varies according to the content. This basically means that I have to make sure that the dropbox is wide enough to display the longest selection possible. This makes my page look very ugly :( Is there any workaround for this problem? How can I use CSS to set different widths for dropbox and the dropdownlist? | Here's another jQuery based example. In contrary to all the other answers posted here, it takes all keyboard and mouse events into account, especially clicks: if (!$.support.leadingWhitespace) { // if IE6/7/8 $('select.wide') .bind('focus mouseover', function() { $(this).addClass('expand').removeClass('clicked'); }) .bind('click', function() { $(this).toggleClass('clicked'); }) .bind('mouseout', function() { if (!$(this).hasClass('clicked')) { $(this).removeClass('expand'); }}) .bind('blur', function() { $(this).removeClass('expand clicked'); });} Use it in combination with this piece of CSS: select { width: 150px; /* Or whatever width you want. */}select.expand { width: auto;} All you need to do is to add the class wide to the dropdown element(s) in question. <select class="wide"> ...</select> Here is a jsfiddle example . Hope this helps. | {
"score": 8,
"source": [
"https://Stackoverflow.com/questions/73960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/747/"
]
} |
73,964 | I would like to turn the HTML generated by my CFM page into a PDF, and have the user prompted with the standard "Save As" prompt when navigating to my page. | You should use the cfdocument tag (with format="PDF") to generate the PDF by placing it around the page you are generating. You'll want to specify a filename attribute, otherwise the document will just stream right to your browser. After you have saved the content as a PDF, use cfheader and cfcontent in combination to output the PDF as an attachment ("Save As") and add the file to the response stream. I also added deletefile="Yes" on the cfcontent tag to keep the file system clean of the files. <cfdocument format="PDF" filename="file.pdf" overwrite="Yes"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <title>Hello World</title></head><body> Hello World</body></html></cfdocument><cfheader name="Content-Disposition" value="attachment;filename=file.pdf"><cfcontent type="application/octet-stream" file="#expandPath('.')#\file.pdf" deletefile="Yes"> As an aside: I'm just using file.pdf for the filename in the example below, but you might want to use some random or session generated string for the filename to avoid problems resulting from race conditions. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/73964",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2232/"
]
} |
73,971 | In JavaScript, what is the best way to determine if a date provided falls within a valid range? An example of this might be checking to see if the user input requestedDate is part of the next valid work week. Note that this is not just checking to see if one date is larger than another as a valid date would be equal to or greater than the lower end of the range while less than or equal to the upper end of the range. | This is actually a problem that I have seen come up before a lot in my works and the following bit of code is my answer to the problem. // checkDateRange - Checks to ensure that the values entered are dates and // are of a valid range. By this, the dates must be no more than the // built-in number of days appart.function checkDateRange(start, end) { // Parse the entries var startDate = Date.parse(start); var endDate = Date.parse(end); // Make sure they are valid if (isNaN(startDate)) { alert("The start date provided is not valid, please enter a valid date."); return false; } if (isNaN(endDate)) { alert("The end date provided is not valid, please enter a valid date."); return false; } // Check the date range, 86400000 is the number of milliseconds in one day var difference = (endDate - startDate) / (86400000 * 7); if (difference < 0) { alert("The start date must come before the end date."); return false; } if (difference <= 1) { alert("The range must be at least seven days apart."); return false; } return true;} Now a couple things to note about this code, the Date.parse function should work for most input types, but has been known to have issues with some formats such as "YYYY MM DD" so you should test that before using it. However, I seem to recall that most browsers will interpret the date string given to Date.parse based upon the computers region settings. Also, the multiplier for 86400000 should be whatever the range of days you are looking for is. So if you are looking for dates that are at least one week apart then it should be seven. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/73971",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1185/"
]
} |
73,972 | I have somehow misconfigured fingers. This leads to a very annoying situation. I select a block of text to copy; I move the cursor the place where I want to paste the code; I accidentally press Ctrl+C again instead of Ctrl+V; My block of copied text is replaced by an empty block; I have to go back and do it all over again. Grrrrr. Is there any way to disable this behavior, that is to disable copy of empty blocks of text in Visual Studio 2005+? | It's not copying an empty block, it's copying the blank line. You can change this setting in Tools > Options > Text Editor > All Languages > 'Apply Cut or Copy Commands to blank lines when there is no selection' | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/73972",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6508/"
]
} |
74,010 | I am a bit rusty on my cursor lingo in PL/SQL. Anyone know this? | An implicit cursor is one created "automatically" for you by Oracle when you execute a query. It is simpler to code, but suffers from inefficiency (the ANSI standard specifies that it must fetch twice to check if there is more than one record) vulnerability to data errors (if you ever get two rows, it raises a TOO_MANY_ROWS exception) Example SELECT col INTO var FROM table WHERE something; An explicit cursor is one you create yourself. It takes more code, but gives more control - for example, you can just open-fetch-close if you only want the first record and don't care if there are others. Example DECLARE CURSOR cur IS SELECT col FROM table WHERE something; BEGIN OPEN cur; FETCH cur INTO var; CLOSE cur;END; | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/74010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3208/"
]
} |
74,019 | How can I specify the filename when dumping data into the response stream? Right now I'm doing the following: byte[] data= GetFoo();Response.Clear();Response.Buffer = true;Response.ContentType = "application/pdf"; Response.BinaryWrite(data);Response.End(); With the code above, I get "foo.aspx.pdf" as the filename to save. I seem to remember being able to add a header to the response to specify the filename to save. | Add a content-disposition to the header: Response.AddHeader("content-disposition", @"attachment;filename=""MyFile.pdf"""); | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/74019",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1672/"
]
} |
74,092 | I have a function in Python which is iterating over the attributes returned from dir(obj) , and I want to check to see if any of the objects contained within is a function, method, built-in function, etc. Normally you could use callable() for this, but I don't want to include classes. The best I've come up with so far is: isinstance(obj, (types.BuiltinFunctionType, types.FunctionType, types.MethodType)) Is there a more future-proof way to do this check? Edit: I misspoke before when I said: "Normally you could use callable() for this, but I don't want to disqualify classes." I actually do want to disqualify classes. I want to match only functions, not classes. | The inspect module has exactly what you want: inspect.isroutine( obj ) FYI, the code is: def isroutine(object): """Return true if the object is any kind of function or method.""" return (isbuiltin(object) or isfunction(object) or ismethod(object) or ismethoddescriptor(object)) | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74092",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/156/"
]
} |
74,113 | It seems obvious that some people have been able to figure out how to access the iPhone camera through the SDK (Spore Origins, for example). How can this be done? | You need to use the UIImagePickerController class, basically: UIImagePickerController *picker = [[UIImagePickerController alloc] init];picker.delegate = pickerDelegatepicker.sourceType = UIImagePickerControllerSourceTypeCamera The pickerDelegate object above needs to implement the following method: - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info The dictionary info will contain entries for the original, and the edited image, keyed with UIImagePickerControllerOriginalImage and UIImagePickerControllerEditedImage respectively. (see https://developer.apple.com/documentation/uikit/uiimagepickercontrollerdelegate and https://developer.apple.com/documentation/uikit/uiimagepickercontrollerinfokey for more details) | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/74113",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5338/"
]
} |
74,148 | How do you convert between hexadecimal numbers and decimal numbers in C#? | To convert from decimal to hex do... string hexValue = decValue.ToString("X"); To convert from hex to decimal do either... int decValue = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber); or int decValue = Convert.ToInt32(hexValue, 16); | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/74148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3362/"
]
} |
74,162 | I'm trying to write a query that extracts and transforms data from a table and then insert those data into another table. Yes, this is a data warehousing query and I'm doing it in MS Access. So basically I want some query like this: INSERT INTO Table2(LongIntColumn2, CurrencyColumn2) VALUES (SELECT LongIntColumn1, Avg(CurrencyColumn) as CurrencyColumn1 FROM Table1 GROUP BY LongIntColumn1); I tried but get a syntax error message. What would you do if you want to do this? | No "VALUES", no parenthesis: INSERT INTO Table2(LongIntColumn2, CurrencyColumn2)SELECT LongIntColumn1, Avg(CurrencyColumn) as CurrencyColumn1 FROM Table1 GROUP BY LongIntColumn1; | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/74162",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8203/"
]
} |
74,267 | I'm trying to script the shutdown of my VM Servers in a .bat.if one of the vmware-cmd commands fails (as the machine is already shutdown say), I'd like it to continue instead of bombing out. c:cd "c:\Program Files\VMWare\VmWare Server"vmware-cmd C:\VMImages\TCVMDEVSQL01\TCVMDEVSQL01.vmx suspend soft -qvmware-cmd C:\VMImages\DevEnv\DevEnv\DevEnv.vmx suspend soft -qvmware-cmd C:\VMImages\DevEnv\TCVMDEV02\TCVMDEV02.vmx suspend soft =qrobocopy c:\vmimages\ \\tcedilacie1tb\VMShare\DevEnvironmentBackups\ /mir /z /r:0 /w:0vmware-cmd C:\VMImages\TCVMDEVSQL01\TCVMDEVSQL01.vmx startvmware-cmd C:\VMImages\DevEnv\DevEnv\DevEnv.vmx start vmware-cmd C:\VMImages\DevEnv\TCVMDEV02\TCVMDEV02.vmx start | Run it inside another command instance with CMD /C CMD /C vmware-cmd C:\... This should keep the original BAT files running. | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/74267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11538/"
]
} |
74,269 | I have a DataGrid, populated with objects in an ArrayCollection. After updating one of the objects' fields, I want the screen to update. The data source is not bindable, because I'm constructing it at runtime (and I don't understand how to make it bindable on the fly yet -- that's another question). In this situation, if I call InvalidateDisplayList() on the grid nothing seems to happen. But if I call invalidateList(), the updates happen. (And it's very smooth too -- no flicker like I would expect from invalidating a window in WIN32.) So the question: what is the difference between InvalidateList and InvalidateDisplayList? From the documentation it seems like either one should work. | invalidateList tells the component that the data has changed, and it needs to reload it and re-render it. invalidateDisplayList tells the component that it needs to redraw itself (but not necessarily reload its data). | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74269",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4540/"
]
} |
74,326 | I am working on a large C++ project in Visual Studio 2008, and there are a lot of files with unnecessary #include directives. Sometimes the #include s are just artifacts and everything will compile fine with them removed, and in other cases classes could be forward declared and the #include could be moved to the .cpp file. Are there any good tools for detecting both of these cases? | While it won't reveal unneeded include files, Visual studio has a setting /showIncludes (right click on a .cpp file, Properties->C/C++->Advanced ) that will output a tree of all included files at compile time. This can help in identifying files that shouldn't need to be included. You can also take a look at the pimpl idiom to let you get away with fewer header file dependencies to make it easier to see the cruft that you can remove. | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/74326",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13013/"
]
} |
74,358 | How can I get LWP to verify that the certificate of the server I'm connecting to is signed by a trusted authority and issued to the correct host? As far as I can tell, it doesn't even check that the certificate claims to be for the hostname I'm connecting to. That seems like a major security hole (especially with the recent DNS vulnerabilities). Update: It turns out what I really wanted was HTTPS_CA_DIR , because I don't have a ca-bundle.crt. But HTTPS_CA_DIR=/usr/share/ca-certificates/ did the trick. I'm marking the answer as accepted anyway, because it was close enough. Update 2: It turns out that HTTPS_CA_DIR and HTTPS_CA_FILE only apply if you're using Net::SSL as the underlying SSL library. But LWP also works with IO::Socket::SSL, which will ignore those environment variables and happily talk to any server, no matter what certificate it presents. Is there a more general solution? Update 3: Unfortunately, the solution still isn't complete. Neither Net::SSL nor IO::Socket::SSL is checking the host name against the certificate. This means that someone can get a legitimate certificate for some domain, and then impersonate any other domain without LWP complaining. Update 4: LWP 6.00 finally solves the problem. See my answer for details. | This long-standing security hole has finally been fixed in version 6.00 of libwww-perl . Starting with that version, by default LWP::UserAgent verifies that HTTPS servers present a valid certificate matching the expected hostname (unless $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} is set to a false value or, for backwards compatibility if that variable is not set at all, either $ENV{HTTPS_CA_FILE} or $ENV{HTTPS_CA_DIR} is set). This can be controlled by the new ssl_opts option of LWP::UserAgent. See that link for details on how the Certificate Authority certificates are located. But be careful , the way LWP::UserAgent used to work, if you provide a ssl_opts hash to the constructor, then verify_hostname defaulted to 0 instead of 1. ( This bug was fixed in LWP 6.03.) To be safe, always specify verify_hostname => 1 in your ssl_opts . So use LWP::UserAgent 6; should be sufficient to have server certificates validated. | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/74358",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8355/"
]
} |
74,385 | I need to convert a value which is in a DateTime variable into a varchar variable formatted as yyyy-mm-dd format (without time part). How do I do that? | With Microsoft Sql Server: ---- Create test case--DECLARE @myDateTime DATETIMESET @myDateTime = '2008-05-03'---- Convert string--SELECT LEFT(CONVERT(VARCHAR, @myDateTime, 120), 10) | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/74385",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7604/"
]
} |
74,430 | I am trying to use the import random statement in python, but it doesn't appear to have any methods in it to use. Am I missing something? | You probably have a file named random.py or random.pyc in your working directory. That's shadowing the built-in random module. You need to rename random.py to something like my_random.py and/or remove the random.pyc file. To tell for sure what's going on, do this: >>> import random>>> print random.__file__ That will show you exactly which file is being imported. | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/74430",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13050/"
]
} |
74,466 | I have a .ico file that is embedded as a resource (build action set to resource). I am trying to create a NotifyIcon. How can I reference my icon? notifyIcon = new NotifyIcon();notifyIcon.Icon = ?? // my icon file is called MyIcon.ico and is embedded | Your icon file should be added to one of your project assemblies and its Build Action should be set to Resource. After adding a reference to the assembly, you can create a NotifyIcon like this: System.Windows.Forms.NotifyIcon icon = new System.Windows.Forms.NotifyIcon();Stream iconStream = Application.GetResourceStream( new Uri( "pack://application:,,,/YourReferencedAssembly;component/YourPossibleSubFolder/YourResourceFile.ico" )).Stream;icon.Icon = new System.Drawing.Icon( iconStream ); | {
"score": 8,
"source": [
"https://Stackoverflow.com/questions/74466",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047/"
]
} |
74,471 | I have a function that takes, amongst others, a parameter declared as int privateCount . When I want to call ToString() on this param, ReSharper greys it out and marks it as a redundant call. So, curious as I am, I remove the ToString(), and the code still builds! How can a C# compiler allow this, where str is a string? str += privateCount + ... | The + operator for string is overloaded to call String.Concat passing in the left and right side of the expression. Thus: string x = "123" + 45; Gets compiled to: String.Concat("123", 45); Since String.Concat takes in two objects, the right hand side (45) is boxed and then ToString() is called on it. Note that this "overloading" is not via operator overloading in the language (aka it's not a method named op_Addition) but is handled by the compiler. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74471",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8741/"
]
} |
74,484 | We distribute an application that uses an MS Access .mdb file. Somebody has noticed that after opening the file in MS Access the file size shrinks a lot. That suggests that the file is a good candidate for compacting, but we don't supply the means for our users to do that. So, my question is, does it matter? Do we care? What bad things can happen if our users never compact the database? | In addition to making your database smaller, it'll recompute the indexes on your tables and defragment your tables which can make access faster. It'll also find any inconsistencies that should never happen in your database, but might, due to bugs or crashes in Access. It's not totally without risk though -- a bug in Access 2007 would occasionally delete your database during the process. So it's generally a good thing to do, but pair it with a good backup routine. With the backup in place, you can also recover from any 'unrecoverable' compact and repair problems with a minimum of data loss. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9328/"
]
} |
74,519 | I would like to use the 7-Zip DLLs from Delphi but have not been able to find decent documentation or examples. Does anyone know how to use the 7-Zip DLLs from Delphi? | As of release 1.102 the JEDI Code Library has support for 7-Zip built into the JclCompression unit. Haven't used it myself yet, though. | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/74519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13054/"
]
} |
74,521 | Does anyone have details in setting up Qt4 in Visual Studio 2008? Links to other resources would be appreciated as well. I already know that the commercial version of Qt has applications to this end. I also realize that I'll probably need to compile from source as the installer for the open source does not support Visual Studio and installs Cygwin. | As of release 1.102 the JEDI Code Library has support for 7-Zip built into the JclCompression unit. Haven't used it myself yet, though. | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/74521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11994/"
]
} |
74,526 | In Team Foundation Server, I know that you can use the Annotate feature to see who last edited each line in a particular file (equivalent to "Blame" in CVS). What I'd like to do is akin to running Annotate on every file in a project, and get a summary report of all the developers who have edited a file in the project, and how many lines of code they currently "own" in that project. Aside from systematically running Annotate of each file, I can't see a way to do this. Any ideas that would make this process faster? PS - I'm doing to this to see how much of a consultant's code still remains in a particular (rather large) project, not to keep tabs on my developers, in case you're worried about my motivation :) | It's easy enough to use the "tf.exe history" command recursively across a directory of files in TFS. This will tell you who changed what files. However what you're after is a little bit more than this - you want to know if the latest versions of any files have lines written by a particular user. The Team Foundation Power Tools ship with a command-line version of annotate called "tfpt.exe annotate". This has a /noprompt option to direct the output to the console, but it only outputs the changeset id - not the user name. You could also use the TFS VersionControl object model to write a tool that does exactly what you need. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74526",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8114/"
]
} |
74,612 | I have a table inside a div. I want the table to occupy the entire width of the div tag. In the CSS, I've set the width of the table to 100% . Unfortunately, when the div has some margin on it, the table ends up wider than the div it's in. I need to support IE6 and IE7 (as this is an internal app), although I'd obviously like a fully cross-browser solution if possible! I'm using the following DOCTYPE... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Edit : Unfortunately I can't hard-code the width as I'm dynamically generating the HTML and it includes nesting the divs recursively inside each other (with left margin on each div, this creates a nice 'nested' effect). | Add the below CSS to your <table> : table-layout: fixed;width: 100%; | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/475/"
]
} |
74,616 | example: public static void DoSomething<K,V>(IDictionary<K,V> items) { items.Keys.Each(key => { if (items[key] **is IEnumerable<?>**) { /* do something */ } else { /* do something else */ }} Can this be done without using reflection? How do I say IEnumerable in C#? Should I just use IEnumerable since IEnumerable<> implements IEnumerable? | Thanks very much for this post. I wanted to provide a version of Konrad Rudolph's solution that has worked better for me. I had minor issues with that version, notably when testing if a Type is a nullable value type: public static bool IsAssignableToGenericType(Type givenType, Type genericType){ var interfaceTypes = givenType.GetInterfaces(); foreach (var it in interfaceTypes) { if (it.IsGenericType && it.GetGenericTypeDefinition() == genericType) return true; } if (givenType.IsGenericType && givenType.GetGenericTypeDefinition() == genericType) return true; Type baseType = givenType.BaseType; if (baseType == null) return false; return IsAssignableToGenericType(baseType, genericType);} | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/74616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12934/"
]
} |
74,620 | Can't understand why the following takes place: String date = "06-04-2007 07:05";SimpleDateFormat fmt = new SimpleDateFormat("MM-dd-yyyy HH:mm");Date myDate = fmt.parse(date); System.out.println(myDate); //Mon Jun 04 07:05:00 EDT 2007long timestamp = myDate.getTime();System.out.println(timestamp); //1180955100000 -- where are the milliseconds?// on the other hand...myDate = new Date();System.out.println(myDate); //Tue Sep 16 13:02:44 EDT 2008timestamp = myDate.getTime();System.out.println(timestamp); //1221584564703 -- why, oh, why? | What milliseconds? You are providing only minutes information in the first example, whereas your second example grabs current date from the system with milliseconds, what is it you're looking for? String date = "06-04-2007 07:05:00.999";SimpleDateFormat fmt = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss.S");Date myDate = fmt.parse(date);System.out.println(myDate); long timestamp = myDate.getTime();System.out.println(timestamp); | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74620",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10675/"
]
} |
74,625 | A good while ago, I read an article by the creator of viemu , clearing up a lot of the misconceptions about vi, as well as explaining why it's a good idea (and why it's been very popular for the last 30 years+). The same guy also has a great set of graphical cheat sheets that teach the basics a few bits at a time. I'm convinced. I've been convinced for the past 2 years in fact. But I still really haven't gotten around to force myself to learn vi as my primary editor, the learning curve is just too high. When I get down to work, acceptable but immediate productivity (using my current editor) has so far won over tremendous productivity farther down the line (using vi). Does anybody have any good tips to help get past the learning curve? It can be straight out tips, some other tutorial or article, whatever. Edit: Note that I'm aware of the vim/gVim , Cream and MacVim (etc.) variants of vi. I kept my question about vi to refer to the vi family as a whole. Thanks for all the great answers. Update (April 2009) I've been using Vim (more precisely, MacVim) in my day to day professional life since last December. I'm not going back :-) Good luck to everyone in their Vim mastery. | First of all, you may want to pick up Vim; it has a vastly superior feature set along with everything vi has. That said, it takes discipline to learn. If you have a job and can't afford the productivity hit (without getting fired), I'd suggest taking on a weekend project for the sole purpose of learning the editor. Keep its documentation open as you work, and be disciplined enough not to chicken out. As you learn more, become efficient and start relying on muscle memory, it won't be as hard to stick with it. I've been using Vim for so long that I don't even think about what keys to press to search or navigate or save. And my hands never leave the keyboard. To use Vim is one of the best choices I've made in my programming career. | {
"score": 8,
"source": [
"https://Stackoverflow.com/questions/74625",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6349/"
]
} |
74,626 | I have a CIFS share mounted on a Linux machine. The CIFS server is down, or the internet connection is down, and anything that touches the CIFS mount now takes several minutes to timeout, and is unkillable while you wait. I can't even run ls in my home directory because there is a symlink pointing inside the CIFS mount and ls tries to follow it to decide what color it should be. If I try to umount it (even with -fl), the umount process hangs just like ls does. Not even sudo kill -9 can kill it. How can I force the kernel to unmount? | I use lazy unmount: umount -l (that's a lowercase L ) Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.) | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/74626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10168/"
]
} |
74,674 | I need to check CPU and memory usage for the server in java, anyone know how it could be done? | If you are looking specifically for memory in JVM: Runtime runtime = Runtime.getRuntime();NumberFormat format = NumberFormat.getInstance();StringBuilder sb = new StringBuilder();long maxMemory = runtime.maxMemory();long allocatedMemory = runtime.totalMemory();long freeMemory = runtime.freeMemory();sb.append("free memory: " + format.format(freeMemory / 1024) + "<br/>");sb.append("allocated memory: " + format.format(allocatedMemory / 1024) + "<br/>");sb.append("max memory: " + format.format(maxMemory / 1024) + "<br/>");sb.append("total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) + "<br/>"); However, these should be taken only as an estimate... | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/74674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13123/"
]
} |
74,690 | I have a QMainWindow in a Qt application. When I close it I want it to store its current restore size (the size of the window when it is not maximized). This works well when I close the window in restore mode (that is, not maximized). But if I close the window if it is maximized, then next time i start the application and restore the application (because it starts in maximized mode), then it does not remember the size it should restore to. Is there a way to do this? | Use the QWidget::saveGeometry feature to write the current settings into the registry.(The registry is accessed using QSettings). Then use restoreGeometry() upon startup to return to the previous state. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1585/"
]
} |
74,723 | This problem has been afflicting me for quite a while and it's been really annoying. Every time I login after a reboot/power cycle the explorer takes some time to show up.I've taken the step of waiting for all the services to boot up and then I login, but it doesn't make any difference.The result is always the same: Some of the icons do not show up even if the applications have started. I've dug a bit on the code that makes one application "stick" an icon in there, but is there an API call that one can perform so explorer re-reads all that icon info? Like invalidate or redraw or something of the sort? Apparently, it looks like Jon was right and it's not possible to do it. I've followed Bob Dizzle and Mark Ransom code and build this (Delphi Code): procedure Refresh;var hSysTray: THandle;begin hSysTray := GetSystrayHandle; SendMessage(hSysTray, WM_PAINT, 0, 0);end;function GetSystrayHandle: THandle;var hTray, hNotify, hSysPager: THandle;begin hTray := FindWindow('Shell_TrayWnd', ''); if hTray = 0 then begin Result := hTray; exit; end; hNotify := FindWindowEx(hTray, 0, 'TrayNotifyWnd', ''); if hNotify = 0 then begin Result := hNotify; exit; end; hSyspager := FindWindowEx(hNotify, 0, 'SysPager', ''); if hSyspager = 0 then begin Result := hSyspager; exit; end; Result := FindWindowEx(hSysPager, 0, 'ToolbarWindow32', 'Notification Area');end; But to no avail. I've even tried with InvalidateRect() and still no show. Any other suggestions? | Take a look at this blog entry: REFRESHING THE TASKBAR NOTIFICATION AREA . I am using this code to refresh the system tray to get rid of orphaned icons and it works perfectly.The blog entry is very informative and gives a great explanation of the steps the author performed to discover his solution. #define FW(x,y) FindWindowEx(x, NULL, y, L"")void RefreshTaskbarNotificationArea(){ HWND hNotificationArea; RECT r; GetClientRect( hNotificationArea = FindWindowEx( FW(FW(FW(NULL, L"Shell_TrayWnd"), L"TrayNotifyWnd"), L"SysPager"), NULL, L"ToolbarWindow32", // L"Notification Area"), // Windows XP L"User Promoted Notification Area"), // Windows 7 and up &r); for (LONG x = 0; x < r.right; x += 5) for (LONG y = 0; y < r.bottom; y += 5) SendMessage( hNotificationArea, WM_MOUSEMOVE, 0, (y << 16) + x);} | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8167/"
]
} |
74,829 | What should I type on the Mac OS X terminal to run a script as root? | As in any unix-based environment, you can use the sudo command: $ sudo script-name It will ask for your password (your own, not a separate root password). | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/74829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/877/"
]
} |
74,844 | I am not new to *nix, however lately I have been spending a lot of time at the prompt. My question is what are the advantages of using KornShell (ksh) or Bash Shell? Where are the pitfalls of using one over the other? Looking to understand from the perspective of a user, rather than purely scripting. | Bash. The various UNIX and Linux implementations have various different source level implementations of ksh, some of which are real ksh, some of which are pdksh implementations and some of which are just symlinks to some other shell that has a "ksh" personality. This can lead to weird differences in execution behavior. At least with bash you can be sure that it's a single code base, and all you need worry about is what (usually minimum) version of bash is installed. Having done a lot of scripting on pretty much every modern (and not-so-modern) UNIX, programming to bash is more reliably consistent in my experience. | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/74844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13158/"
]
} |
74,847 | Typically I use E_ALL to see anything that PHP might say about my code to try and improve it. I just noticed a error constant E_STRICT , but have never used or heard about it, is this a good setting to use for development? The manual says: Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. So I'm wondering if I'm using the best error_reporting level with E_ALL or would that along with E_STRICT be the best? Or is there any other combination I've yet to learn? | In PHP 5, the things covered by E_STRICT are not covered by E_ALL , so to get the most information, you need to combine them: error_reporting(E_ALL | E_STRICT); In PHP 5.4, E_STRICT will be included in E_ALL , so you can use just E_ALL . You can also use error_reporting(-1); which will always enable all errors. Which is more semantically correct as: error_reporting(~0); | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/74847",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5261/"
]
} |
74,865 | I recently was working with a subversion project that checked out code not only from the repository I was working with, but also from a separate repository on a different server. How can I configure my repository to do this? I'm using the subversion client version 1.3.2 on Linux, and I also have access to TortoiseSVN version 1.4.8 (built on svn version 1.4.6) in Windows. | See svn:externals : Sometimes it is useful to construct a working copy that is made out of a number of different checkouts. For example, you may want different subdirectories to come from different locations in a repository, or perhaps from different repositories altogether. You could certainly setup such a scenario by hand—using svn checkout to create the sort of nested working copy structure you are trying to achieve. But if this layout is important for everyone who uses your repository, every other user will need to perform the same checkout operations that you did. Fortunately, Subversion provides support for externals definitions . An externals definition is a mapping of a local directory to the URL—and possibly a particular revision—of a versioned resource. In Subversion, you declare externals definitions in groups using the svn:externals property. You can create or modify this property using svn propset or svn propedit (see the section called “Why Properties?” ). It can be set on any versioned directory, and its value is a multi-line table of subdirectories (relative to the versioned directory on which the property is set) and fully qualified, absolute Subversion repository URLs... | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7154/"
]
} |
74,879 | I am looking for a tool which will take an XML instance document and output a corresponding XSD schema. I certainly recognize that the generated XSD schema will be limited when compared to creating a schema by hand (it probably won't handle optional or repeating elements, or data constraints), but it could at least serve as a quick starting point. | the Microsoft XSD inference tool is a good, free solution. Many XML editing tools, such as XmlSpy (mentioned by @Garth Gilmour) or OxygenXML Editor also have that feature. They're rather expensive, though. BizTalk Server also has an XSD inferring tool as well. edit: I just discovered the .net XmlSchemaInference class, so if you're using .net you should consider that | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/74879",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/863/"
]
} |
74,880 | Conceptually, I would like to accomplish the following but have had trouble understand how to code it properly in C#: SomeMethod { // Member of AClass{} DoSomething; Start WorkerMethod() from BClass in another thread; DoSomethingElse;} Then, when WorkerMethod() is complete, run this: void SomeOtherMethod() // Also member of AClass{}{ ... } Can anyone please give an example of that? | The BackgroundWorker class was added to .NET 2.0 for this exact purpose. In a nutshell you do: BackgroundWorker worker = new BackgroundWorker();worker.DoWork += delegate { myBClass.DoHardWork(); }worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(SomeOtherMethod);worker.RunWorkerAsync(); You can also add fancy stuff like cancellation and progress reporting if you want :) | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10505/"
]
} |
74,892 | The JPEG compression encoding process splits a given image into blocks of 8x8 pixels, working with these blocks in future lossy and lossless compressions. [source] It is also mentioned that if the image is a multiple 1MCU block (defined as a Minimum Coded Unit, 'usually 16 pixels in both directions') that lossless alterations to a JPEG can be performed. [source] I am working with product images and would like to know both if, and how much benefit can be derived from using multiples of 16 in my final image size (say, using an image with size 480px by 360px) vs. a non-multiple of 16 (such as 484x362). In this example I am not interested in further alterations, editing, or recompression of the final image. To try to get closer to a specific answer where I know there must be largely generalities: Given a 480x360 image that is 64k and saved at maximum quality in Photoshop [example] : Can I expect any quality loss from an image that is 484x362 What amount of file size addition can I expect (for this example, the additional space would be white pixels) Are there any other disadvantages to growing larger than the 8px grid? I know it's arbitrary to use that specific example, but it would still be helpful (for me and potentially any others pondering an image size) to understand what level of compromise I'd be dealing with in breaking the non-8px grid. The key issue here is a debate I've had is whether 8-pixel divisible images are higher quality than images that are not divisible by 8-pixels. | 8 pixels is the cutoff. The reason is because JPEG images are simply an array of 8x8 DCT blocks; if the image resolution isn't mod8 in both directions, the encoder has to pad the sides up to the next mod8 resolution. This in practice is not very expensive bit-wise; what's much worse are the cases when an image has sharp black lines (such as a letterboxed image) that don't lie on block boundaries. This is especially problematic in video encoding. The reason for this being a problem is that the frequency transform of a sharp line is a Gaussian distribution of coefficients--resulting in an enormous number of bits to code. For those curious, the most common method of padding edges in intra compression (such as JPEG images) is to mirror the lines of pixels before the edge. For example, if you need to pad three lines and line X is the edge, line X+1 is equal to line X, line X+2 is equal to line X-1, and line X+3 is equal to line X-2. This quite effectively minimizes the cost in transform coefficients of the extra lines. In inter coding, however, the padding algorithms generally simply duplicate the last line, because the mirror method does not work well for inter compression, such as in video compression. | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/74892",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2486915/"
]
} |
74,902 | I installed Mono on my iMac last night and I immidiately had a change of heart! I don't think Mono is ready for prime time. The Mono website says to run the following script to uninstall: #!/bin/sh -x#This script removes Mono from an OS X System. It must be run as rootrm -r /Library/Frameworks/Mono.frameworkrm -r /Library/Receipts/MonoFramework-SVN.pkgcd /usr/binfor i in `ls -al | grep Mono | awk '{print $9}'`; dorm ${i}done Has anyone had to uninstall Mono? Was it as straight forward as running the above script or do I have to do more? How messy was it? Any pointers are appreciated. | The above script simply deletes everything related to Mono on your system -- and since the developers wrote it, I'm sure they didn't miss anything :) Unlike some other operating systems made by software companies that rhyme with "Macrosoft", uninstalling software in OS X is as simple as deleting the files, 99% of the time.. no registry or anything like that. So, long story short, yes, that script is probably the only thing you need to do. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/877/"
]
} |
74,957 | In PowerShell I'm reading in a text file. I'm then doing a Foreach-Object over the text file and am only interested in the lines that do NOT contain strings that are in $arrayOfStringsNotInterestedIn . What is the syntax for this? Get-Content $filename | Foreach-Object {$_} | If $arrayofStringsNotInterestedIn is an [array] you should use -notcontains: Get-Content $FileName | foreach-object { ` if ($arrayofStringsNotInterestedIn -notcontains $_) { $) } or better (IMO) Get-Content $FileName | where { $arrayofStringsNotInterestedIn -notcontains $_} | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/74957",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1463/"
]
} |
74,986 | I'm developing a .NET 3.5 XBAP application that runs perfectly fine in FF3 and IE6/7 etc. I'm just wondering if its possible to get these to run under other browsers, specifically (as its in the limelight at the moment) Google Chrome. | XBAP applications do work in google chrome, however you have to set your environments PATH variable to the directory where xpcom.dll is located. for example SET PATH=PATH;"C:\Program Files\Mozilla Firefox" | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/74986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5777/"
]
} |
75,001 | As popular as Ruby and Rails are, it seems like this problem would already be solved. JRuby and mod_rails are all fine and dandy, but why isn't there an Apache mod for just straight Ruby? | There is Phusion Passenger , a robust Apache module that can run Rack applications with minimum configuration. It's becoming appealing to shared hosts, and turning any program into a Rack application is ridiculously easy: A Rack application is an Ruby object (not a class) that responds to call . It takes exactly one argument , the environment and returns an Array of exactly three values : The status, the headers, and the body. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75001",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6726/"
]
} |
75,064 | I know something about Java but completely new to Enterprise Java. I'm trying my hand with NetBeans 6.1 and GlassFish Application Server. Please guide me to some resources which tell me actually what java enterprise applications are, how they are different from normal java classes etc. Also which is the best application server to use (on Linux)? | "what java enterprise applications are, how they are different from normal java classes etc" Well they are normal classes. They are ran by an application server. The "application server" is often just a JVM , but sometimes enhanced or modified or extended by the vendor. But that shouldn't be any concern to you. The application server (ie: JVM) uses a class loader (probably customized by vendor) to load your servlet (any class that implements the HttpServlet interface). Any other classes (not just J2EE classes, but all classes) will be loaded by the class loader. From there on it is your same java code. I hope this gives you the kind of answer you want. Reading J2EE documents (even aimed towards developers) usually entails meaningless buzzwords. I would recommend that you look over the J2EE Tutorial from Sun. It's free, and goes over the basics that you should know before moving onto a framework (Struts for example). And of course must need to know if you are just going to use just straight J2EE. You may wish to familiarize yourself with some of this: http://java.sun.com/j2ee/1.4/docs/api/ You may also wish to go over HTTP specification (RFC or elsewhere) as well in case you don't understand how http requests and responses are processed by a standalone webserver. http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Overview3.html (web containers in particular) A couple of helpful facts: A JSP is compiled into a servlet. These were created so that your Servlets wouldn't have to be developed using an Output Writer to handle every write to page content (the JSP will be compiled into that for you). ie: out.println("<html>etcetc...") the request (HttpServletRequest) object represents the request. the response (HttpServletRespone) object will build the response. (both the http headers and content). Session and Context objects are also important. The former is for carrying session scoped objects (managed by the app server) and mapped to a jsessionid cookie on the client side (so it knows what client (ie: request) has what objects on the server side). The context object is used for initial settings. You will want to go over web containers to fit it all together. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75064",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13198/"
]
} |
75,105 | I need to store phone numbers in a table. Please suggest which datatype should I use? Wait. Please read on before you hit reply.. This field needs to be indexed heavily as Sales Reps can use this field for searching (including wild character search). As of now, we are expecting phone numbers to come in a number of formats (from an XML file). Do I have to write a parser to convert to a uniform format? There could be millions of data (with duplicates) and I dont want to tie up the server resources (in activities like preprocessing too much) every time some source data comes through.. Any suggestions are welcome.. Update: I have no control over source data. Just that the structure of xml file is standard. Would like to keep the xml parsing to a minimum.Once it is in database, retrieval should be quick. One crazy suggestion going on around here is that it should even work with Ajax AutoComplete feature (so Sales Reps can see the matching ones immediately). OMG!! | Does this include: International numbers? Extensions? Other information besides the actual number (like "ask for bobby")? If all of these are no, I would use a 10 char field and strip out all non-numeric data. If the first is a yes and the other two are no, I'd use two varchar(50) fields, one for the original input and one with all non-numeric data striped and used for indexing. If 2 or 3 are yes, I think I'd do two fields and some kind of crazy parser to determine what is extension or other data and deal with it appropriately. Of course you could avoid the 2nd column by doing something with the index where it strips out the extra characters when creating the index, but I'd just make a second column and probably do the stripping of characters with a trigger. Update: to address the AJAX issue, it may not be as bad as you think. If this is realistically the main way anything is done to the table, store only the digits in a secondary column as I said, and then make the index for that column the clustered one. | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/75105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13205/"
]
} |
75,123 | I have a DataSet which I get a DataTable from that I am being passed back from a function call. It has 15-20 columns, however I only want 10 columns of the data. Is there a way to remove those columns that I don't want, copy the DataTable to another that has only the columns defined that I want or is it just better to iterate the collection and just use the columns I need. I need to write the values out to a fixed length data file. | Aside from limiting the columns selected to reduce bandwidth and memory: DataTable t;t.Columns.Remove("columnName");t.Columns.RemoveAt(columnIndex); | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/75123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3208/"
]
} |
75,134 | How do I have two effects in jQuery run in sequence , not simultaneously? Take this piece of code for example: $("#show-projects").click(function() { $(".page:visible").fadeOut("normal"); $("#projects").fadeIn("normal");}); The fadeOut and the fadeIn run simultaneously, how do I make them run one after the other? | You can supply a callback to the effects functions that run after the effect has completed. $("#show-projects").click(function() { $(".page:visible").fadeOut("normal", function() { $("#projects").fadeIn("normal"); });}); | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/75134",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6967/"
]
} |
75,175 | Is it possible to create an instance of a generic type in Java? I'm thinking based on what I've seen that the answer is no ( due to type erasure ), but I'd be interested if anyone can see something I'm missing: class SomeContainer<E>{ E createContents() { return what??? }} EDIT: It turns out that Super Type Tokens could be used to resolve my issue, but it requires a lot of reflection-based code, as some of the answers below have indicated. I'll leave this open for a little while to see if anyone comes up with anything dramatically different than Ian Robertson's Artima Article . | You are correct. You can't do new E() . But you can change it to private static class SomeContainer<E> { E createContents(Class<E> clazz) { return clazz.newInstance(); }} It's a pain. But it works. Wrapping it in the factory pattern makes it a little more tolerable. | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/75175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5309/"
]
} |
75,180 | If you have a statically allocated array, the Visual Studio debugger can easily display all of the array elements. However, if you have an array allocated dynamically and pointed to by a pointer, it will only display the first element of the array when you click the + to expand it. Is there an easy way to tell the debugger, show me this data as an array of type Foo and size X? | Yes, simple.say you have char *a = new char[10]; writing in the debugger: a,10 would show you the content as if it were an array. | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/75180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9530/"
]
} |
75,182 | How can one detect being in a chroot jail without root privileges? Assume a standard BSD or Linux system. The best I came up with was to look at the inode value for "/" and to consider whether it is reasonably low, but I would like a more accurate method for detection. [edit 20080916 142430 EST] Simply looking around the filesystem isn't sufficient, as it's not difficult to duplicate things like /boot and /dev to fool the jailed user. [edit 20080916 142950 EST] For Linux systems, checking for unexpected values within /proc is reasonable, but what about systems that don't support /proc in the first place? | The inode for / will always be 2 if it's the root directory of an ext2/ext3/ext4 filesystem, but you may be chrooted inside a complete filesystem. If it's just chroot (and not some other virtualization), you could run mount and compare the mounted filesystems against what you see. Verify that every mount point has inode 2. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13277/"
]
} |
75,191 | In C/C++, what an unsigned char is used for? How is it different from a regular char ? | In C++, there are three distinct character types: char signed char unsigned char If you are using character types for text , use the unqualified char : it is the type of character literals like 'a' or '0' (in C++ only, in C their type is int ) it is the type that makes up C strings like "abcde" It also works out as a number value, but it is unspecified whether that value is treated as signed or unsigned. Beware character comparisons through inequalities - although if you limit yourself to ASCII (0-127) you're just about safe. If you are using character types as numbers , use: signed char , which gives you at least the -127 to 127 range. (-128 to 127 is common) unsigned char , which gives you at least the 0 to 255 range. "At least", because the C++ standard only gives the minimum range of values that each numeric type is required to cover. sizeof (char) is required to be 1 (i.e. one byte), but a byte could in theory be for example 32 bits. sizeof would still be report its size as 1 - meaning that you could have sizeof (char) == sizeof (long) == 1 . | {
"score": 10,
"source": [
"https://Stackoverflow.com/questions/75191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1785/"
]
} |
75,213 | In C++, what is the purpose of the scope resolution operator when used without a scope? For instance: ::foo(); | It means global scope. You might need to use this operator when you have conflicting functions or variables in the same scope and you need to use a global one. You might have something like: void bar(); // this is a global functionclass foo { void some_func() { ::bar(); } // this function is calling the global bar() and not the class version void bar(); // this is a class member}; If you need to call the global bar() function from within a class member function, you should use ::bar() to get to the global version of the function. | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/75213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1785/"
]
} |
75,218 | How can I detect when an Exception has been thrown anywhere in my application? I'm try to auto-magically send myself an email whenever an exception is thrown anywhere in my Java Desktop Application. I figure this way I can be more proactive. I know I could just explicitly log and notify myself whenever an exception occurs, but I'd have to do it everywhere and I might(more likely will) miss a couple. Any suggestions? | You probobly don't want to mail on any exception. There are lots of code in the JDK that actaully depend on exceptions to work normally. What I presume you are more inerested in are uncaught exceptions. If you are catching the exceptions you should handle notifications there. In a desktop app there are two places to worry about this, in the event-dispatch-thread (EDT) and outside of the EDT. Globaly you can register a class implementing java.util.Thread.UncaughtExceptionHandler and register it via java.util.Thread.setDefaultUncaughtExceptionHandler . This will get called if an exception winds down to the bottom of the stack and the thread hasn't had a handler set on the current thread instance on the thread or the ThreadGroup. The EDT has a different hook for handling exceptions. A system property 'sun.awt.exception.handler' needs to be registerd with the Fully Qualified Class Name of a class with a zero argument constructor. This class needs an instance method handle( Throwable ) that does your work. The return type doesn't matter, and since a new instance is created every time, don't count on keeping state. So if you don't care what thread the exception occurred in a sample may look like this: class ExceptionHandler implements Thread.UncaughtExceptionHandler { public void uncaughtException(Thread t, Throwable e) { handle(e); } public void handle(Throwable throwable) { try { // insert your e-mail code here } catch (Throwable t) { // don't let the exception get thrown out, will cause infinite looping! } } public static void registerExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler()); System.setProperty("sun.awt.exception.handler", ExceptionHandler.class.getName()); }} Add this class into some random package, and then call the registerExceptionHandler method and you should be ready to go. | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/75218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2443/"
]
} |
75,255 | When you're doing a usual gdb session on an executable file on the same computer, you can give the run command and it will start the program over again. When you're running gdb on an embedded system, as with the command target localhost:3210 , how do you start the program over again without quitting and restarting your gdb session? | You are looking for Multi-Process Mode for gdbserver and set remote exec-file filename | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11138/"
]
} |
75,261 | I got this output when running sudo cpan Scalar::Util::Numeric jmm@freekbox:~/bfwsandbox/sa/angel/astroportal/dtu8e/resources$ sudo cpan Scalar::Util::Numeric[sudo] password for jmm:CPAN: Storable loaded okGoing to read /home/jmm/.cpan/Metadata Database was generated on Tue, 09 Sep 2008 16:02:51 GMTCPAN: LWP::UserAgent loaded okFetching with LWP: ftp://ftp.perl.org/pub/CPAN/authors/01mailrc.txt.gzGoing to read /home/jmm/.cpan/sources/authors/01mailrc.txt.gzFetching with LWP: ftp://ftp.perl.org/pub/CPAN/modules/02packages.details.txt.gzGoing to read /home/jmm/.cpan/sources/modules/02packages.details.txt.gz Database was generated on Tue, 16 Sep 2008 16:02:50 GMT There's a new CPAN.pm version (v1.9205) available! [Current version is v1.7602] You might want to try install Bundle::CPAN reload cpan without quitting the current session. It should be a seamless upgrade while we are running...Fetching with LWP: ftp://ftp.perl.org/pub/CPAN/modules/03modlist.data.gzGoing to read /home/jmm/.cpan/sources/modules/03modlist.data.gzGoing to write /home/jmm/.cpan/MetadataRunning install for module Scalar::Util::NumericRunning make for C/CH/CHOCOLATE/Scalar-Util-Numeric-0.02.tar.gzCPAN: Digest::MD5 loaded okChecksum for /home/jmm/.cpan/sources/authors/id/C/CH/CHOCOLATE/Scalar-Util-Numeric-0.02.tar.gz okScanning cache /home/jmm/.cpan/build for sizesScalar-Util-Numeric-0.02/Scalar-Util-Numeric-0.02/ChangesScalar-Util-Numeric-0.02/lib/Scalar-Util-Numeric-0.02/lib/Scalar/Scalar-Util-Numeric-0.02/lib/Scalar/Util/Scalar-Util-Numeric-0.02/lib/Scalar/Util/Numeric.pmScalar-Util-Numeric-0.02/Makefile.PLScalar-Util-Numeric-0.02/MANIFESTScalar-Util-Numeric-0.02/META.ymlScalar-Util-Numeric-0.02/Numeric.xsScalar-Util-Numeric-0.02/ppport.hScalar-Util-Numeric-0.02/READMEScalar-Util-Numeric-0.02/t/Scalar-Util-Numeric-0.02/t/pod.tScalar-Util-Numeric-0.02/t/Scalar-Util-Numeric.tRemoving previously used /home/jmm/.cpan/build/Scalar-Util-Numeric-0.02 CPAN.pm: Going to build C/CH/CHOCOLATE/Scalar-Util-Numeric-0.02.tar.gzChecking if your kit is complete...Looks goodWriting Makefile for Scalar::Util::Numericcp lib/Scalar/Util/Numeric.pm blib/lib/Scalar/Util/Numeric.pmAutoSplitting blib/lib/Scalar/Util/Numeric.pm (blib/lib/auto/Scalar/Util/Numeric)/usr/bin/perl /usr/share/perl/5.8/ExtUtils/xsubpp -typemap /usr/share/perl/5.8/ExtUtils/typemap Numeric.xs > Numeric.xsc && mv Numeric.xsc Numeric.ccc -c -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O3 -DVERSION=\"0.02\" -DXS_VERSION=\"0.02\" -fPIC "-I/usr/lib/perl/5.8/CORE" Numeric.cIn file included from Numeric.xs:2:/usr/lib/perl/5.8/CORE/perl.h:420:24: error: sys/types.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:451:19: error: ctype.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:463:23: error: locale.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:480:20: error: setjmp.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:486:26: error: sys/param.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:491:23: error: stdlib.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:496:23: error: unistd.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:776:23: error: string.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:925:27: error: netinet/in.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:929:26: error: arpa/inet.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:939:25: error: sys/stat.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:961:21: error: time.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:968:25: error: sys/time.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:975:27: error: sys/times.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:982:19: error: errno.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:997:25: error: sys/socket.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:1024:21: error: netdb.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:1127:24: error: sys/ioctl.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:1156:23: error: dirent.h: No such file or directoryIn file included from /usr/lib/gcc/i486-linux-gnu/4.2.3/include/syslimits.h:7, from /usr/lib/gcc/i486-linux-gnu/4.2.3/include/limits.h:11, from /usr/lib/perl/5.8/CORE/perl.h:1510, from Numeric.xs:2:/usr/lib/gcc/i486-linux-gnu/4.2.3/include/limits.h:122:61: error: limits.h: No such file or directoryIn file included from /usr/lib/perl/5.8/CORE/perl.h:2120, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/handy.h:136:25: error: inttypes.h: No such file or directoryIn file included from /usr/lib/perl/5.8/CORE/perl.h:2284, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/unixish.h:106:21: error: signal.h: No such file or directoryIn file included from Numeric.xs:2:/usr/lib/perl/5.8/CORE/perl.h:2421:33: error: pthread.h: No such file or directoryIn file included from Numeric.xs:2:/usr/lib/perl/5.8/CORE/perl.h:2423: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘perl_os_thread’/usr/lib/perl/5.8/CORE/perl.h:2424: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘perl_mutex’/usr/lib/perl/5.8/CORE/perl.h:2425: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘perl_cond’/usr/lib/perl/5.8/CORE/perl.h:2426: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘perl_key’In file included from /usr/lib/perl/5.8/CORE/iperlsys.h:51, from /usr/lib/perl/5.8/CORE/perl.h:2733, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/perlio.h:65:19: error: stdio.h: No such file or directoryIn file included from /usr/lib/perl/5.8/CORE/iperlsys.h:51, from /usr/lib/perl/5.8/CORE/perl.h:2733, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/perlio.h:259: error: expected ‘)’ before ‘*’ token/usr/lib/perl/5.8/CORE/perlio.h:262: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token/usr/lib/perl/5.8/CORE/perlio.h:265: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token/usr/lib/perl/5.8/CORE/perlio.h:268: error: expected declaration specifiers or ‘...’ before ‘FILE’In file included from /usr/lib/perl/5.8/CORE/perl.h:2747, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/sv.h:389: error: expected specifier-qualifier-list before ‘DIR’In file included from /usr/lib/perl/5.8/CORE/op.h:497, from /usr/lib/perl/5.8/CORE/perl.h:2754, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/reentr.h:72:20: error: pwd.h: No such file or directory/usr/lib/perl/5.8/CORE/reentr.h:75:20: error: grp.h: No such file or directory/usr/lib/perl/5.8/CORE/reentr.h:85:26: error: crypt.h: No such file or directory/usr/lib/perl/5.8/CORE/reentr.h:90:27: error: shadow.h: No such file or directoryIn file included from /usr/lib/perl/5.8/CORE/op.h:497, from /usr/lib/perl/5.8/CORE/perl.h:2754, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/reentr.h:612: error: field ‘_crypt_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:620: error: field ‘_drand48_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:624: error: field ‘_grent_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:635: error: field ‘_hostent_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:654: error: field ‘_netent_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:669: error: field ‘_protoent_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:684: error: field ‘_pwent_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:695: error: field ‘_servent_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:710: error: field ‘_spent_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:721: error: field ‘_gmtime_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:724: error: field ‘_localtime_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:771: error: field ‘_random_struct’ has incomplete type/usr/lib/perl/5.8/CORE/reentr.h:772: error: expected specifier-qualifier-list before ‘int32_t’In file included from /usr/lib/perl/5.8/CORE/perl.h:2756, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/av.h:13: error: expected specifier-qualifier-list before ‘ssize_t’In file included from /usr/lib/perl/5.8/CORE/perl.h:2759, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/scope.h:232: error: expected specifier-qualifier-list before ‘sigjmp_buf’In file included from Numeric.xs:2:/usr/lib/perl/5.8/CORE/perl.h:2931: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getuid’/usr/lib/perl/5.8/CORE/perl.h:2932: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘geteuid’/usr/lib/perl/5.8/CORE/perl.h:2933: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getgid’/usr/lib/perl/5.8/CORE/perl.h:2934: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getegid’In file included from Numeric.xs:2:/usr/lib/perl/5.8/CORE/perl.h:3238:22: error: math.h: No such file or directoryIn file included from /usr/lib/perl/5.8/CORE/perl.h:3881, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/thrdvar.h:85: error: field ‘Tstatbuf’ has incomplete type/usr/lib/perl/5.8/CORE/thrdvar.h:86: error: field ‘Tstatcache’ has incomplete type/usr/lib/perl/5.8/CORE/thrdvar.h:91: error: field ‘Ttimesbuf’ has incomplete typeIn file included from /usr/lib/perl/5.8/CORE/perl.h:3883, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/intrpvar.h:66: error: expected specifier-qualifier-list before ‘time_t’In file included from /usr/lib/perl/5.8/CORE/perl.h:3950, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/proto.h:128: error: expected declaration specifiers or ‘...’ before ‘mode_t’/usr/lib/perl/5.8/CORE/proto.h:128: error: expected declaration specifiers or ‘...’ before ‘uid_t’/usr/lib/perl/5.8/CORE/proto.h:297: error: expected declaration specifiers or ‘...’ before ‘off64_t’/usr/lib/perl/5.8/CORE/proto.h:299: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_do_sysseek’/usr/lib/perl/5.8/CORE/proto.h:300: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_do_tell’/usr/lib/perl/5.8/CORE/proto.h:411: error: expected declaration specifiers or ‘...’ before ‘gid_t’/usr/lib/perl/5.8/CORE/proto.h:411: error: expected declaration specifiers or ‘...’ before ‘uid_t’/usr/lib/perl/5.8/CORE/proto.h:736: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_my_fork’/usr/lib/perl/5.8/CORE/proto.h:1020: error: expected declaration specifiers or ‘...’ before ‘pid_t’/usr/lib/perl/5.8/CORE/proto.h:1300: error: expected declaration specifiers or ‘...’ before ‘pid_t’/usr/lib/perl/5.8/CORE/proto.h:1456: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token/usr/lib/perl/5.8/CORE/proto.h:2001: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_PerlIO_read’/usr/lib/perl/5.8/CORE/proto.h:2002: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_PerlIO_write’/usr/lib/perl/5.8/CORE/proto.h:2003: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_PerlIO_unread’/usr/lib/perl/5.8/CORE/proto.h:2004: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_PerlIO_tell’/usr/lib/perl/5.8/CORE/proto.h:2005: error: expected declaration specifiers or ‘...’ before ‘off64_t’In file included from /usr/lib/perl/5.8/CORE/perl.h:3988, from Numeric.xs:2:/usr/lib/perl/5.8/CORE/perlvars.h:31: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PL_thr_key’/usr/lib/perl/5.8/CORE/perlvars.h:48: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PL_op_mutex’/usr/lib/perl/5.8/CORE/perlvars.h:52: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PL_dollarzero_mutex’/usr/lib/perl/5.8/CORE/perl.h:4485:24: error: sys/ipc.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:4486:24: error: sys/sem.h: No such file or directory/usr/lib/perl/5.8/CORE/perl.h:4611:24: error: sys/file.h: No such file or directoryIn file included from /usr/lib/perl/5.8/CORE/perlapi.h:38, from /usr/lib/perl/5.8/CORE/XSUB.h:349, from Numeric.xs:3:/usr/lib/perl/5.8/CORE/intrpvar.h:66: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token/usr/lib/perl/5.8/CORE/intrpvar.h:237: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token/usr/lib/perl/5.8/CORE/intrpvar.h:238: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token/usr/lib/perl/5.8/CORE/intrpvar.h:239: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token/usr/lib/perl/5.8/CORE/intrpvar.h:240: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenIn file included from /usr/lib/perl/5.8/CORE/perlapi.h:39, from /usr/lib/perl/5.8/CORE/XSUB.h:349, from Numeric.xs:3:/usr/lib/perl/5.8/CORE/perlvars.h:31: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token/usr/lib/perl/5.8/CORE/perlvars.h:48: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token/usr/lib/perl/5.8/CORE/perlvars.h:52: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ tokenIn file included from Numeric.xs:4:ppport.h:3042:1: warning: "PERL_UNUSED_DECL" redefinedIn file included from Numeric.xs:2:/usr/lib/perl/5.8/CORE/perl.h:163:1: warning: this is the location of the previous definitionNumeric.c: In function ‘XS_Scalar__Util__Numeric_is_num’:Numeric.c:20: error: invalid type argument of ‘unary *’Numeric.c:20: error: invalid type argument of ‘unary *’Numeric.c:20: error: invalid type argument of ‘unary *’Numeric.c:22: error: invalid type argument of ‘unary *’Numeric.c:24: error: invalid type argument of ‘unary *’Numeric.xs:16: error: invalid type argument of ‘unary *’Numeric.xs:17: error: invalid type argument of ‘unary *’Numeric.xs:20: error: invalid type argument of ‘unary *’Numeric.xs:20: error: invalid type argument of ‘unary *’Numeric.xs:20: error: invalid type argument of ‘unary *’Numeric.xs:20: error: invalid type argument of ‘unary *’Numeric.xs:20: error: invalid type argument of ‘unary *’Numeric.c:36: error: invalid type argument of ‘unary *’Numeric.c:36: error: invalid type argument of ‘unary *’Numeric.c: In function ‘XS_Scalar__Util__Numeric_uvmax’:Numeric.c:43: error: invalid type argument of ‘unary *’Numeric.c:43: error: invalid type argument of ‘unary *’Numeric.c:43: error: invalid type argument of ‘unary *’Numeric.c:45: error: invalid type argument of ‘unary *’Numeric.xs:26: error: invalid type argument of ‘unary *’Numeric.xs:26: error: invalid type argument of ‘unary *’Numeric.xs:26: error: invalid type argument of ‘unary *’Numeric.xs:26: error: invalid type argument of ‘unary *’Numeric.xs:26: error: invalid type argument of ‘unary *’Numeric.c:51: error: invalid type argument of ‘unary *’Numeric.c:51: error: invalid type argument of ‘unary *’Numeric.c: In function ‘boot_Scalar__Util__Numeric’:Numeric.c:60: error: invalid type argument of ‘unary *’Numeric.c:60: error: invalid type argument of ‘unary *’Numeric.c:60: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:63: error: invalid type argument of ‘unary *’Numeric.c:65: error: invalid type argument of ‘unary *’Numeric.c:65: error: invalid type argument of ‘unary *’Numeric.c:66: error: invalid type argument of ‘unary *’Numeric.c:66: error: invalid type argument of ‘unary *’Numeric.c:67: error: invalid type argument of ‘unary *’Numeric.c:67: error: invalid type argument of ‘unary *’Numeric.c:67: error: invalid type argument of ‘unary *’Numeric.c:67: error: invalid type argument of ‘unary *’make: *** [Numeric.o] Error 1 /usr/bin/make -- NOT OKRunning make test Can't test without successful makeRunning make install make had returned bad status, install seems impossiblejmm@freekbox:~/bfwsandbox/sa/angel/astroportal/dtu8e/resources$ | You're missing your C library development headers. You should install a package that has them. These are necessary to install this module because it has to compile some non-perl C code and needs to know more about your system. I can't tell what kind of operating system you're on, but it looks like linux. If it's debian, you should be able to use apt-get to install the 'libc6-dev' package. That will contain the headers you need to compile this module. On other types of linux there will be a similarly named package. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
]
} |
75,267 | In how many languages is Null not equal to anything not even Null? | It's this way in SQL (as a logic language) because null means unknown/undefined. However, in programming languages (like say, C++ or C#), a null pointer/reference is a specific value with a specific meaning -- nothing. Two nothings are equivilent, but two unknowns are not. The confusion comes from the fact that the same name (null) is used for both concepts. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6178/"
]
} |
75,270 | Does anyone know of a good open source plugin for database querying and exploring within Eclipse? The active Database Exploring plugin within Eclipse is really geared around being associated with a Java project. While I am just trying to run ad-hoc queries and explore the schema. I am effectively looking for a just a common, quick querying tool without the overhead of having to create a code project. I have found a couple open source database plugins for Eclipse but these have not seen active development in over a year. Any suggestions? | It's this way in SQL (as a logic language) because null means unknown/undefined. However, in programming languages (like say, C++ or C#), a null pointer/reference is a specific value with a specific meaning -- nothing. Two nothings are equivilent, but two unknowns are not. The confusion comes from the fact that the same name (null) is used for both concepts. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75270",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12600/"
]
} |
75,282 | I'm handling the onSelectIndexChanged event. An event is raised when the DropDownList selection changes. the problem is that the DropDownList still returns the old values for SelectedValue and SelectedIndex . What am I doing wrong? Here is the DropDownList definition from the aspx file: <div style="margin: 0px; padding: 0px 1em 0px 0px;"> <span style="margin: 0px; padding: 0px; vertical-align: top;">Route:</span> <asp:DropDownList id="Select1" runat="server" onselectedindexchanged="index_changed" AutoPostBack="true"> </asp:DropDownList> <asp:Literal ID="Literal1" runat="server"></asp:Literal></div> Here is the DropDownList OnSelectedIndexChanged event handler: protected void index_changed(object sender, EventArgs e){ decimal d = Convert.ToDecimal( Select1.SelectedValue ); Literal1.Text = d.ToString();} | Do you have any code in page load that is by chance re-defaulting the value to the first value? When the page reloads do you see the new value? | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4491/"
]
} |
75,322 | I have an ASP.Net/AJAX control kit project that i am working on. 80% of the time there is no problem. The page runs as it should. If you refresh the page it will sometimes show a javascript error "Sys is undefined". It doesn't happen all the time, but it is reproducible. When it happens, the user has to shut down their browser and reopen the page. This leads me to believe that it could be an IIS setting. Another note. I looked at the page source both when I get the error, and when not. When the page throws errors the following code is missing: <script src="/ScriptResource.axd?d=EAvfjPfYejDh0Z2Zq5zTR_TXqL0DgVcj_h1wz8cst6uXazNiprV1LnAGq3uL8N2vRbpXu46VsAMFGSgpfovx9_cO8tpy2so6Qm_0HXVGg_Y1&t=baeb8cc" type="text/javascript"></script><script type="text/javascript">//<![CDATA[if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');//]]></script> | I fixed my problem by moving the <script type="text/javascript"></script> block containing the Sys.* calls lower down (to the last item before the close of the body's <asp:Content/> section) in the HTML on the page. I originally had my the script block in the HEAD <asp:Content/> section of my page. I was working inside a page that had a MasterPageFile. Hope this helps someone out. | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/75322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
]
} |
75,340 | Can anyone recommend an efficient method to execute XSLT transforms of XML data within a Ruby application? The XSL gem (REXSL) is not available yet, and while I have seen a project or two that implement it, I'm wary of using them so early on. A friend had recommended a shell out call to Perl, but I'm worried about resources. This is for a linux environment. | I fixed my problem by moving the <script type="text/javascript"></script> block containing the Sys.* calls lower down (to the last item before the close of the body's <asp:Content/> section) in the HTML on the page. I originally had my the script block in the HEAD <asp:Content/> section of my page. I was working inside a page that had a MasterPageFile. Hope this helps someone out. | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/75340",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13320/"
]
} |
75,401 | User kokos answered the wonderful Hidden Features of C# question by mentioning the using keyword. Can you elaborate on that? What are the uses of using ? | The reason for the using statement is to ensure that the object is disposed as soon as it goes out of scope, and it doesn't require explicit code to ensure that this happens. As in Understanding the 'using' statement in C# (codeproject) and Using objects that implement IDisposable (microsoft) , the C# compiler converts using (MyResource myRes = new MyResource()){ myRes.DoSomething();} to { // Limits scope of myRes MyResource myRes= new MyResource(); try { myRes.DoSomething(); } finally { // Check for a null resource. if (myRes != null) // Call the object's Dispose method. ((IDisposable)myRes).Dispose(); }} C# 8 introduces a new syntax, named " using declarations ": A using declaration is a variable declaration preceded by the using keyword. It tells the compiler that the variable being declared should be disposed at the end of the enclosing scope. So the equivalent code of above would be: using var myRes = new MyResource();myRes.DoSomething(); And when control leaves the containing scope (usually a method, but it can also be a code block), myRes will be disposed. | {
"score": 10,
"source": [
"https://Stackoverflow.com/questions/75401",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13332/"
]
} |
75,432 | I am using URLDownloadToFile to retrieve a file from a website. Subsequent calls return the original file rather than an updated version. I assume it is retrieving a cached version. | Call DeleteUrlCacheEntry with the same URL just prior to calling URLDownloadToFile.You will need to link against Wininet.lib | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75432",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8761/"
]
} |
75,440 | What method do I call to get the name of a class? | In [1]: class Test: ...: pass ...: In [2]: Test.__name__Out[2]: 'Test' | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/75440",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8453/"
]
} |
75,446 | I have just started reading DDD. I am unable to completely grasp the concept of Entity vs Value objects.. Can someone please explain the problems (maintainability, performance.. etc) a system could face when a Value object is designed as a Entity object? Example would be great... | Reduced to the essential distinction, identity matters for entities, but does not matter for value objects. For example, someone's Name is a value object. A Customer entity might be composed of a customer Name (value object), List<Order> OrderHistory (List of entities), and perhaps a default Address (typically a value object). The Customer Entity would have an ID, and each order would have an ID, but a Name should not; generally, within the object model anyway, the identity of an Address probably does not matter. Value objects can typically be represented as immutable objects; changing one property of a value object essentially destroys the old object and creates a new one, because you're not as concerned with identity as with content. Properly, the Equals instance method on Name would return "true" as long as the object's properties are identical to the properties of another instance. However, changing some attribute of an entity like Customer doesn't destroy the customer; a Customer entity is typically mutable. The identity remains the same (at least once the object has been persisted). You probably create value objects without realizing it; anytime you are representing some aspect of an Entity by creating a fine-grained class, you've got a value object. For example, a class IPAddress, which has some constraints on valid values but is composed of simpler datatypes, would be a value object. An EmailAddress could be a string, or it could be a value object with its own set of behaviors. It's quite possible that even items that have an identity in your database don't have an identity in your object model. But the simplest case is a composite of some attributes that make sense together. You probably don't want to have Customer.FirstName, Customer.LastName, Customer.MiddleInitial and Customer.Title when you can compose those together as Customer.Name; they'll probably be multiple fields in your database by the time you think about persistence, but your object model doesn't care. | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/75446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
]
} |
75,482 | I am serving all content through apache with Content-Encoding: zip but that compresses on the fly. A good amount of my content is static files on the disk. I want to gzip the files beforehand rather than compressing them every time they are requested. This is something that, I believe, mod_gzip did in Apache 1.x automatically, but just having the file with .gz next to it. That's no longer the case with mod_deflate . | This functionality was misplaced in mod_gzip anyway. In Apache 2.x, you do that with content negotiation . Specifically, you need to enable MultiViews with the Options directive and you need to specify your encoding types with the AddEncoding directive . | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9594/"
]
} |
75,489 | I am pulling a long timestamp from a database, but want to present it as a Date using Tags only, no embedded java in the JSP. I've created my own tag to do this because I was unable to get the parseDate and formatDate tags to work, but that's not to say they don't work. Any advice? Thanks. | You can avoid having to make any changes to your Servlet by creating a date object within the JSP using the jsp:useBean and jsp:setProperty tags to set the time of newly created date object to that of the time stamp. For example: <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %><jsp:useBean id="dateValue" class="java.util.Date"/><jsp:setProperty name="dateValue" property="time" value="${timestampValue}"/><fmt:formatDate value="${dateValue}" pattern="MM/dd/yyyy HH:mm"/> | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/75489",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9450/"
]
} |
75,495 | When creating a UserControl in WPF, I find it convenient to give it some arbitrary Height and Width values so that I can view my changes in the Visual Studio designer. When I run the control, however, I want the Height and Width to be undefined, so that the control will expand to fill whatever container I place it in. How can I acheive this same functionality without having to remove the Height and Width values before building my control? (Or without using DockPanel in the parent container.) The following code demonstrates the problem: <Window x:Class="ExampleApplication3.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:loc="clr-namespace:ExampleApplication3" Title="Example" Height="600" Width="600"> <Grid Background="LightGray"> <loc:UserControl1 /> </Grid></Window> The following definition of UserControl1 displays reasonably at design time but displays as a fixed size at run time: <UserControl x:Class="ExampleApplication3.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="300" Width="300"> <Grid Background="LightCyan" /></UserControl> The following definition of UserControl1 displays as a dot at design time but expands to fill the parent Window1 at run time: <UserControl x:Class="ExampleApplication3.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid Background="LightCyan" /></UserControl> | For Blend, a little known trick is to add these attributes to your usercontrol or window: xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="500" d:DesignWidth="600" This will set the design height and width to 500 and 600 respectively. However this will only work for the blend designer. Not the Visual Studio Designer. As far as the Visual Studio Designer your technique is all that works. Which is why I don't use the Visual Studio Designer. ;) | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/75495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/317/"
]
} |
75,500 | I have around 1000 pdf filesand I need to convert them to 300 dpi tiff files. What is the best way to do this? If there is an SDK or something or a tool that can be scripted that would be ideal. | Use Imagemagick, or better yet, Ghostscript. http://www.ibm.com/developerworks/library/l-graf2/#N101C2 has an example for imagemagick: convert foo.pdf pages-%03d.tiff http://www.asmail.be/msg0055376363.html has an example for ghostscript: gs -q -dNOPAUSE -sDEVICE=tiffg4 -sOutputFile=a.tif foo.pdf -c quit I would install ghostscript and read the man page for gs to see what exact options are needed and experiment. | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/75500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/260/"
]
} |
75,538 | No C++ love when it comes to the "hidden features of" line of questions? Figured I would throw it out there. What are some of the hidden features of C++? | You can put URIs into C++ source without error. For example: void foo() { http://stackoverflow.com/ int bar = 4; ...} | {
"score": 8,
"source": [
"https://Stackoverflow.com/questions/75538",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2328/"
]
} |
75,626 | I have a JSP page that contains a scriplet where I instantiate an object. I would like to pass that object to the JSP tag without using any cache. For example I would like to accomplish this: <%@ taglib prefix="wf" uri="JspCustomTag" %><% Object myObject = new Object();%><wf:my-tag obj=myObject /> I'm trying to avoid directly interacting with any of the caches (page, session, servletcontext), I would rather have my tag handle that. | A slightly different question that I looked for here: "How do you pass an object to a tag file?" Answer: Use the "type" attribute of the attribute directive: <%@ attribute name="field" required="true" type="com.mycompany.MyClass" %> The type defaults to java.lang.String , so without it you'll get an error if you try to access object fields saying that it can't find the field from type String. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13393/"
]
} |
75,650 | I'm working in a team environment where each developer works from their local desktop and deploys to a virtual machine that they own on the network. What I'm trying to do is set up the Visual Studio solution so that when they build the solution each projects deployment is handled in the post-build event to that developers virtual machine. What I'd really like to do is give ownership of those scripts to the individual developer as well so that they own their post build steps and they don't have to be the same for everyone. A couple of questions: Is a post build event the place to execute this type of deployment operation? If not what is the best place to do it? What software, tools, or tutorials/blog posts are available to assist in developing an automatic deployment system that supports these scenarios? Edit: MSBuild seems to be the way to go in this situation. Anyone use alternative technologies with any success? Edit: If you are reading this question and wondering how to execute a different set of MSBuild tasks for each developer please see this question; Executing different set of MSBuild tasks for each user? | A slightly different question that I looked for here: "How do you pass an object to a tag file?" Answer: Use the "type" attribute of the attribute directive: <%@ attribute name="field" required="true" type="com.mycompany.MyClass" %> The type defaults to java.lang.String , so without it you'll get an error if you try to access object fields saying that it can't find the field from type String. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
]
} |
75,652 | or "How do I answer questions on SO in Firefox using gVim inside the textboxes?" | It's All Text! From the extension page: At the bottom right corner of any edit box, a little edit button will appear. Click it. If this is the first time you've used "It's All Text!" then you will be asked to set your preferences, most importantly the editor. The web page will pop up in your selected editor. When you save it, it'll refresh in the web page. Wait for the magic yellow glow that means that the radiation has taken effect! | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/75652",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13060/"
]
} |
75,675 | How do I dump the data, and only the data, not the schema, of some SQLite3 tables of a database (not all the tables)?The dump should be in SQL format, as it should be easily re-entered into the database later and should be done from the command line. Something like sqlite3 db .dump but without dumping the schema and selecting which tables to dump. | You're not saying what you wish to do with the dumped file. To get a CSV file (which can be imported into almost everything) .mode csv -- use '.separator SOME_STRING' for something other than a comma..headers on .out file.csv select * from MyTable; To get an SQL file (which can be reinserted into a different SQLite database) .mode insert <target_table_name>.out file.sql select * from MyTable; | {
"score": 8,
"source": [
"https://Stackoverflow.com/questions/75675",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6068/"
]
} |
75,677 | How can I convert a uniform distribution (as most random number generators produce, e.g. between 0.0 and 1.0) into a normal distribution? What if I want a mean and standard deviation of my choosing? | The Ziggurat algorithm is pretty efficient for this, although the Box-Muller transform is easier to implement from scratch (and not crazy slow). | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/75677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8062/"
]
} |
75,701 | Let's say I write a DLL in C++, and declare a global object of a class with a non-trivial destructor. Will the destructor be called when the DLL is unloaded? | In a Windows C++ DLL, all global objects (including static members of classes) will be constructed just before the calling of the DllMain with DLL_PROCESS_ATTACH, and they will be destroyed just after the call of the DllMain with DLL_PROCESS_DETACH. Now, you must consider three problems: 0 - Of course, global non-const objects are evil (but you already know that, so I'll avoid mentionning multithreading, locks, god-objects, etc.) 1 - The order of construction of objects or different compilation units (i.e. CPP files) is not guaranteed, so you can't hope the object A will be constructed before B if the two objects are instanciated in two different CPPs. This is important if B depends on A. The solution is to move all global objects in the same CPP file, as inside the same compilation unit, the order of instanciation of the objects will be the order of construction (and the inverse of the order of destruction) 2 - There are things that are forbidden to do in the DllMain. Those things are probably forbidden, too, in the constructors. So avoid locking something. See Raymond Chen's excellent blog on the subject: Some reasons not to do anything scary in your DllMain Another reason not to do anything scary in your DllMain: Inadvertent deadlock Some reasons not to do anything scary in your DllMain, part 3 In this case, lazy initialization could be interesting: The classes remain in an "un-initialized" state (internal pointers are NULL, booleans are false, whatever) until you call one of their methods, at which point they'll initialize themselves. If you use those objects inside the main (or one of the main's descendant functions), you'll be ok because they will be called after execution of DllMain. 3 - Of course, if some global objects in DLL A depend on global objects in DLL B, you should be very very careful about DLL loading order, and thus dependancies. In this case, DLLs with direct or indirect circular dependancies will cause you an insane amount of headaches. The best solution is to break the circular dependancies. P.S.: Note that in C++, constructor can throw, and you don't want an exception in the middle of a DLL loading, so be sure your global objects won't be using exception without a very, very good reason. As correctly written destructors are not authorized to throw, the DLL unloading should be ok in this case. | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/75701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13313/"
]
} |
75,704 | I see that within MySQL there are Cast() and Convert() functions to create integers from values, but is there any way to check to see if a value is an integer? Something like is_int() in PHP is what I am looking for. | I'll assume you want to check a string value. One nice way is the REGEXP operator, matching the string to a regular expression. Simply do select field from table where field REGEXP '^-?[0-9]+$'; this is reasonably fast. If your field is numeric, just test for ceil(field) = field instead. | {
"score": 9,
"source": [
"https://Stackoverflow.com/questions/75704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8224/"
]
} |
75,722 | In C#, if I want to deterministically clean up non-managed resources, I can use the "using" keyword. But for multiple dependent objects, this ends up nesting further and further: using (FileStream fs = new FileStream("c:\file.txt", FileMode.Open)){ using (BufferedStream bs = new BufferedStream(fs)) { using (StreamReader sr = new StreamReader(bs)) { // use sr, and have everything cleaned up when done. } }} In C++, I'm used to being able to use destructors to do it like this: { FileStream fs("c:\file.txt", FileMode.Open); BufferedStream bs(fs); StreamReader sr(bs); // use sr, and have everything cleaned up when done.} Is there a better way in C# to do this? Or am I stuck with the multiple levels of nesting? | You don't have to nest with multiple usings: using (FileStream fs = new FileStream("c:\file.txt", FileMode.Open))using (BufferedStream bs = new BufferedStream(fs))using (StreamReader sr = new StreamReader(bs)){ // all three get disposed when you're done} | {
"score": 6,
"source": [
"https://Stackoverflow.com/questions/75722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8701/"
]
} |
75,746 | EmployeeNumber =string.IsNullOrEmpty(employeeNumberTextBox.Text) ? null : Convert.ToInt32(employeeNumberTextBox.Text), I often find myself wanting to do things like this ( EmployeeNumber is a Nullable<int> as it's a property on a LINQ-to-SQL dbml object where the column allows NULL values). Unfortunately, the compiler feels that There is no implicit conversion between 'null' and 'int' even though both types would be valid in an assignment operation to a nullable int on their own. Using the null coalescing operator is not an option as far as I can see because of the inline conversion that needs to happen on the .Text string if it's not null. As far as I know the only way to do this is to use an if statement and/or assign it in two steps. In this particular case I find that very frustrating because I wanted to use the object initializer syntax and this assignment would be in the initialization block... Does anyone know a more elegant solution? | The problem occurs because the conditional operator doesn't look at how the value is used (assigned in this case) to determine the type of the expression -- just the true/false values. In this case, you have a null and an Int32 , and the type can not be determined (there are real reasons it can't just assume Nullable<Int32> ). If you really want to use it in this way, you must cast one of the values to Nullable<Int32> yourself, so C# can resolve the type: EmployeeNumber = string.IsNullOrEmpty(employeeNumberTextBox.Text) ? (int?)null : Convert.ToInt32(employeeNumberTextBox.Text), or EmployeeNumber = string.IsNullOrEmpty(employeeNumberTextBox.Text) ? null : (int?)Convert.ToInt32(employeeNumberTextBox.Text), | {
"score": 7,
"source": [
"https://Stackoverflow.com/questions/75746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12975/"
]
} |
75,752 | I'm building a quick csv from a mysql table with a query like: select DATE(date),count(date) from table group by DATE(date) order by date asc; and just dumping them to a file in perl over a: while(my($date,$sum) = $sth->fetchrow) { print CSV "$date,$sum\n"} There are date gaps in the data, though: | 2008-08-05 | 4 | | 2008-08-07 | 23 | I would like to pad the data to fill in the missing days with zero-count entries to end up with: | 2008-08-05 | 4 | | 2008-08-06 | 0 | | 2008-08-07 | 23 | I slapped together a really awkward (and almost certainly buggy) workaround with an array of days-per-month and some math, but there has to be something more straightforward either on the mysql or perl side. Any genius ideas/slaps in the face for why me am being so dumb? I ended up going with a stored procedure which generated a temp table for the date range in question for a couple of reasons: I know the date range I'll be looking for every time The server in question unfortunately was not one that I can install perl modules on atm, and the state of it was decrepit enough that it didn't have anything remotely Date::-y installed The perl Date/DateTime-iterating answers were also very good, I wish I could select multiple answers! | When you need something like that on server side, you usually create a table which contains all possible dates between two points in time, and then left join this table with query results. Something like this: create procedure sp1(d1 date, d2 date) declare d datetime; create temporary table foo (d date not null); set d = d1 while d <= d2 do insert into foo (d) values (d) set d = date_add(d, interval 1 day) end while select foo.d, count(date) from foo left join table on foo.d = table.date group by foo.d order by foo.d asc; drop temporary table foo;end procedure In this particular case it would be better to put a little check on the client side, if current date is not previos+1, put some addition strings. | {
"score": 5,
"source": [
"https://Stackoverflow.com/questions/75752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13196/"
]
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.