instruction stringlengths 21 27.8k | chosen stringlengths 18 28.2k | rejected stringlengths 18 33.6k | __index_level_0__ int64 0 50k |
|---|---|---|---|
<p>I am looking for the best way to make my desktop java program run in the background (<strong>daemon/service</strong>?) across most platforms (Windows, Mac OS, Linux [Ubuntu in particular]).</p>
<p>By "best way" I am hoping to find a way that will:</p>
<ol>
<li>require a <strong>minimum</strong> amount of platform-... | <p>You can use the <a href="http://java.sun.com/javase/6/docs/api/java/awt/SystemTray.html" rel="nofollow noreferrer">SystemTray</a> classes and install your app as any other in the default platform.</p>
<p>For windows it could be an scheduled task that run at startup.
For Linux and OSX I don't know (besides crontab... | <p>Check out <a href="https://jdic.dev.java.net/" rel="nofollow noreferrer">JDIC,</a> the Java Desktop Integration Components project. It supports desktop integration like system tray (or equivalent) with a cross-platform API.</p>
<p>Others have mentioned Quartz, which is an enterprise job scheduler. It can be lightwe... | 42,310 |
<p>Are there any command line interfaces to the DHCP settings in Mac OS X? I have found that inside System Profiler, the Network tab provides a lot of useful information, but I have not found any documentation about any command line equivalents.</p>
| <p>You may use</p>
<pre><code>networksetup -listallnetworkservices
networksetup -getinfo <networkservice>
networksetup -setdhcp <networkservice> [clientid]
</code></pre>
<p>networkservice is something like Ethernet (all availabe listed by the first command)</p>
| <p>You should look at:</p>
<pre><code>ifconfig(8)
netstat(1)
netintro(4)
</code></pre>
<p>The most important of these (netintro isn't actually a utility but rather introductory information on unix networking) is ifconfig which is the command line tool used to configure the various network interfaces you may have inst... | 40,876 |
<p>Given a large API (an in particular, the Java or J2EE standard libraries), is there a tool or search engine or other resource that can tells me which methods, classes, or even packages people in general tend to use the most?
I am annotating (see below) APIs and would like to focus my attention on popular areas.
The ... | <p>I wouldn't know if such statistics are even feasible, but I think a pretty safe bet would be to start with the basics plus some famous third party libraries. For example:</p>
<ul>
<li><a href="http://java.sun.com/j2se/1.5.0/docs/guide/collections/index.html" rel="nofollow noreferrer">Collections</a></li>
<li><a hre... | <p>It seems like it would be possible to automate a process where a list of J2SE or J2EE packages could be submitted to Koders.com, Google Code or another open source code search repository, count the results per package and sort for the most popular.</p>
<p>Note that this won't give you absolutely complete results, a... | 29,279 |
<p>I'm writing a shell for a project of mine, which by design parses commands that looks like this:</p>
<p>COMMAND_NAME ARG1="Long Value" ARG2=123 ARG3=me@me.com</p>
<p>My problem is that Python's command line parsing libraries (getopt and optparse) forces me to use '-' or '--' in front of the arguments. This behavio... | <p>You could split them up with shlex.split(), which can handle the quoted values you have, and pretty easily parse this with a very simple regular expression. Or, you can just use regular expressions for both splitting and parsing. Or simply use split().</p>
<pre><code>args = {}
for arg in shlex.split(cmdln_args):
... | <p>Without fairly intensive surgery on optparse or getopt, I don't believe you can sensibly make them parse your format. You can easily parse your own format, though, or translate it into something optparse could handle:</p>
<pre><code>parser = optparse.OptionParser()
parser.add_option("--ARG1", dest="arg1", help="...... | 18,986 |
<p>After installing asp.net (and aspnet_regIIS.exe -i) the site doesn't accept my default.aspx page. When trying to access it I get a 404.
When hitting directly to my mvc pages (/search.mvc for example) it works like a charm.</p>
<p>We checked the website configuration and noted that there are no .aspx references in t... | <p>We added a single session manually (for aspx.net) with the wrong -old- version of asp.net engine and then ran aspnet_regiis.exe and now it added all the old lines too.</p>
<p>Don't have a clue why and when and how. Mistery...</p>
| <p>Probably you are missing the .aspx references in the scriptmaps. SCNR. ;-)</p>
<p>More seriously, are they there at the "Web Sites" properties level in IIS manager? What is the output you get when running <code>aspnet_regIIS.exe -i</code>?</p>
<p>Mine says:</p>
<pre>
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>... | 28,813 |
<p>I'm looking for a way to supply an argument to a ruby on rails project at runtime. Essentially, our project uses public key cryptography to encrypt some sensitive client data and we want the ability to supply the password to the private key file at runtime.</p>
| <p>An easy way to do this would be to create a Rails plugin that takes arguments using 'gets' in its 'init.rb'. Allow me to cook-up a quick code sample:</p>
<p>Make a directory: '$railsRoot/vendor/plugins/startup_args/lib'</p>
<p>Create an object to store argument data in '$railsRoot/vendor/plugins/startup_args/lib/... | <p>What is wrong with putting the password in a file that is chmod'ed to only be readable by the web server user?</p>
| 31,629 |
<p>Does anyone know of a disassembler for <em>ARMV4i</em> executables and DLLs?</p>
<p>I've got a plug-in DLL I'm writing with a very rare <code>data abort</code> (<5% of the time) that I have narrowed down to a specific function (via dumpbin and the address output by the <code>data abort</code>). However, it is a... | <p>IDA Pro will definitely do ARM disassembly. And they (Datarescue) once arranged me a licence at about 11PM local time, so I like to recommend them...</p>
<p>I see from <a href="http://www.datarescue.com/idabase/" rel="nofollow noreferrer">http://www.datarescue.com/idabase/</a> that there's been some rearrangement ... | <p>A couple of years ago I found an ARM disassembler I used while doing some embedded work. However, I don't remember its name - though I think it was part of a larger package like an emulator or something.</p>
<p>In your case, could you ask your compiler to generate an assembly listing of the compiled code? That migh... | 4,228 |
<p>I've been really enjoying Python programming lately. I come from a background of a strong love for C-based coding, where everything is perhaps more complicated than it should be (but puts hair on your chest, at least). So switching from C to Python for more complex things that don't require tons of speed has been mo... | <p>Part of learning a new programming language is learning to read code in that language. A crutch like this may make it easier to read your own code, but it's going to impede the process of learning how to read anyone else's Python code. I really think you'd be better off getting rid of the end of block comments and... | <p>I would look in to understanding more details about Python syntax. Often times if a piece of code looks odd, there usually is a better way to write it. For example, in the above example:</p>
<pre><code>bar = foo if baz else None
while bar not biz:
bar = i_am_going_to_find_you_biz_i_swear_on_my_life()
did_i_not... | 7,458 |
<p>For example, <a href="http://reductiotest.org/" rel="nofollow noreferrer">Reductio</a> (for Java/Scala) and <a href="http://www.cs.chalmers.se/~rjmh/QuickCheck/" rel="nofollow noreferrer">QuickCheck</a> (for Haskell). The kind of framework I'm thinking of would provide "generators" for built-in data types and allow... | <p>There's FsCheck, a port from QuickCheck to F# and thus C#, although most of the doc seems to be for f#.
I've been exploring the ideas myself aswell. see : <a href="http://kilfour.wordpress.com/2009/08/02/testing-tool-tour-quicknet-preview/" rel="nofollow noreferrer">http://kilfour.wordpress.com/2009/08/02/testing-to... | <p>I might not understand you correctly but check this out...</p>
<p><a href="http://www.ayende.com/projects/rhino-mocks.aspx" rel="nofollow noreferrer">http://www.ayende.com/projects/rhino-mocks.aspx</a></p>
| 10,314 |
<p>Is there a PHP module that you can use to programmatically read a torrent to find out information about it, Seeders for instance?</p>
| <p>I have used these functions in a small website I made once. Think I found them with a php bittorrent tracker called OpenTracker or something, but can't find the website...</p>
<p>You wont find the seeders in the torrent file though. The torrent file just contain info about the files, hash codes and lengths etc. And... | <p>This library contains a sublibrary which does the job very well:
<a href="http://www.binpress.com/app/phptracker/177" rel="nofollow">http://www.binpress.com/app/phptracker/177</a></p>
| 20,192 |
<p>I've been looking at F# recently, and while I'm not likely to leap the fence any time soon, it definitely highlights some areas where C# (or library support) could make life easier.</p>
<p>In particular, I'm thinking about the pattern matching capability of F#, which allows a very rich syntax - much more expressive... | <p>In C# 7, you can do:</p>
<pre><code>switch(shape)
{
case Circle c:
WriteLine($"circle with radius {c.Radius}");
break;
case Rectangle s when (s.Length == s.Height):
WriteLine($"{s.Length} x {s.Height} square");
break;
case Rectangle r:
WriteLine... | <p>You can achieve what you are after by using a library I wrote, called <a href="https://github.com/mcintyre321/OneOf" rel="nofollow noreferrer">OneOf</a></p>
<p>The major advantage over <code>switch</code> (and <code>if</code> and <code>exceptions as control flow</code>) is that it is compile-time safe - there is no... | 18,926 |
<p>Imagine that you are handed a new book everyday from an author.
The book is a work in progress.
He does not tell you what he has changed or added.</p>
<p>Your job is to identify the changes and additions, and pass ONLY these along to the publisher (who does not have time to read the entire book everyday)</p>
<p>Fo... | <p>I would use <a href="http://www.freebsd.org/cgi/man.cgi?query=diff&apropos=0&sektion=0&manpath=Unix+Seventh+Edition&format=html" rel="nofollow noreferrer">diff</a>.</p>
<p>If I needed to implement it within my own program, I would use one of the algorithms for finding the <a href="http://en.wikipedi... | <p>"Then when we get the next file tomorrow, we go through it line by line, creating a new hash for each line and comparing it to the hash from the previous day."</p>
<p>Got it: 1m lines of today's hash values compared with 1m lines of yesterday's values. </p>
<p>Do lines get inserted or removed? If not, this is a ... | 30,939 |
<p>How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?</p>
| <pre><code>import socket
socket.gethostbyname(socket.gethostname())
</code></pre>
<p>This won't work always (returns <code>127.0.0.1</code> on machines having the hostname in <code>/etc/hosts</code> as <code>127.0.0.1</code>), a paliative would be what gimel shows, use <code>socket.getfqdn()</code> instead. Of course ... | <p>Simple yet sweet!</p>
<pre><code>def getip():
import socket
hostname= socket.gethostname()
ip=socket.gethostbyname(hostname)
return(ip)
</code></pre>
| 20,112 |
<p>My question is quite relevant to <a href="https://stackoverflow.com/questions/42785/how-do-you-retrofit-unit-tests-into-a-code-base">something asked before</a> but I need some practical advice.</p>
<p>I have "Working effectively with legacy code" in my hands and I 'm using advice from the book as I read it in the p... | <p><a href="https://rads.stackoverflow.com/amzn/click/com/0131177052" rel="nofollow noreferrer" rel="nofollow noreferrer">Working Effectively With Legacy Code</a> is the best resource for how to start testing old code. There are really no short term solutions that won't result in things getting worse.</p>
| <p>I personally would continue doing as you are doing or consider having a build script that makes the target application and the unit tests at the same time (two resulting binaries off the same codebase). Yes it smells fishy but it is very practical.</p>
<p>Kudos to you and good luck with your testing.</p>
| 27,587 |
<p>I'm trying to generate code coverage reports with <a href="http://emma.sourceforge.net/" rel="nofollow noreferrer">EMMA</a> using tests of which some use <a href="http://jmockit.dev.java.net" rel="nofollow noreferrer">JMockit</a> as a mocking framework. For the most part, it works, but a few of my tests crash with a... | <p>Seems to be a bug in JMockit: After the class was already instrumented by EMMA, JMockit seems to have issues creating "reentry=true" mock methods.</p>
<p>Removing the "reentry=true" "worked around" the issue.</p>
| <p>From where and how to remove this "reentry=true"</p>
| 31,612 |
<p>Compiling a C++ file takes a very long time when compared to C# and Java. It takes significantly longer to compile a C++ file than it would to run a normal size Python script. I'm currently using VC++ but it's the same with any compiler. Why is this?</p>
<p>The two reasons I could think of were loading header files... | <p>Several reasons</p>
<h1>Header files</h1>
<p>Every single compilation unit requires hundreds or even thousands of headers to be (1) loaded and (2) compiled.
Every one of them typically has to be recompiled for every compilation unit,
because the preprocessor ensures that the result of compiling a header <em>might<... | <p>In large object-oriented projects, the significant reason is that C++ makes it hard to confine dependencies.</p>
<p>Private functions need to be listed in their respective class' public header, which makes dependencies more transitive (contagious) than they need to be:</p>
<pre><code>// Ugly private dependencies
#in... | 41,149 |
<p>I have a bunch of Eclipse plugins and features, which I would like to build as part of a nightly (headless) build. I've managed to do this using a complicated setup involving manually specifying paths to Eclipse plugin jars, copying customTargets.xml, etc. </p>
<p>Is there really no simpler solution? Isn't there a ... | <p><em>Given that all the answers to this question are all 3-5 years old, I figure an update would be useful to others.</em></p>
<p>For those who want to add the building of Eclipse plugins to the CI process, I recommend they check out the <a href="http://eclipse.org/tycho/" rel="noreferrer">Eclipse Tycho project</a>.... | <p>You might look into buckminster and maven. There is a learning curve for sure, but they seem to do their jobs well.</p>
| 16,129 |
<p>Who here is using WASP (<a href="http://wasp.sourceforge.net/content/" rel="nofollow noreferrer">http://wasp.sourceforge.net/content/</a>) to in real world applications? What impressions do you have? Good? Bad? If you can provide any inputs, how good it is comparing with rails for example.</p>
<p>I'm really looking... | <p>I downloaded it a while ago and tried it out, but as the documentation is pretty terrible at the moment (consisting of some auto-generated 'documentation' that was useless) I gave up pretty quickly. I think one of the most important things to have in a framework is clear, thorough documentation - if you have to spen... | <p>Check out symfony, too. Free software, top-notch documentation.</p>
| 13,511 |
<p>Does anybody have experience using the open source offering from Terracotta as opposed to their enterprise offering? Specifically, I'm interested if it is worth the effort to use terracotta without the enterprise tools to manage your cluster?</p>
<p>Over-simplified usage summary: we're a small startup with limited ... | <p>At the moment, the Terracotta enterprise tools provide only a few features beyond the open source version around things like visualization and management (like the ability to kick a client out of the cluster). That will continue to diverge and the enterprise tools are likely to boast more operator-level functionali... | <p><strong>Update</strong></p>
<p>What I see in the OP message is "well, I don't really know what we need (thus the lack of detailed requirements), but may be some enterprizey tool will magically solve all our problems, known and unforeseen? That would be <em>awesome</em>!" </p>
<p>With an architectural approach like... | 35,353 |
<p>I need your help in determining the best approach for analyzing industry-specific sentences (i.e. movie reviews) for "positive" vs "negative". I've seen libraries such as OpenNLP before, but it's too low-level - it just gives me the basic sentence composition; what I need is a higher-level structure:
- hopefully wit... | <p>What you are looking for is commonly dubbed <a href="http://en.wikipedia.org/wiki/Sentiment_analysis" rel="noreferrer">Sentiment Analysis</a>. Typically, sentiment analysis is not able to handle delicate subtleties, like sarcasm or irony, but it fares pretty well if you throw a large set of data at it.</p>
<p>Senti... | <p>Some approaches to sentiment analysis use strategies popular on other text classification tasks. The most common being transforming your film review into a word vector, and feeding it into a classifier algorithm as training data. Most popular data mining packages can help you here. You could have a look at this <a h... | 14,913 |
<p>My app generates PDFs for user consumption. The "Content-Disposition" http header is set as mentioned <a href="https://stackoverflow.com/questions/74019/specifying-filename-for-dynamic-pdf-in-aspnet">here</a>. This is set to "inline; filename=foo.pdf", which should be enough for Acrobat to give "foo.pdf" as the fi... | <p>Part of the problem is that the relevant <a href="http://greenbytes.de/tech/webdav/rfc2183.html" rel="noreferrer">RFC 2183</a> doesn't really state what to do with a disposition type of "inline" and a filename.</p>
<p>Also, as far as I can tell, the only UA that actually uses the filename for type=inline is Firefo... | <p>Try this, if your executable is "get.cgi"</p>
<p><a href="http://server,org/get.cgi/filename.pdf?file=filename.pdf" rel="nofollow noreferrer">http://server,org/get.cgi/filename.pdf?file=filename.pdf</a></p>
<p>Yes, it's completely insane. There is no file called "filename.pdf" on the server, there is directory at ... | 18,215 |
<p>I have the following:</p>
<pre><code>classA::FuncA()
{
... code
FuncB();
... code
}
classA::FuncB(const char *pText)
{
SelectObject(m_hDC, GetStockObject ( SYSTEM_FONT));
wglUseFontBitmaps(m_hDC, 0, 255, 1000);
glListBase(1000);
glCallLists(static_cast<GLsizei>(strlen(pText)), GL_UNS... | <p>Make sure all compiler optimizations are disabled (/Od). Compiler optimization can cause problems with debugger breakpoints.</p>
| <p>If everything fails try updating to VS2005 SP1 if you don't already have it...</p>
<p>Sounds strange indeed!</p>
| 38,891 |
<p>What do you find is the optimal setting for mysql slow query log parameter, and why?</p>
| <p>I recommend these three lines</p>
<pre>
log_slow_queries
set-variable = long_query_time=1
log-queries-not-using-indexes
</pre>
<p>The first and second will log any query over a second. As others have pointed out a one second query is pretty far gone if you are a shooting for a high transaction rate on your website... | <p>Not only is it a blunt instrument as far as resolution is concerned, but also it is MySQL-instance wide, so that if you have different databases with differing performancy requirements you're kind of out of luck. Obviously there are ways around that, but it's important to keep that in mind when setting your slow lo... | 11,764 |
<p>I need to print a thin piece.
Theoretically, it could work, but Cura prints the walls as single lines.
In my case, it is just this line that breaks apart as you can see here.</p>
<p>Is there a setting that would instruct Cura to avoid creating such a line as the outer wall, or how else could I resolve this problem?<... | <p>The raft still needs to fit on the bed, and it counts as a print, because, it is printed. You want the raft for better adhesion, so that means that you need more contact with the bed. If you’re not, your basically wasting filament. Its kinda logical actually.</p>
| <h2>Adjusted model Dimensions</h2>
<p>The model has the size determined by the base area of the bounding box, in this case, <span class="math-container">$\pu{190 \times 200 mm }$</span>. The raft as told by OP adds 15mm on <strong>all</strong> sides of the model, and thus adds 30 mm in total on both the X and Y dimensi... | 2,224 |
<p>I want to know what is the difference between a query and a view in terms of performance. And if a view is costly, what else besides a query could I do to improve performance?</p>
| <p>Views and ad-hoc queries, in the simple case, are nearly identical in terms of performance. So much so that when you program with a view, you should think of it as though the text of the view definition were being cut and pasted into your parent query. </p>
<p>HLGEM points out in his answer that certain editions ... | <p>If you mean network performance then working from a local cache (as with ADO.Net DataSets) would reduce network traffic- but could cause problems with locking. Just a thought.</p>
| 41,978 |
<p>We are ready to start a brand new project at work, no legacy code. We did use Subsonic in the past and we pretty happy with it. But that was before Linq.</p>
<p>Has anyone had to face this same issue (Linq x Subsonic)? </p>
<p>What was your decision? What were the reasons?</p>
<p>Any insight appreciated.</p>
| <p><strong>SubSonic</strong></p>
<p>Pros:</p>
<ul>
<li>Nice and simple</li>
<li>Scaffolding</li>
</ul>
<p>Cons:</p>
<ul>
<li>Method signatures often accept string parms (though you're encouraged to use DAO string constants) which can be abused.</li>
</ul>
<p>Keep in mind:</p>
<ul>
<li>Requires Website project for... | <p>The biggest risk with linq to sql is that Microsoft will grow tired of it and abandon it. There is a lot of speculation that this has already happened and that only the entity framework will be updated. Subsonic does not suffer from this and worse case you have the source code to make your edits.</p>
| 31,146 |
<p>how do i make an autocomplete textbox in asp?
but i need to get the autocomplete data by querying the database.
I dont really know how to explain this, sory if theres not enough detail.
i cant use ajax, because i think i will have compability issues with my old app.
so im thinking of doing this using java script. ... | <p>It's going to be a lot of effort without using some third party autocomplete I think - not sure what you mean by 'I can't use ajax', but how about using the <a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx" rel="nofollow noreferrer">ASP.NET AJAX autocomplete control</a>, set... | <p>The ASP.NET AJAX framework works for ASP.NET 2.0 & above. As such it will not work in Visual Studio 2003 environment.</p>
<p>Anthem.NET is a free, cross-browser AJAX toolkit/framework for the ASP.NET development environment that works with both ASP.NET 1.1 and 2.0 -
<a href="http://sourceforge.net/projects/anth... | 36,913 |
<p>I'm using an Ubuntu 8.04 (x86_64) machine to connect to my employer's Cisco VPN. (The client didn't compile out of the box, but I found <a href="http://projects.tuxx-home.at/?id=cisco_vpn_client" rel="nofollow noreferrer">patches to update the client to compile on kernels released in the last two years</a>.) This al... | <p>If you are running without NetworkManager handling the connections, use the resolvconf package to act as an intermediary to programs tweaking /etc/resolv.conf: <strong><code>sudo apt-get install resolvconf</code></strong></p>
<p>If you are using NetworkManager it will handle this for you, so get rid of the resolvco... | <p>vpnc seems to be doing the right thing for my employer's cisco concentrator. I jump on and off the vpn, and it seems to update everything smoothly.</p>
| 7,047 |
<p>There is previous little on the google on this subject other than people asking this very same question.</p>
<p>How would I get started writing my own firewall?</p>
<p>I'm looking to write one for the windows platform but I would also be interested in this information for other operating systems too.
... | <p>For Windows 2000/XP there is an article with examples on CodeProject <a href="http://www.codeproject.com/KB/IP/drvfltip.aspx" rel="noreferrer">Developing Firewalls for Windows 2000/XP</a><br><br>For Vista I think you will need to use <a href="http://www.microsoft.com/whdc/device/network/wfp.mspx" rel="noreferrer">Wi... | <p>The usual approach is to use API hooking. Google can teach you that. Just hook all important networking stuff, like <code>connect</code>'s and <code>listens</code>'s, and refuse what you want.</p>
| 3,896 |
<p>Does anybody know if it's possible, and how, to programmatically send a <strong>SMS</strong> from the <code>iPhone</code>, with the official SDK / Cocoa Touch?</p>
| <h3>Restrictions</h3>
<p>If you could send an SMS within a program on the iPhone, you'll be able to write games that spam people in the background. I'm sure you really want to have spams from your friends, "Try out this new game! It roxxers my boxxers, and yours will be too! roxxersboxxers.com!!!! If you sign up now... | <p>You need to use the <strong>MFMessageComposeViewController</strong> if you want to show creating and sending the message in your own app.</p>
<p>Otherwise, you can use the <strong>sharedApplication</strong> method.</p>
| 3,201 |
<p>I've been trying a lot of different things to combat corners curling upward in the first few tens of layers after the bottom skin. To be clear, I'm not talking about corners of the first layer printed on the bed, but rather the points of the outline in layers above the base where direction of print motion changes di... | <p>While I tried a lot of things to solve this, including tuning temperature, fan, speed, etc., ultimately the single biggest factor that causes or prevents it is the state of Cura's <em>Outer Before Inner Walls</em> (<code>outer_inset_first</code>) option. With outer walls first, I don't have the problem at all. With ... | <p>Cura has an additional setting that you can make visible called "Lift Head". My recommendation is that you do the following:</p>
<ol>
<li>Set your minimum print speed to something actually reasonable like 30mm/s or higher. Printing too slowly negates the following two settings and is not beneficial to printing smal... | 1,408 |
<p>I am attempting to create a UML diagram representative of some Java code.</p>
<p>In a class I have a method that is overloaded.</p>
<p>As far as I know, parameters for methods aren't shown in UML diagrams.</p>
<p>How do I represent method overloading in UML?</p>
<p>Thanks.</p>
| <p>Check the display options for the entire diagram or the individual class/interface. Most UML tools have options to display show the parameter list of methods.</p>
| <p>Most of the answers above are correct given a certain question. Alepuzio, Vincent and bmatthews68 all have answers that make sense in context.</p>
<p>** If the question is around Overriding of a super classes method with the same signature than redefining is the correct definition. If it is overloading in that you... | 42,714 |
<p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| <p>From an efficiency perspective, you're not going to beat </p>
<pre><code>s.translate(None, string.punctuation)
</code></pre>
<p>For higher versions of Python use the following code:</p>
<pre><code>s.translate(str.maketrans('', '', string.punctuation))
</code></pre>
<p>It's performing raw string operations in C w... | <p>I like to use a function like this:</p>
<pre><code>def scrub(abc):
while abc[-1] is in list(string.punctuation):
abc=abc[:-1]
while abc[0] is in list(string.punctuation):
abc=abc[1:]
return abc
</code></pre>
| 33,352 |
<p>I am using NHibernate on a new ASP.NET project, and am running into what I believe to be strange behavior. I am attempting to manage my session by using an HttpModule to catch the EndRequest event and close the session. This is working fine, however, after the EndRequest event fires, I am getting an exception in t... | <p>I just had a 'palm slaps forehead' moment. Despite the fact that I am in fact deploying to an IIS 7 server, I have been debugging using the VS 2008 Built in Web server (Casini). Casini passes all requests through the ASP.NET pipeline, IIS does not. This was causing a request for an image file or javascript file (... | <p>use HttpModule if you need lazy loading. Inherit your class from it and then you'd have two methods you can override (can't remember their names). First one is called each time any page is requested. Open the session there and put the session in viewstate. The other method is called when page is posted back, close y... | 42,927 |
<p>How does the <strong>open-source/free software community</strong> develop drivers for products that offer no documentation?</p>
| <p>How do you reverse engineer something?</p>
<ul>
<li>You observe the input and output, and develop a set of rules or models that describe the operation of the object.</li>
</ul>
<p>Example:</p>
<p>Let's say you want to develop a USB camera driver. The "black box" is the software driver.</p>
<ol>
<li>Develop hook... | <p>This is a pretty vague question, but I would say <a href="http://en.wikipedia.org/wiki/Reverse_engineering" rel="nofollow noreferrer">reverse engineering</a>. How they go about that is dependent on what kind of device it is and what is available for it. In many cases the device may have a similar core chipset to ano... | 8,372 |
<p>I have a new 1 TB drive coming in tomorrow. What is the best way to divide this space for a development workstation?</p>
<p>The biggest problem I think I'm going to have is that some partitions (probably /usr) will become to small after a bit of use. Other partitions are probably to huge. The swap drive for example... | <p>If you partition your drive using <a href="http://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)" rel="noreferrer">LVM</a> you won't have to worry about any individual partition running out of space in the future. Just move space around as necessary.</p>
| <p>Please tell me what are you doing to /boot that you need more than 64MB on it? Unless you never intend to clean it, anything more is a waste of space. Kernel image + initrd + System.map won't take more than 10MB (probably less - mine weight 5MB) and you really don't need to keep more than two spares.</p>
<p>And wit... | 3,773 |
<p>My database is located in e.g. california.
My user table has all the user's timezone e.g. -0700 UTC </p>
<p>How can I adjust the time from my database server whenever I display a date to the user who lives in e.g. new york? UTC/GMT -4 hours</p>
| <p>You should store your data in UTC format and showing it in local timezone format.</p>
<pre><code>DateTime.ToUniversalTime() -> server;
DateTime.ToLocalTime() -> client
</code></pre>
<p>You can adjust date/time using AddXXX methods group, but it can be error prone. .NET has support for time zones in <a href="... | <p>Up until .NET 3.5 (VS 2008), .NET does not have any built-in support for timezones, apart from converting to and from UTC.</p>
<p>If the time difference is always exactly 3 hours all year long (summer and winter), simply use <strong><code>yourDate.AddHours(3)</code></strong> to change it one way, and <strong><code>... | 14,414 |
<p>The following query returns strange results for me:</p>
<pre><code>SELECT
`Statistics`.`StatisticID`,
COUNT(`Votes`.`StatisticID`) AS `Score`,
COUNT(`Views`.`StatisticID`) AS `Views`,
COUNT(`Comments`.`StatisticID`) AS `Comments`
FROM `Statistics`
LEFT JOIN `Votes` ON `Votes`.`StatisticID` = `Statis... | <p>Assuming you have an id field or similar on the votes/views/comments:</p>
<pre><code>SELECT
`Statistics`.`StatisticID`,
COUNT(DISTINCT `Votes`.`VoteID`) AS `Score`,
COUNT(DISTINCT `Views`.`ViewID`) AS `Views`,
COUNT(DISTINCT `Comments`.`CommentID`) AS `Comments`
FROM `Statistics`
LEFT JOIN `Votes` O... | <p>When joining like this, you will duplicate the data as many times as you find mathing rows in the other tables. This is fine, if you only have 1 corresponding row in each table.</p>
<p>Run this query without the grouping, and you will get an idea on why you get the same result on all counts. I would however have gu... | 39,503 |
<p>As the question implies, I'm looking for a way to programmatically screen grab a given panorama, I.E set a longitude and latitude and POV (pitch, yaw and zoom) and save the grab to the server. So far the most promise has been shown by </p>
<ol>
<li><p>Using .net to control the google earth com api (<a href="http://... | <p>Are you concerned with licensing? I would suspect that google limits what you can do with StreetView data, and likely prohibits "screen scraping"... </p>
<p>Assuming that you figured out how not to get sued by google, one option might be to trace the HTTP requests generated by the street view SWF, and try to revers... | <p>If you have the co-ordinates, POV and other variables then you can use Google Street View Image API </p>
<p><a href="https://developers.google.com/maps/documentation/streetview/" rel="nofollow">https://developers.google.com/maps/documentation/streetview/</a></p>
<p>For Instance - </p>
<pre><code>http://maps.googl... | 32,166 |
<p>With a class in Python, how do I define a function to print every single instance of the class in a format defined in the function?</p>
| <p>I see two options in this case:</p>
<h2>Garbage collector</h2>
<pre><code>import gc
for obj in gc.get_objects():
if isinstance(obj, some_class):
dome_something(obj)
</code></pre>
<p>This has the disadvantage of being very slow when you have a lot of objects, but works with types over which you have no... | <p>In my project, I faced a similar problem and found a simple solution that may also work for you in listing and printing your class instances. The solution worked smoothly in Python version 3.7; gave partial errors in Python version 3.5.</p>
<p>I will copy-paste the relevant code blocks from my recent project.</p>
<p... | 42,611 |
<p>So I have a relatively large (enough code that it would be easier to write this CMS component from scratch than to rewrite the app to fit into a CMS) webapp that I want to add basic Page/Menu/Media management too, I've seen several Django pluggables addressing this issue, but many seem targeted as full CMS platforms... | <p>I have worked with all three (and more) and they are all built for different use cases IMHO. I would agree that these are the top-teir choices.</p>
<p>The grid comparison at djangopluggables.com certainly can make evaluating each of these easier.</p>
<p><strong>django-cms</strong> is the most full-featured and is ... | <p>I've had success with integrating <a href="http://django-cms.org" rel="nofollow noreferrer">django-cms</a>. Just include it at the end of your urlconf and it won't interfere. (You'll just lose the the nice 404 page when <code>DEBUG=True</code>)</p>
<p>Using various combinations of context processors and custom te... | 38,921 |
<p>I'm considering using AMQP (using qpid) to enable a mixture of Python and Java services communicate with each other. Basic text messaging seems simple enough but, as with every other messaging technology I've investigated, that's where it seems to stop. Except for building instant messaging applications, I would hav... | <p>Owen, may I offer a few words about RabbitMQ. </p>
<p>AMQP is a binary protocol and you can certainly do much more than send strings around! Which Python client do you plan to use? We recommend Barry Pederson's client for most uses: <a href="http://barryp.org/software/py-amqplib/" rel="noreferrer">http://barryp.... | <p>XML or JSON are probably the easiest. Protocol buffers is cool but I'd treat it as an optimisation to think of later on if you really need to (as its a bit harder to use being essentially a binary wire format).</p>
<p>BTW you might want to look at Stomp rather than AMQP; its got way more client libraries and suppor... | 42,916 |
<p>How do I push my content to the top of the page to not cover up the ad, but to cover the menu and myspace links. I want to do something similar to: <a href="http://www.myspace.com/sensesfail" rel="nofollow noreferrer">http://www.myspace.com/sensesfail</a> and <a href="http://www.myspace.com/attackattack" rel="nofoll... | <p>Absolute positioning could work, or you could use negative margins.</p>
| <p>without dissecting the html source of the links you provided (because i am much too lazy to do all your work for you), my best guess is that they used absolute positioning (or negative relative positioning) and a high z-index to float their picture over the default banner</p>
| 28,682 |
<p>In my app i need to save changed values (old and new) when model gets saved. Any examples or working code?</p>
<p>I need this for premoderation of content. For example, if user changes something in model, then administrator can see all changes in separate table and then decide to apply them or not.</p>
| <p>You haven't said very much about your specific use case or needs. In particular, it would be helpful to know what you need to do with the change information (how long do you need to store it?). If you only need to store it for transient purposes, @S.Lott's session solution may be best. If you want a full audit tr... | <p>for everyone's information, muhuk's solution fails under python2.6 as it raises an exception stating 'object.__ init __()' accepts no argument...</p>
<p>edit: ho! apparently it might've been me misusing the the mixin... I didnt pay attention and declared it as the last parent and because of that the call to <stro... | 13,598 |
<p>I want to loop over the contents of a text file and do a search and replace on some lines and write the result back to the file. I could first load the whole file in memory and then write it back, but that probably is not the best way to do it.</p>
<p>What is the best way to do this, within the following code?</p>
... | <p>I guess something like this should do it. It basically writes the content to a new file and replaces the old file with the new file:</p>
<pre><code>from tempfile import mkstemp
from shutil import move, copymode
from os import fdopen, remove
def replace(file_path, pattern, subst):
#Create temp file
fh, abs_... | <p>if you remove the indent at the like below, it will search and replace in multiple line.
See below for example.</p>
<pre><code>def replace(file, pattern, subst):
#Create temp file
fh, abs_path = mkstemp()
print fh, abs_path
new_file = open(abs_path,'w')
old_file = open(file)
for line in old_... | 6,013 |
<p>I have a button that I would like to disable when the form submits to prevent the user submitting multiple times.</p>
<p>I have tried naively disabling the button with javascript onclick but then if a client side validation that fails the button remains disabled.</p>
<p>How do I disable the button when the form su... | <p>Give this a whirl:</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
... | <p>Not sure if this will help, but there's onsubmit event in form. You can use this event whenever the form submit (from any button or controls).
For reference: <a href="http://www.htmlcodetutorial.com/forms/_FORM_onSubmit.html" rel="nofollow noreferrer">http://www.htmlcodetutorial.com/forms/_FORM_onSubmit.html</a></p>... | 13,206 |
<p>I'm trying to understand what this method means as I'm reading <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.getpostbackeventreference.aspx" rel="noreferrer">this</a> and have wondered what uses this may have. I don't quite understand the example given.</p>
<p>Can anyone give an... | <p>The simplest example is a LinkButton. Drop one in a page and look at the HTML it generates. You'll see something like.</p>
<pre><code>href="javascript:__doPostBack('ctl00$LinkButton1','')"
</code></pre>
<p>GetPostBackEventReference allows you to get that piece of JavaScript, so that you can trigger that postback f... | <p>As steve mentioned this can be used for </p>
<blockquote>
<p>GetPostBackEventReference allows you to get that piece of JavaScript, so that you can trigger that postback from elsewhere.</p>
</blockquote>
<p>To give an example, you can use this function to get reference to PostBack event of button click and add it... | 33,481 |
<p>Below I have a very simple example of what I'm trying to do. I want to be able to use HTMLDecorator with any other class. Ignore the fact it's called decorator, it's just a name.</p>
<pre><code>import cgi
class ClassX(object):
pass # ... with own __repr__
class ClassY(object):
pass # ... with own __repr__
... | <blockquote>
<p>Very close, but then I lose everything from ClassX. Below is something a collegue gave me that does do the trick, but it's hideous. There has to be a better way.</p>
</blockquote>
<p>Looks like you're trying to set up some sort of proxy object scheme. That's doable, and there are better solutions tha... | <blockquote>
<p>Is what I'm trying to do possible? If so, what am I doing wrong?</p>
</blockquote>
<p>It's certainly possible. What's wrong is that <code>HTMLDecorator.__init__()</code> doesn't accept parameters.</p>
<p>Here's a simple example:</p>
<pre><code>def decorator (func):
def new_func ():
retu... | 5,817 |
<p>I have a strange problem when I publish my website. I inherited this project and the problem started before I arrived so I don't know what conditions lead to the creation of the problem.</p>
<p>Basically, 3 folders below the website project fail to publish properly. When the PrecompiledWeb is transferred to the hos... | <p>I would try cleaning the bin\ folder.
In any case our shop completely dropped websites in favour of web form applications, which are arguably far better.</p>
<p>EDIT: <a href="http://webproject.scottgu.com/CSharp/Migration2/Migration2.aspx" rel="nofollow noreferrer">Migration HOW TO here</a></p>
| <p>I had a similar problem a while back, where the publish would say it was successful, but the publish folder remained empty.</p>
<p>Besides looking at the <a href="http://msdn.microsoft.com/en-us/asp.net/aa336619.aspx" rel="nofollow noreferrer">Web Deployment Projects</a> you should also set the verbosity to Diagnos... | 8,955 |
<p>I'm trying to create a <em>fast</em> 2D point inside polygon algorithm, for use in hit-testing (e.g. <code>Polygon.contains(p:Point)</code>). Suggestions for effective techniques would be appreciated.</p>
| <p>For graphics, I'd rather not prefer integers. Many systems use integers for UI painting (pixels are ints after all), but macOS, for example, uses float for everything. macOS only knows points and a point can translate to one pixel, but depending on monitor resolution, it might translate to something else. On retina ... | <p>This only works for convex shapes, but Minkowski Portal Refinement, and GJK are also great options for testing if a point is in a polygon. You use minkowski subtraction to subtract the point from the polygon, then run those algorithms to see if the polygon contains the origin.</p>
<p>Also, interestingly, you can ... | 26,739 |
<p>I have a user defined function in SQL called getBuisnessDays it takes @startdate and @enddate and returns the number of business days between the two dates. How can I call that function within my select?</p>
<p>Here's what I'd like to do.. </p>
<pre><code>SELECT getBusinessDays(a.opendate,a.closedate)
FROM accoun... | <p>Yes, you can do almost that: </p>
<pre><code>SELECT dbo.GetBusinessDays(a.opendate,a.closedate) as BusinessDays
FROM account a
WHERE...
</code></pre>
| <p>Use a scalar-valued UDF, not a table-value one, then you can use it in a SELECT as you want.</p>
| 47,497 |
<p>Within a stored procedure, another stored procedure is being called within a cursor. For every call, the SQL Management Studio results window is showing a result. The cursor loops over 100 times and at that point the results window gives up with an error. Is there a way I can stop the stored procedure within the cur... | <p>you could insert the results into a temp table, then drop the temp table</p>
<pre><code>create table #tmp (columns)
while
...
insert into #tmp exec @RC=dbo.NoisyProc
...
end
drop table #tmp
</code></pre>
<p>otherwise, can you modify the proc being called to accept a flag telling it not to output a res... | <p>Place:</p>
<pre><code>SET ROWCOUNT OFF
/* the internal SP */
SET ROWCOUNT ON
</code></pre>
<p>wrap that around the internal SP, or you could even do it around the SELECT statement from the originating query, that will prevent results from appearing.</p>
| 26,135 |
<p>Trying to implement a progress dialog window for file uploads that looks like a cross between <a href="http://www.codinghorror.com/blog/images/ie6-download-ui.png" rel="nofollow noreferrer">IE download dialog</a> and <a href="http://www.codinghorror.com/blog/images/firefox2-download-ui.png" rel="nofollow noreferrer"... | <p>"ftplib" is the standard ftp library built in to Python. In Python 2.6, it had a callback parameter added to the method used for uploading.</p>
<p>That callback is a function you provide to the library; it is called once for every block that is completed.</p>
<p>Your function can send a message to the GUI (perhaps... | <p>If you can't use Python 2.6's ftplib, there is a company offering a <em>commercial</em> solution.</p>
<p>Chilkat's <a href="http://www.chilkatsoft.com/refdoc/pythonCkFtp2Ref.html" rel="nofollow noreferrer" title="CKFTP2 Manual">CKFTP2</a> costs several hundreds of dollars, but promises to work with Python 2.5, and ... | 25,390 |
<p><code>DBCC SHRINKFILE</code> always works when I run it manually on a log file, even when I get the following message:</p>
<pre><code>'Cannot shrink log file 2 (Claim_Log) because all logical log files are in use.'
</code></pre>
<p>When I run it from a job, however, it only shrinks the log about one third of the t... | <p>I recently solved a similar issue, I found that in sys.databases, log_reuse_wait_desc was equal to 'replication'. Apparently this means something to the effect of SQL Server waiting for a replication task to finish before it can reuse the log space.</p>
<p>However replication had never been used on our DB nor on ou... | <p>Means Currently the Log file is in Use and issue check point where Check point will writes to datfile that was not written to the datafile from transaction log file (Dirty pages).
Check is there any current Activity is going on or Not, </p>
<p>Check using for Active Transaction
In 2005
SELECT *
FROM sys.dm_tran_... | 46,018 |
<p>I'm guessing it needs to be something like:</p>
<pre><code>CONVERT(CHAR(24), lastModified, 101)
</code></pre>
<p>However I'm not sure of the right value for the third parameter.</p>
<p>Thanks!</p>
<hr>
<p>Well I'm trying to write a script to copy my sql server db to a sqlite file, which gets downloaded to an ai... | <p>Last epoch is when 1970 GMT?</p>
<pre><code>SELECT DATEDIFF(s,'19700101 05:00:00:000',lastModified)
</code></pre>
<p>See also <a href="http://wiki.lessthandot.com/index.php/Epoch_Date" rel="nofollow noreferrer">Epoch Date</a></p>
| <p>Define "last epoch". Does this come close?</p>
<p>Select Cast(lastModified As Integer)</p>
| 3,237 |
<p>I have a data structure that represents a directed graph, and I want to render that dynamically on an HTML page. These graphs will usually be just a few nodes, maybe ten at the very upper end, so my guess is that performance isn't going to be a big deal. Ideally, I'd like to be able to hook it in with jQuery so tha... | <p>I've just put together what you may be looking for: <a href="http://www.graphdracula.net" rel="noreferrer">http://www.graphdracula.net</a></p>
<p>It's JavaScript with directed graph layouting, SVG and you can even drag the nodes around. Still needs some tweaking, but is totally usable. You create nodes and edges eas... | <p>As guruz mentioned, the <a href="http://philogb.github.io/jit/" rel="nofollow noreferrer">JIT</a> has several lovely graph/tree layouts, including quite appealing RGraph and HyperTree visualizations.</p>
<p>Also, I've just put up a super simple SVG-based <a href="http://github.com/jackrusher/jssvggraph" rel="nofoll... | 2,869 |
<p>I need to create a trigger in every database on my sql 2005 instance. I'm setting up some auditing ddl triggers.</p>
<p>I create a cursor with all database names and try to execute a USE statement. This doesn't seem to change the database - the CREATE TRIGGER statement just fires in adventureworks repeatedly. Th... | <p>When you use EXEC() each use is in its own context. So, when you do EXEC('USE MyDB') it switches to MyDB for that context then the command ends and you're back where you started. There are a couple of possible solutions...</p>
<p>You can call sp_executesql with a database name (for example, MyDB..sp_executesql) and... | <p>The first thing I would try is to put the 'USE ' command inside your @command string although if it's complaining that the trigger ddl must be first in the batch, that's unlikely to work. </p>
<p>Do you have access to Visual Studio? This would be fairly quick to code in like a C# console app, leaving you an exe f... | 43,395 |
<p>I have a page where my combo box has hundreds of elements which makes it very hard to pick the one item I want. Is there a good Javascript replacement that would do better than</p>
<pre><code><select id="field-component" name="field_component">
<option selected="selected">1</option... | <p><img src="https://i.stack.imgur.com/TouKN.gif" alt="http://www.dhtmlx.com/images/logo_combo.gif"><br>
You have <a href="http://www.dhtmlx.com/docs/products/dhtmlxCombo/index.shtml" rel="nofollow noreferrer">dhtmlCombo</a>, using ajax to retrieve data when you are filling the input field.</p>
<p>dhtmlxCombo is a cro... | <p>The <a href="http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter" rel="nofollow noreferrer">autocompleter</a> using <a href="http://prototypejs.org" rel="nofollow noreferrer">Prototype</a> and <a href="http://script.aculo.us/" rel="nofollow noreferrer">Scriptaculous</a> works well in this situation.</p... | 32,799 |
<p>I am pulling data out of an old-school ActiveX in the form of arrays of doubles. I don't initially know the final number of samples I will actually retrieve.</p>
<p>What is the most efficient way to concatenate these arrays together in C# as I pull them out of the system?</p>
| <p>You can't append to an actual array - the size of an array is fixed at creation time. Instead, use a <code>List<T></code> which can grow as it needs to.</p>
<p>Alternatively, keep a list of arrays, and concatenate them all only when you've grabbed everything.</p>
<p>See <a href="https://learn.microsoft.com/en-... | <p>Olmo's suggestion is very good, but I'd add this:
If you're not sure about the size, it's better to make it a little bigger than a little smaller. When a list is full, keep in mind it will double its size to add more elements. </p>
<p>For example: suppose you will need about 50 elements. If you use a 50 elements si... | 39,185 |
<p>Since a few days ago, MySQL server on my Windows machine was not successful on closing itself. I found multiple instance of these lines in the MySQL error log:</p>
<pre><code>InnoDB: Operating system error number 32 in a file operation.
InnoDB: The error means that another program is using InnoDB's files.
InnoDB: Th... | <p>If the file is in use by another program then <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="noreferrer">Process Explorer</a> could help you track down which one has it open. I assume you've checked you only have one copy of MySQL running.</p>
| <p>Sounds like a conflict. Make sure to stop the mysqld service and then double-check if it's really not running anymore, then restart the service. Also, when it's back up, make sure to run checks on your tables and see if there is any damage.</p>
<p>My assumption is based on the <a href="http://dev.mysql.com/doc/refm... | 35,971 |
<p>Can someone please point me to the easiest way to have a timer in a Win32 service?</p>
<p>I suppose I could create a dummy window for this purpose or have a second thread do tick counts, but what's best? Is there a more elegant way?</p>
<p>Thanks in advance.</p>
| <p>You can use Timer Queues (<a href="http://msdn.microsoft.com/en-us/library/ms686796.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms686796.aspx</a>). They don't require an HWND.</p>
| <p>Are you just trying to "wake up" every now and then to do some work? You can always use Sleep().</p>
<p>Additionally, I typically have a thread that is in a while(1 == 1) loop with a sleep inside. There I can check for the shutdown request and other misc housekeeping. You could use that system to tickle an event... | 27,676 |
<p>Any recommendations on <a href="http://en.wikipedia.org/wiki/Grep" rel="noreferrer">grep</a> tools for Windows? Ideally ones that could leverage 64-bit OS.</p>
<p>I'm aware of <a href="http://www.cygwin.com/" rel="noreferrer">Cygwin</a>, of course, and have also found <a href="http://www.powergrep.com/" rel="norefe... | <h2>Based on recommendations in the comments, I've started using <a href="https://tools.stefankueng.com/grepWin.html" rel="nofollow noreferrer">grepWin</a> and it's fantastic and <em>free</em>.</h2>
<hr />
<p>(I'm still a fan of <a href="http://www.powergrep.com/" rel="nofollow noreferrer">PowerGREP</a>, but I don't us... | <p>I have <a href="http://en.wikipedia.org/wiki/Cygwin" rel="nofollow">Cygwin</a> installed on my machine and put the Cygwin bin directory in my environmental path, so the Cygwin grep works like normal in a command line which solves all my scripting needs for grep at the moment.</p>
| 11,286 |
<p>Yesterday I thought it would be nice to implement my own Trigger in a WPF app. I created a class MyTrigger which inherited TriggerBase. TriggerBase is a public abstract class. So inheritance isn't a problem. But the constructors inside this class are marked internal. The compiler throws an error because the is no va... | <p>If you want the class to be visible, but only allow it to be subclassed within your own assembly. The subclasses may have public constuctors themselves - or they may be accessed with a factory.</p>
<p>I can't comment on whether that's a good design decision for TriggerBase in WPF, but it's at least reasonable in so... | <p>It's public because it's used as a base class for the triggers that ship with WPF (Trigger, MultiTrigger, EventTrigger, DataTrigger etc). It it wasn't public then you wouldn't be able to flag these classes as public.</p>
<p>The constructors are internal because they don't intend for you to use it yourself. I'd gues... | 48,469 |
<p>I currently have a database that is 20GB in size.
I've run a few scripts which show on each tables size (and other incredibly useful information such as index stuff) and the biggest table is 1.1 million records which takes up 150MB of data. We have less than 50 tables most of which take up less than 1MB of data.</p>... | <p>Try this query:</p>
<pre><code>SELECT object_name(object_id) AS name, rows, total_pages,
total_pages * 8192 / 1024 as [Size(Kb)]
FROM sys.partitions p
INNER JOIN sys.allocation_units a
ON p.partition_id = a.container_id
</code></pre>
| <p>Did you try the dbcc command to shrink the catalog? If you transfer all data to an empty catalog, is it also 20GB?</p>
<p>A database uses a page-based file system, so you might be running into a lot of slack (empty space between pages) due to heavy row removal: if the dbms expects rows to be inserted at that spot, ... | 46,771 |
<p>is there any way of making sure that, one user is logged in only once?</p>
<p>I would like to avoid two different persons logging into the system with the same login/password.</p>
<p>I guess I could do it myself by checking in the django_session table before logging in the user, but I rather prefer using the frame... | <p>Logged in twice is ambiguous over HTTP. There's no "disconnecting" signal that's sent. You can frustrate people if you're not careful.</p>
<p>If I shut down my browser and drop the cookies -- accidentally -- I might be prevented from logging in again. </p>
<p>How would the server know it was me trying to re-log... | <p>A site I did last year was concerned that usernames/passwords might be posted to a forum. I dealt with this by adding a model and a check to the login view that looked at how many unique IPs the name had been used from in the last X hours. I gave the site admins two values in settings.py to adjust the number of hour... | 34,240 |
<p>Has anyone come across this issue?</p>
<p>Seems MS have broken it with their own update:</p>
<blockquote>
<p>A number of people have reported
problems using the ActiveX print
control in the report viewer after
installing Microsoft Update 956391.
Specifically, users receive the error
"Unable to load cl... | <p>Found a Fix:</p>
<ol>
<li><p>First ensure that printing is working from Report Manager (open a report in Report Manager and print from there). </p></li>
<li><p>If it works go to Step 3, if you received the same error you need to install the following patches on the Report Server.</p>
<ul>
<li><p>KB954606 - Securit... | <p>I got this working with out removing any patches. The above patch was not working too. Finally what I did was on the IIS server install the following patch and reset / restart the IIS server.
This is not for report manager application. This is for any ASP.NET Web application developed in .net3.5 using VS2008
<a href... | 44,183 |
<p>I would like to monitor the following system information in Java:</p>
<ul>
<li>Current CPU usage** (percent)</li>
<li>Available memory* (free/total)</li>
<li><p>Available disk space (free/total)</p>
<p>*Note that I mean overall memory available to the whole system, not just the JVM.</p></li>
</ul>
<p>I'm looking ... | <p>Along the lines of what I mentioned <a href="https://stackoverflow.com/questions/25552/using-java-to-get-os-level-system-information#25583">in this post</a>. I recommend you use the <a href="https://github.com/hyperic/sigar" rel="noreferrer">SIGAR API</a>. I use the SIGAR API in one of my own applications and it is... | <pre><code> OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
System.out.println((osBean.getCpuLoad() * 100) + "%");
</code></pre>
<p>import <code>com.sun.management.OperatingSystemMXBean</code></p>
<p>It only starts working after the second call so save t... | 6,937 |
<p>I would like to hear some opinions about using the isolated storage in Silverlight for storing sensitive data. For example, is it OK to store an authentication token (some GUID that identifies a server-side session) in this storage, or is it better to use cookies?</p>
<p>The isolated storage gives an advantage over... | <p>I have a similar situation here, though I use MySQL. Every database has a versions table that contains the version (simply an integer) and a short comment of what has changed in this version. I use a script to update the databases. Every database change can be in one function or sometimes one change is made by multi... | <p>Better don't create additional databases. At first glance you may think that you'll get some performance gain, but actually you get support nightmare. Remember - what can break, does break sooner or later. </p>
<p>It is way simpler to perform and optimize queries in single database. It is much easier manage user pe... | 31,525 |
<p>I am currently looking at the "unload" event of a window to try to determine how the "unload" event was triggered, but am having little success. Is there a way to determine how the javascript event was triggered?</p>
<ul>
<li>Page Refresh</li>
<li>Back Button (or navigate away from the page)</li>
<li>Closing the Br... | <p>No, and if there was it would be browser dependent.
What kind of code are you trying to run when the user closes the page?
Is it to logout the user?
Then the user would not be logged out if the browser crashes or the network connection breaks (and probably not if the computer goes to sleep/hibernation mode).</p>
<p... | <p>I use a method of doing keyboard "sniffing", in that it looks for keydown's of "F5", "ctrl+r", "alt-f4", "backspace" and others, and if it finds them flowing through the keyboard event queue, it sets boolean variables appropriately to trap that status... then I use a "onbeforeunload" function handler, which tests ag... | 37,187 |
<p>My client has an old MS SQL 2000 database that uses varchar(50) fields to store names. He tried to use this database to capture some data (via a web form). Some of the form-fillers are from other countries, and the varchar fields went nutty when some of these folks entered their names. Is it possible to recover the ... | <p>Working from the 5th example.</p>
<p>Ã is ascii #195 (C3).
¼ is ascii #188 (BC).</p>
<p>I'd guess that Müller is meant to be Müller. </p>
<p>If this is UTF-8, based upon
<a href="http://en.wikipedia.org/wiki/UTF-8#Description" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/UTF-8#Description</a></p>
<p>... | <p>You basically need to poke it through libiconv, converting it to UTF8. </p>
<p>A full list of appropriate character sets is going to depend on your application, but you can make some guesses based on the country code. Start with <a href="http://en.wikipedia.org/wiki/8859" rel="nofollow noreferrer">this page on Wiki... | 29,939 |
<p>Pig is a dataflow programming environment for processing very large files. Pig's language is called Pig Latin.</p>
<p>Does anyone know of a good reference manual for <a href="http://wiki.apache.org/pig/" rel="nofollow noreferrer">PigLatin</a>? I'm looking for something that includes all the syntax and commands desc... | <p>The reference manual I work with is in the Wiki: <a href="http://hadoop.apache.org/pig/docs/r0.2.0/piglatin.html" rel="noreferrer">Pig Latin Manual</a>. </p>
<p>It contains all Pig Latin commands with their syntax and examples.</p>
| <p>one can find the documents in the dist. download the latest tar and lookup docs.</p>
| 48,098 |
<p>I've followed every steps in <a href="http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx" rel="nofollow noreferrer">here</a>, but still, the Intellisense for JQuery simply isn't working, any ideas?</p>
| <p>I <a href="http://itscommonsensestupid.blogspot.com/2008/11/potential-jquery-intellisenses-bug.html" rel="nofollow noreferrer">got the problem solved</a>. It turns out that I didn't reference the JQuery script file properly. </p>
| <p>I think I had to reload the files or the project or something to get it working. IME it's a bit like all MS Intellisense - you never quite know if you're going to get anything or what it's going to be...</p>
<p>No doubt JetBrains and WholeTomato will along soon enough to fix it.</p>
| 40,890 |
<p>How can I iterate over each file in a directory using a <code>for</code> loop?</p>
<p>And how could I tell if a certain entry is a directory or if it's just a file?</p>
| <p>This lists all the files (and only the files) in the current directory and its subdirectories recursively:</p>
<pre><code>for /r %i in (*) do echo %i
</code></pre>
<p>Also if you run that command in a batch file you need to double the % signs.</p>
<pre><code>for /r %%i in (*) do echo %%i
</code></pre>
<p>(thanks @ag... | <p>In my case I had to delete all the files and folders underneath a temp folder. So this is how I ended up doing it. I had to run two loops one for file and one for folders. If files or folders have spaces in their names then you have to use " "</p>
<pre><code>cd %USERPROFILE%\AppData\Local\Temp\
rem files only
for /... | 16,768 |
<p>Please bear with me, I'm just learning C++. </p>
<p>I'm trying to write my header file (for class) and I'm running into an odd error.</p>
<pre><code>cards.h:21: error: expected unqualified-id before ')' token
cards.h:22: error: expected `)' before "str"
cards.h:23: error: expected `)' before "r"
</code></pre>
<p>... | <p>Your issue is your <code>#define</code>. You did <code>#define Card</code>, so now everywhere <code>Card</code> is seen as a token, it will be replaced.</p>
<p>Usually a <code>#define Token</code> with no additional token, as in <code>#define Token Replace</code> will use the value <code>1</code>.</p>
<p>Remove th... | <p>Remove the <strong>#define Card</strong>.</p>
| 13,161 |
<p>Using PHP, what's the fastest way to convert a string like this: <code>"123"</code> to an integer?</p>
<p>Why is that particular method the fastest? What happens if it gets unexpected input, such as <code>"hello"</code> or an array?</p>
| <p>I've just set up a quick benchmarking exercise:</p>
<pre><code>Function time to run 1 million iterations
--------------------------------------------
(int) "123": 0.55029
intval("123"): 1.0115 (183%)
(int) "0": 0.42461
intval("0"): 0.95683 (2... | <p>More ad-hoc benchmark results:</p>
<pre><code>$ time php -r 'for ($x = 0;$x < 999999999; $x++){$i = (integer) "-11";}'
real 2m10.397s
user 2m10.220s
sys 0m0.025s
$ time php -r 'for ($x = 0;$x < 999999999; $x++){$i += "-11";}'
real 2m1.724s
user 2m1.635s
sys 0m0.009s
... | 29,584 |
<p>I am new to sharepoint development but have about 10 years of expirence in C++, VB6 and C#. It is my experience that a great way to learn a new language or coding style is to spend some time "dissecting" one of the open source projects available at CodePlex or Google code.
In order to avoid picking up some bad habi... | <p>I would also recommend the CKS but I would also add that I have found that coding isn't the biggest issue when learning SharePoint but determining the best solution to acheive your goal. Should you use a workflow or an event handler? Should you use custom code or the BDC? Should you build a web part or a layout page... | <p>Generally speaking, SharePoint "code" will come in the form of web parts and pages that are written for specific SharePoint installations. However, that doesn't mean that there aren't any SharePoint utilities and libraries out there.</p>
<p>In fact, I'm a big fan of <a href="http://www.codeplex.com/smartpart" rel="... | 28,107 |
<p>This is probably explained more easily with an example. I'm trying to find a way of turning a relative URL, e.g. "/Foo.aspx" or "~/Foo.aspx" into a full URL, e.g. <a href="http://localhost/Foo.aspx" rel="noreferrer">http://localhost/Foo.aspx</a>. That way when I deploy to test or stage, where the domain under which ... | <p>Have a play with this (modified <a href="http://web.archive.org/web/20130730034405/http://www.aspdotnetfaq.com/Faq/how-to-convert-relative-url-to-absolute-url-in-asp-net-page.aspx" rel="noreferrer">from here</a>)</p>
<pre><code>public string ConvertRelativeUrlToAbsoluteUrl(string relativeUrl) {
return string.Fo... | <p>Ancient question, but I thought I'd answer it since many of the answers are incomplete.</p>
<pre><code>public static string ResolveFullUrl(this System.Web.UI.Page page, string relativeUrl)
{
if (string.IsNullOrEmpty(relativeUrl))
return relativeUrl;
if (relativeUrl.StartsWith("/"))
relative... | 15,355 |
<p>I didn't upgrade to Vista until May or so and one of the things I've always heard developers I know in real life say is "first thing you should do is turn off that UAC crap"</p>
<p>Well, I've left it on this whole time for a few reasons. First, just as a failsafe in case I do something idiotic like have a momentary... | <p>I think it is necessary to leave UAC on on a test machine, so you can see what a real user would see using your app. However, I turn it off on my development machine since I find it distracting, and I trust myself enough to not need it.</p>
<p>(Hopefully your test machine != your dev machine right?)</p>
<p>All thi... | <p>If you stay on Vista, turn off UAC and rely on Microsoft Security Essentials' real-time monitor to intercept anything that wants to alter your system. Or, upgrade to Win7, where you can leave UAC on and control the levels at which you want UAC to notify and interrupt the execution.</p>
<p>EDIT: It's very easy to ex... | 15,617 |
<p>Is there a way to have Visual Studio 2008 automatically add heading information to files? For example, "Copyright 2008" or something along those lines. I've been digging through the options, but nothing seems to be jumping out at me.</p>
| <p>I assume you'd like to modify the class file templates. They're in:</p>
<pre><code>%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
</code></pre>
<p><a href="http://blogs.southworks.net/jpgarcia/2008/09/01/visual-studio-2008-templates-compliant-with-microsoft-stylecop/" rel="n... | <p>I found a better solution than modifying the template file directly. This utility allows you to create and save header/footer templates and apply them to entire source trees.</p>
<p><a href="http://code.msdn.microsoft.com/HeaderDesigner" rel="nofollow noreferrer">C# Header Designer</a> from MSDN Code Gallery</p>
| 17,702 |
<p>From what I understand, UV curing of resin prints works by starting a chemical reaction that hardens the resin permanently.</p>
<p>Also, a curing step after print is needed to speed up the print and also to reduce the curing during print, which would cure resin beyond the current layer.</p>
<p>However, what is the... | <p>A wide line works if there is something below it to squeeze the filament against, but if you don't have a full layer below it, it will stay thinner and it will droop. I would not use extreme ratios on overhangs. Still, do a parametric test: a overhang tower (a compact one) at different line widths and layer heights.... | <p>In terms of Cura's model for showing overhangs, I'm nearly sure it's just the ratio - rise over run, or rather run over rise. And indeed that's what makes sense mathematically:</p>
<p>At least some portion of the wall extrusion in layer N+1 needs to sit on top of the corresponding wall extrusion in layer N. For a g... | 1,665 |
<p>Is there any way to do it? I only have client access and no access to the server. Is there a command I've missed or some software that I can install locally that can connect and find a file by filename?</p>
| <p>You could grep the output of</p>
<pre><code>cvs rlog -Nh .
</code></pre>
<p>(note the period character at the end - this effectively means: the whole repository).</p>
<p>That should give you info about the whole shebang including removed files and files added on branches.</p>
| <p>You can use</p>
<pre><code> cvs rls -Rde <modulename>
</code></pre>
<p>which will give you all files in recursively, e.g.</p>
<pre><code>foo:
/x.py/1.2/Mon Dec 1 23:33:51 2008//
/y.py/1.1/Mon Dec 1 23:33:31 2008//
D/bar////
foo/bar:
/xxx/1.1/Mon Dec 1 23:36:38 2008//
</code></pre>
<p>Notice that the -... | 43,033 |
<p>I'm gearing up to do some Ajax style client-side JavaScript code in the near future, and I've heard rave reviews of jQuery when it comes to this realm. What I'm wondering is:</p>
<ul>
<li><strong>What are all the cross-browser JavaScript libraries out there?</strong></li>
</ul>
<p>What is the experience using them... | <p>An excellent resource is <a href="https://blog.codinghorror.com/secrets-of-the-javascript-ninjas/" rel="nofollow noreferrer">Jeff Atwood's post on JavaScript libraries</a>. </p>
<p>He lists:</p>
<ol>
<li><a href="https://en.wikipedia.org/wiki/Prototype_JavaScript_Framework" rel="nofollow noreferrer">Prototype</a> ... | <p>Do have a closer look at <a href="http://en.wikipedia.org/wiki/MooTools" rel="nofollow noreferrer">MooTools</a>.</p>
| 12,367 |
<p>I've had to do some introspection in python and it wasn't pretty:</p>
<pre><code>name = sys._getframe(1).f_code
name = "%s:%d %s()" %(os.path.split(name.co_filename)[1],name.co_firstlineno,name.co_name)
</code></pre>
<p>To get something like</p>
<pre><code>foo.py:22 bar() blah blah
</code></pre>
<p>In our debugg... | <p>A print statement does its IO through "sys.stdout.write" so you can override sys.stdout if you want to manipulate the print stream.</p>
| <p>The python <a href="http://www.python.org/doc/current/lib/module-inspect.html" rel="nofollow noreferrer">inspect</a> module makes this a lot easier and cleaner. </p>
| 6,288 |
<p>I've just performed a new installation of the very latest (Fall, 2008) version of Fedora 9 Linux and am perplexed that it never set the default route properly and that even traveling the labyrinthine ways of this OS, there's no obvious way.</p>
<p>Of course, it's clear that one can do it on a one-off basis like thi... | <p>The gateway is normally set in /etc/sysconfig/network-scripts/ifcfg-eth0, not in /etc/sysconfig/network. For example, on my current machine:</p>
<blockquote>
<p>/etc/sysconfig/network</p>
</blockquote>
<pre><code>NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=flyboys
NISDOMAIN=ekcineon
</code></pre>
<blockquote>
... | <p>Haven't seen Fedora. But shouldn't there be some GUI for this kind of thing? If you have Gnome try running <code>gnome-network-preferences</code></p>
| 24,233 |
<p>Does anyone have a decent algorithm for calculating axis minima and maxima? </p>
<p>When creating a chart for a given set of data items, I'd like to be able to give the algorithm: </p>
<ul>
<li>the maximum (y) value in the set </li>
<li>the minimum (y) value in the set </li>
<li>the number of tick marks to appear ... | <p>OK, here's what I came up with for one of our applications. Note that it doesn't deal with the "optional value" scenario you mention, since our optional value is always 0, but it shouldn't be hard for you to modify.</p>
<p>Data is continually added to the series so we just keep the range of y values up to date by i... | <p>I can recommend the following:</p>
<ul>
<li>Set a visually appealing minimum number of major lines. This will depend on the nature of the data that you're presenting and the size of the plot you're doing, but 7 is a pretty good number</li>
<li>Choose the exponent and the multiplier based on a progression of 1, 2, 5... | 7,487 |
<p>I see Oracle procedures sometimes written with "AS", and sometimes with "IS" keyword. </p>
<pre><code>CREATE OR REPLACE Procedure TESTUSER.KILLINSTANCE (INSTANCEID integer) **AS**
...
</code></pre>
<p>vs.</p>
<pre><code>CREATE OR REPLACE Procedure TESTUSER.KILLINSTANCE (INSTANCEID integer) **IS**
...
</code></pre... | <p>None whatsover. They are synonyms supplied to make your code more readable:</p>
<p>FUNCTION f IS ...</p>
<p>CREATE VIEW v AS SELECT ...</p>
| <p>According to <a href="https://www.tutorialspoint.com/plsql/plsql_procedures.htm" rel="nofollow noreferrer">TutorialsPoint</a></p>
<blockquote>
<p>The AS keyword is used instead of the IS keyword for creating a
standalone procedure.</p>
</blockquote>
<p>and considering previous answers,</p>
<p>I guess</p>
<p>... | 28,517 |
<p>To use <a href="http://en.wikipedia.org/wiki/Modular_exponentiation" rel="noreferrer">modular exponentiation</a> as you would require when using the <a href="http://en.wikipedia.org/wiki/Fermat_primality_test" rel="noreferrer">Fermat Primality Test</a> with large numbers (100,000+), it calls for some very large calc... | <p>For some reason, there are two standard libraries in PHP handling the arbitrary length/precision numbers: <a href="http://www.php.net/manual/en/book.bc.php" rel="noreferrer">BC Math</a> and <a href="http://www.php.net/manual/en/book.gmp.php" rel="noreferrer">GMP</a>. I personally prefer GMP, as it's fresher and has ... | <p>I suggest you try <a href="http://pear.php.net/package/Math_BigInteger" rel="nofollow noreferrer">BigInteger</a>. If that doesn't work out, you may use <a href="http://www.swig.org/" rel="nofollow noreferrer">SWIG</a> to add C/C++ code for the big integer calculations and link it into your code.</p>
| 25,965 |
<p>For example, in Java there is <a href="http://functionaljava.org/" rel="noreferrer">Functional Java</a> and <a href="http://www.cs.chalmers.se/~bringert/hoj/" rel="noreferrer">Higher-Order Java</a>. Both essentially give a small API for manipulating higher-order, curried functions, and perhaps a few new data types ... | <p>have you looked into <a href="https://www.microsoft.com/en-us/research/project/f-at-microsoft-research/?from=http://research.microsoft.com/fsharp/fsharp.aspx" rel="nofollow noreferrer">F#</a>?</p>
<p>Also a neat blog post would be <a href="https://web.archive.org/web/20210121191830/http://geekswithblogs.net/akraus1/... | <p>F#, there's a CTP release available from microsoft.</p>
| 10,940 |
<p>How can I set up my crontab to execute X script at 11:59PM every day without emailing me or creating any logs?</p>
<p>Right now my crontab looks something like this</p>
<pre><code>@daily /path/to/script.sh
</code></pre>
| <p>When you do crontab -e, try this:</p>
<pre><code>59 23 * * * /usr/sbin/myscript > /dev/null
</code></pre>
<p>That means: At 59 Minutes and 23 Hours on every day (*) on every month on every weekday, execute myscript.</p>
<p>See <strong>man crontab</strong> for some more info and examples.</p>
| <p>You will with the above response receive email with any text written to stderr. Some people redirect that away too, and make sure that the script writes a log instead.</p>
<pre><code>... 2>&1 ....
</code></pre>
| 2,528 |
<p>Is there anyway to combine all resources into a single exe file such as app.config and associated DLL's?</p>
<p>Some applications seem to do this such as eMule.</p>
<p>I don't want my app.config sitting there waiting to be edited.</p>
<p>Thanks</p>
| <p>Certainly, in the <code>Solution Explorer</code> (assuming Visual Studio here, since you don't mention) <code>Right-click</code> and <code>Properties</code> of the file(s) you want included. </p>
<p>There should be an option there for <code>Build Action</code> which you can set to <code>Embedded Resource</code>.</... | <p>I have used Thinstall as an application virtualization shrinkwrapper before:</p>
<p><a href="https://thinstall.com/help/index.php?_netsupport.htm" rel="nofollow noreferrer">https://thinstall.com/help/index.php?_netsupport.htm</a></p>
<p>This does what you want, i.e. bundles all your app's dependencies into one exe... | 18,240 |
<h2>Overview</h2>
<p>One of the things I've asked a lot about on this site is <a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx" rel="noreferrer">LINQ</a>. The questions I've asked have been wide and varied and often don't have much context behind them. So in an attempt to consolidate the knowledge I'... | <p>LINQ to entities:</p>
<ul>
<li><a href="http://blogs.msdn.com/adonet/archive/2008/05/20/how-do-i-new-entity-framework-videos.aspx" rel="noreferrer">Video walkthroughs</a></li>
<li><a href="http://channel9.msdn.com/shows/Going+Deep/ADONET-Entity-Framework-What-How-Why/" rel="noreferrer">Channel 9 video</a></li>
<li>... | <p><strong>For Linq Practice</strong></p>
<p>If you want some practice on LINQ with exercises and answers, really easy to set up and, in my opinion, awesome:</p>
<p><a href="https://github.com/walkhard/linq-exercises" rel="nofollow noreferrer">https://github.com/walkhard/linq-exercises</a></p>
<p>Download from git, ... | 3,703 |
<p>Joe Duffy states in the MSDN article "<a href="http://msdn.microsoft.com/en-us/magazine/cc163552.aspx" rel="noreferrer">Using concurrency for scalability</a>" that the cost of creating a thread is approximately 200,000 cycles, and the cost of destroying is about 100,000 cycles.</p>
<p>When I try to create a new thr... | <p>You could use a sampling profiler like Intel's Vtune to obtain a measure of how many CPU cycles are being consumed with a minimum amount of disturbance on the system being measured.</p>
<p>When using threads however the goal is to avoid needless spawning new threads. Look into using the <a href="http://msdn.microso... | <p>I asked a closely related question a couple of days ago, and have yet not found a way to measure the actual CPU cycle usage of the code:
<a href="https://stackoverflow.com/questions/234411/limiting-assembly-execution-number-of-cpu-cycles">Limiting assembly execution number of cpu cycles</a></p>
<p>In your case, cou... | 29,525 |
<p>Is it possible to programmatically either via the win32API (python) or via a command line option set the processor affinity for a process?</p>
| <p>Given a process handle, you can call the <a href="http://msdn.microsoft.com/en-us/library/ms686223(VS.85).aspx" rel="nofollow noreferrer">SetProcessAffinityMask</a> Win32 API function to set the processor affinity for another process. Note that all the usual security restrictions are in effect, that is, you will pro... | <p>In C/C++ you can use <a href="http://msdn.microsoft.com/en-us/library/ms686253(VS.85).aspx" rel="nofollow noreferrer">SetThreadIdealProcessor()</a>. I have no idea if this is accessible in python.</p>
<pre><code>DWORD processorId = 0;
SetThreadIdealProcessor(GetCurrentThread(),processorId);
</code></pre>
| 37,228 |
<p>I'm in a small business of hosting my clients' websites, and a lot of times they ask me to create one from scratch. I'm no designer, but I can code CSS/HTML, AJAX, PHP. However, I'm <em>not</em> willing to create sites from scratch, knowing how much is involved.</p>
<p>In the past, I've tried using design templates... | <p>If it has to be dead easy, then look at something like Joomla. If you want a bit more control, try Drupal. I think that both will suit you better than WordPress if my hunch is right.</p>
| <p>I think you are basically looking for a CMS. Now the problem is that there a so many CMS'es out there that it can be overwhelming to pick one. Another thing I've noticed over the years is that with the vast amount of CMS systems to pick from there is a lot of personal taste involved. To pick the one that suits you b... | 20,800 |
<p>I am trying to process an uploaded file in a Perl program, using CGI::Application. I need to get the content type of the uploaded file. From what I read, the following should work, but it doesn't for me:</p>
<pre><code>my $filename = $q->param("file");
my $contenttype = $q->uploadInfo($filename)->{'Conte... | <p>You trust whatever did the upload to give you a good content type? I just save the uploaded file to disk and do:</p>
<pre><code>chomp(my $mime_type = qx!file -i $uploaded!);
$mime_type =~ s/^.*?: //;
$mime_type =~ s/;.*//;
</code></pre>
<p>though you could use File::Type, File::MMagic, or File::MimeInfo instead.<... | <p>Are you checking for anything that might have gone wrong?</p>
<p>I got that exact code to work just fine, but looking at it, it's wrapped in a test for <code>$filename</code> being undef and also for anything in <code>$cgi->cgi_error()</code>. My memories are a bit dim but there must have been a reason for that.... | 48,359 |
<p>I need to find out the time a function takes for computing the performance of the application / function.
is their any open source Java APIs for doing the same ?</p>
| <p>You're in luck as there are quite a few <a href="http://java-source.net/open-source/profilers" rel="nofollow noreferrer">open source Java profilers</a> available for you.</p>
| <p>Hiperic provide a GPLv2 licenced tool for monitoring all sort of system resources called SIGAR (System Information Gatherer and Reporter).</p>
<p>This tool is used to provide things like adaptive load balancing in GridGain (a grid computing framework).</p>
<p><a href="http://www.hyperic.com/products/sigar.html" re... | 21,958 |
<p>I sometimes have difficulties with other people who wish to solve a problem when they wish to skip the official interfaces and access underlying implementation details directly.</p>
<p>They argue that doing so will allow them to solve the problem more quickly. I argue that doing so will cause our architecture to b... | <p>Convince them that taking shortcuts is a false economy.</p>
<p>Explain that the initial <em>coding</em> effort is less than 30% of the initial development effort, and less than 10% (in my experience) of the overall project effort (including maintenance).</p>
<p>If they remain unconvinced, and you have the authorit... | <p><a href="http://catb.org/jargon/html/L/LART.html" rel="nofollow noreferrer">http://catb.org/jargon/html/L/LART.html</a>
SCNR, etc. pp ;)</p>
| 25,825 |
<p>As mentioned in many of my previous questions, I'm working through K&R, and am currently into the preprocessor. One of the more interesting things — something I never knew before from any of my prior attempts to learn C — is the <code>##</code> preprocessor operator. According to K&R:</p>
<block... | <p><strong>CrashRpt: Using ## to convert macro multi-byte strings to Unicode</strong></p>
<p>An interesting usage in CrashRpt (crash reporting library) is the following:</p>
<pre><code>#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)
//Note you need a WIDEN2 so that __DATE__ will evaluate first.
</code></pre>
<p>... | <p>It is very useful for logging. You can do:</p>
<pre><code>#define LOG(msg) log_msg(__function__, ## msg)
</code></pre>
<p>Or, if your compiler doesn't support <strong>function</strong> and <strong>func</strong>:</p>
<pre><code>#define LOG(msg) log_msg(__file__, __line__, ## msg)
</code></pre>
<p>The above "funct... | 26,664 |
<p>On my side job as programmer, I am to write a program in C++ to convert audio files from/to various formats. Probably, this will involve building a simple GUI.</p>
<p>Will it be a great effort to build seperate GUIs for Mac and Windows using Cocoa and WinForms instead of a cross-platform toolkit like Qt or GTK? <br... | <p>If you have the expertise, use native frontends, it'll effectively double the job you have to do for UI but from my experience non-native UI is a little bit clunkier than their native counterparts.</p>
| <p>wxWidgets used standard c++ syntax and preprocessor thus make you easily alter from plain C or C++. And will produce very native look where is appear, be it on GTK, X11, MS-Windows or Mac.</p>
<p>It's mature since 20yrs of 1rst release, has complete documentation with easy navigating, and supported by large communi... | 5,454 |
<p>I've built a custom machine based on the AM8 (Anet A8 upgrade). I've got an E3D V6 clone hotend in, seems like a decent clone. I've replaced the heat break, heat block, and nozzle several times but after a given period it seems like filament leaks up the heat break. The heat break and nozzle are "all-metal"... | <ol>
<li>Verification: When you tighten the nozzle against the heat break, the nozzle is not tightened completely against the heater block. If the nozzle tightens completely against the heater block, it will not finish tightening against the heat break.</li>
</ol>
<p>Note: the heat break is thin between the heater blo... | <ol>
<li>Verification: When you tighten the nozzle against the heat break, the nozzle is not tightened completely against the heater block. If the nozzle tightens completely against the heater block, it will not finish tightening against the heat break.</li>
</ol>
<p>Note: the heat break is thin between the heater blo... | 1,966 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.