instruction stringlengths 0 30k ⌀ |
|---|
The following **C++** code uses a **ifstream** object to read integers from a text file (which has one number per line) until it hits **EOF**. Why does it read the integer on the last line twice? How to fix this?
**Code:**
#include <iostream>
#include <fstream>
using namespace std;
int ma... |
Customizing Visual Studio |
|c#|asp.net|visual-studio|winforms| |
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#) for several months now. For the most part my IDE is set up fairly standard but I have been wondering what are some suggestions in terms of plugins/settings that you find to be the most useful? |
|c#|asp.net|visual-studio|winforms|plugin-development| |
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#) for several months now. For the most part my IDE is set up fairly standard but I have been wondering what are some suggestions in terms of plugins/settings that you find to be the most useful?
**Update**: Thanks for all the gr... |
Thanks for the answer, samjudson.
After further experimentation, I found that you can even use just `$(':checkbox')` to select them. It's interesting that you can use the `.slice()` function to get the range, but you also have the option of doing it in the selector with `:gt` and `:lt`. I do find the syntax of `.sli... |
> Tag = a defined slice in time, usually used for releases
I think this is what one typically means by "tag". But in Subversion:
> They don't really have any formal meaning. A folder is a folder to SVN.
which I find rather confusing: a revision control system that knows nothing about branches or tags. From an ... |
@DAC
> In short: SID = the unique name of
> your DB, ServiceName = the alias used
> when connecting
Not strictly true.. SID = unique name of the INSTANCE (eg the oracle process running on the machine). Oracle considers the "Database" to the be files.
Service Name = alias to an INSTANCE (or many instances). T... |
As with all development, screen size is paramount so I would suggest the 24" iMac if your golden ticket stretches that far or a mac mini with a large (probably non-Apple) monitor if it doesn't. |
Restrict selection of SELECT option without disabling the field |
|html|select| |
I have a multiple selection SELECT field which I don't want the end user to be able to change the value of.
For UI reasons, I would like to be able to do this without using the disabled="true" attribute. I've tried using onmousedown, onfocus, onclick and setting each to blur or return false but with no success.
... |
I've come up with a fairly naive recursive algorithm (pseudocode):
Map<Object, List<Object>> source; // map of each object to its dependency list
List<Object> dest; // destination list
function resolve(a):
if (dest.contains(a)) return;
foreach (b in source[a]):
reso... |
AdBlock forum [says][1] this is used to detect AdBlock. After some tweaking you could use this to gather some statistics.
<script language="JavaScript" type="text/JavaScript">
setTimeout('detect_abp()', 10000);
var isFF = (navigator.userAgent.indexOf("Firefox") > -1) ? true : false;
var h... |
Not Java per-se, but you may run into issues where you have written something to a file, but it hasn't been actually written yet - it might be in a cache somewhere, and reading from the same file may not actually give you the new information.
Short version - use flush() or whatever the relevant system call is to ens... |
Dare Obasanjo has a [pretty good blog][1] post about this topic. You really need to assess what it is you're caching, why you're caching it and what your needs are before you can make a decision on a caching strategy.
[1]: http://www.25hoursaday.com/weblog/2007/07/05/ASPNETCachingVsMemcachedSeekingEfficientDataP... |
> It is the only framework that I've
> ever used where component creation is
> a deep intricate process like this.
> None of the other web frameworks
> (whether in the .net world or not)
> make this so painful, which is
> completely inexplicable to me.
Some of the design decisions behind JSF start to make a li... |
In short, what you are doing is right, you want to move the common code into a class library (DLL) and then reference that in any projects that require its logic.
Where you are going wrong is that you are not _maintaining_ it. If you need to make little "tweaks" _[subclass](http://en.wikipedia.org/wiki/Subclass_(com... |
I like to write all of my generic classes as just that: generics. I keep them as application independent as possible, and try to keep them even type unaware. If I make a fancy Tree class, I'll use generics to create it as Tree<T> so that I can use any type I want with the class. If I need to use the Tree to hold ... |
You can use something like this in VBA:
Sub ListIndirectRef()
Dim rRng As Range
Dim oSh As Worksheet
Dim oCell As Range
For Each oSh In ThisWorkbook.Worksheets
Set rRng = oSh.UsedRange
For Each oCell In rRng
If InStr(oCell.Formula, "INDIRECT") Then
Debug.Print oCell... |
I don't use Visual Studio or .NET, but it think this problem is common enough amongst ALL programmers so I guess I'll take a crack at it.
We've run into problems just like this when we try to extract common code into a separate library. It might be OK at first, but eventually 1 client is going to need some new func... |
In addition to the process management code in the os module that Greg pointed out, you should also take a look at the threading module: <http://docs.python.org/lib/module-threading.html>
from threading import Thread
def separate_computations(x, y):
print sum(x for i in range(y)) # really exp... |
This kind of thing is much easier if you use STL containers, or maybe [Boost.MultiArray](http://www.boost.org/libs/multi_array/doc/index.html). But if you must use an array, this might give you a hint:
#include <iostream>
int sum(int x) {
return x;
}
template <class T, unsigned N>
... |
This kind of thing is much easier if you use STL containers, or maybe [Boost.MultiArray](http://www.boost.org/libs/multi_array/doc/index.html). But if you must use an array:
#include <iostream>
#include <boost/foreach.hpp>
#include <vector>
int sum(int x) {
return x;
}
templ... |
Here's when I use it:
* Accessing Private Methods from within the class (to differentiate)
* Passing the current object to another method (or as a sender object, in case of an event)
* When creating extension methods :D
I don't use this for Private fields because I prefix private field variable names with an un... |
I've done this a fair few times and the solutions out there really depend on the environment (enterprise / mission critical or development). The BEST way would be the ***Oracle AS/400 Gateway***. Here are some important links in that area:
Allow AS/400 apps to access oracle with the Oracle Access Manager:
[Ins... |
How to unit test an object with database queries |
|database|unit-testing| |
I've heard that unit testing is "totally awesome", "really cool" and "all manner of good things" but 70% or more of my files involve database access (some read and some write) and I'm not sure how to write a unit test for these files.
I'm using PHP and Python but I think it's a question that applies to most/all lang... |
@ allain <blockquote>Can you lower your own process' priority without being superuser?</blockquote>
Sure. Be aware, however, that this is a one way street. You can't even get back to where you started. And even fairly small reductions in priority can have startlingly large effects on running time when there is signi... |
Modern `mysqldump` commands have a couple options to help with setting up consistent replication. Check out `--master-data` which will put the binary log file and position in the dump and automatically set when loaded into slave. Also `--single-transaction` will do the dump inside a transaction so that no write lock is... |
Ideally, your objects should be persistent ignorant. For instance, you should have a "data access layer", that you would make requests to, that would return objects. This way, you can leave that part out of your unit tests, or test them in isolation.
If your objects are tightly coupled to your data layer, it is diff... |
You should mock the database access if you want to unit test your classes. After all, you don't want to test the database in a unit test. That would be an integration test.
Abstract the calls away and then insert a mock that just returns the expected data. If your classes don't do more than executing queries, it ma... |
Yes, design patterns are largely used in the real world - and daily by many of the people I work with.
In my opinion the biggest value provided by design patterns is that they provide a universal, high level language for you to convey software design to other programmers.
For instance instead of describing your... |
Well I'm still new to rails and I'm not sure exactly what you're going for here, but if you're just going for code reuse why not use a regular class method?
<pre><code>
def self.ab(a, b)
a(a).b(b)
end
</pre></code>
You could make that more flexible by taking *args instead of a a... |
There are three key components (assuming ur using SQL server):
SQLConnection, SqlCommand, SqlDataReader
(if you're using something else, replace "Sql" with "Something", like "MySqlConnection", "OracleCommand"
Everything else is just built on top of that
Example 1:
using (SqlConnection connection = new ... |
I've never tried it, but you should write a test case to see if reading from a stream after you have hit the end will work, regardless of if there is more data written to the file.
Is there a reason you can't use a piped input/output stream? Is the data being written and read from the same application (if so, you h... |
Check out SQLite, it seems like a good option for this particular scenario. |
I would not use config files for storing user data. Use a db. |
[LittleCms][1] is about as barebones as you can get.
@modesty, I would definitely NOT use SharePoint, as it is anything but barebones.
[1]: http://www.littlecms.com/ |
[tinyCMS][1] is about as barebones as you can get. (**edit**: fixed link, I had gotten a little click happy and linked to the wrong thing)
@modesty, I would definitely NOT use SharePoint, as it is anything **but** barebones. It is a fairly expensive product (especially when compared to the many free alternatives), ... |
Seconding memcached, does the simple stuff well and can go distributive and all that jazz if you need it too |
C#: Accessing a Dictionary.Keys Key through a numeric index |
|c#|.net| |
I'm using a Dictionary<string, int> where the int is a count of the key.
Now, I need to access the last-inserted Key inside the Dictionary, but i do not know the name of it. The obvious attempt:
int LastCount = mydict[mydict.keys[mydict.keys.Count]];
does not work, because Dictionary.Keys does not im... |
Not 100% sure example what you are asking, but personally, and I use MochiKit, I create JavaScript "classes" (or widgets, if you prefer) for every significant client-side UI structure. These know, of course, how to populate themselves with data.
I don't know what more there is to say - writing UI code for the browse... |
Here's how I would do it.
I'd obtain a list of common English words with usage frequency and some grammatical information (like is it a noun or a verb?).
Then I'd run a filter on it so obscure words are removed and that words which are too long are excluded.
Then my generation algorithm would pick 2 words from... |
Here's how I would do it.
I'd obtain a list of common English words with usage frequency and some grammatical information (like is it a noun or a verb?). I think you can look around the intertubes for some copy. Firefox is open-source and it has a spellchecker... so it must be obtainable somehow.
Then I'd run a f... |
Best I can give you is a "works for me" on SVN 1.5. You may try adding `--no-auth-cache` to your `svn update` to see if that lets you override more easily.
If you want to permanently switch from user2 to user1, head into ~/.subversion/auth/ on *nix and delete the auth cache file for domain.com (most likely in ~/.su... |
The following **C++** code uses a **ifstream** object to read integers from a text file (which has one number per line) until it hits **EOF**. Why does it read the integer on the last line twice? How to fix this?
**Code:**
#include <iostream>
#include <fstream>
using namespace std;
int ma... |
Complexity of Regex substitution |
|regex|complexity-theory| |
I didn't get the answer to this anywhere. What is the runtime complexity of a Regex substitution? |
I didn't get the answer to this anywhere. What is the runtime complexity of a Regex match and substitution?
Edit: I work in python. But would like to know in general about most popular languages/tools (java, perl, sed). |
Have you looked at [as3corelib][1]? It appears to provide an AS3 parser for JSON data, and my hope would be that it doesn't rely upon eval (eval tends to be bad for security as you noted). There are similar libs for Javascript as well, and they tend to be the preferred way to parse json due to the security implicatio... |
I generally only derive my own collection classes if I need to "add value". Like, if the collection itself needed to have some "metadata" properties tagging along with it. |
If your clients are using SMS then you're in the clear... SMS supports EXE. You enter a command line when creating 'Programs' and clients are probably already calling msiexec to launch the MSI. Also I'm pretty sure SMS predates the MSI file format :)
However if they're using Active Directory / Group Policy Objects..... |
**6 of 1, half dozen of another**
Either way its the same thing. I only do it when I have reason to add custom code into the BusinessObjectCollection.
With out it having load methods return a list<T> allows me to write more code in a common generic class and have it just work. Such as a Load method.
|
I prefer just to use `List<BusinessObject>`. Typedefing it just adds unnecessary boilerplate to the code. `List<BusinessObject>` is a specific type, it's not just any `List` object, so it's still strongly typed.
More importantly, declaring something `List<BusinessObject>` makes it easier for everyone reading the c... |
The literal answer is no - there is never anything "inherently wrong" with code, it's a matter of whether it meets the requirements - which may or may not include being maintainable, secure, robust or fast.
The code you are running is actually a JET query purely within Access - the Java code is doing nothing except ... |
I usually try to break up my tests between testing the objects (and ORM, if any) and testing the db. I test the object-side of things by mocking the data access calls whereas I test the db side of things by testing the object interactions with the db which is, in my experience, usually fairly limited.
I used to get... |
I'd like to think my issue is "special" here, since I am using a custom form. I chose to use a custom form rather than a custom FormTemplate simply because I'm doing a lot of stuff that's not very SharePoint list-like (making ajax calls to get info from a third-party app then generating some dynamic form elements base... |
Is there any way that you could *include* the child nant file as opposed to executing it as a full-fledged child nant project? This would prevent the overwrite, but not sure if it's possible in your situation. |
You can find an implementation of md5crypt in the [tcllib package.][1] Download is available from [sourceforge][2].
[1]: http://tcllib.sourceforge.net/doc/md5crypt.html
[2]: http://sourceforge.net/project/showfiles.php?group_id=12883 |
You can find an implementation of md5crypt in the [tcllib package.][1] Download is available from [sourceforge][2].
You can also find an example of an apache-compatible md5crypt in the [source code for the CAS Generic Handler][3]
[1]: http://tcllib.sourceforge.net/doc/md5crypt.html
[2]: http://sourceforge.... |
id:[a* TO z*] id:[0* TO 9*] etc.
I just did this in lukeall on my index and it worked, therefore it should work in Solr which uses the standard query parser. I don't actually use Solr.
In base Lucene there's a fine reason for why you'd never query for every document, it's because to query for a document you m... |
There are a couple of open source plugins on SourceForge,
http://sourceforge.net/tracker/?group_id=103281&atid=738747
(search for image)
The plugin architecture is easy to understand if you know Javascript.
If you have the time you could roll out your own. |
MD5Crypt is basically a replacement for the old-fashioned unix crypt function. It was introduced in freebsd, and has been adopted by other groups as well.
The basic idea is this:
- a hash is a good way to store a password
- you take the user's entered password and hash it
- compare it to the stored has... |
It stops and starts the services that IIS consists of.
You can think of it as closing the relevant program and starting it up again. |
Yes, you just run xcode builds via the command line (xcodebuild) which makes it simple to target from CC via an ant <exec>. I've been using just regular CC, not the ruby version and it works fine. Here's a barebones example:
<project name="cocoathing" default="build">
<target name="build">
<exec ... |
Yes, you just run xcode builds via the command line (xcodebuild) which makes it simple to target from CC via an ant `<exec>`. I've been using just regular CC, not the ruby version and it works fine. Here's a barebones example:
<project name="cocoathing" default="build">
<target name="build">
<exe... |
C# Performance For Proxy Server (vs C++) |
|c#|c++|performance|sockets|system.net| |
I want to create a simple http proxy server that does some very basic processing on the http headers (i.e. if header x == y, do z). The server may need to support hundreds of users. I can write the server in C# (pretty easy) or c++ (much harder). However, would a C# version have as good of performance as a C++ versi... |
I've never done this in PHP and I've never used Python, but what you want to do is mock out the calls to the database. To do that you can implement some [IoC][1] whether 3rd party tool or you manage it yourself, then you can implement some mock version of the database caller which is where you will control the outcome... |
I agree with the first post - database access should be stripped away into a DAO layer that implements an interface. Then, you can test your logic against a stub implementation of the DAO layer. |
I misunderstood you. I thought you wanted Nuclear or Deals. The below should give you only Nuclear and Deals.
----------
select p.*
from wp_posts p, wp_terms t, wp_term_taxonomy tt, wp_term_relationship tr,
wp_terms t2, wp_term_taxonomy tt2, wp_term_relationship tr2
wp_terms t2, wp_term_taxonomy tt2, wp_term... |
What you really need to do is to use some sort of source control software such that:
- Any change that you do in one project will reflect across all projects without loss of referential integrity
- You may have the option to keep more than one version of the library you have and reference a specific version inste... |
If by user friendly, you mean that a user could type the answer in then I think you would want to look in a different direction. I've seen and done implementations for initial random passwords that pick random words and numbers as an easier and less error prone string.
If though you're looking for a way to encode a... |
You can use the `nm -g` tool from the binutils toolchain. However, their source is not always readily available. and I'm not actually even sure that this information can always be retrieved. Perhaps `objcopy` reveals further information.
/EDIT: The tool's name is of course `nm`. The flag `-g` is used to show only ex... |
@[Outlaw](#34752)<br/>
If you need to copy code and make application-specific changes, then that code isn't generic. it should be refactored so that the common functionality stays in the common library, and the application specific functionality should be added to a subclass in that application's codebase.
Using v... |
I have done it both ways that you mentioned. I like the second, but like you said, it is a little tedious for when you make updates to that library.
Another way that I have used, is choosing a central location to keep your libraries. Then add a registry key with a string value to point to that directory. When add... |
I think the problem is that when the Grid is drawn, it draws each row from top to bottom, and within each row the items left to right. So the row-spanned <mx:TextArea> item is drawn first extending down into the area of the 2 next rows, which get drawn after and on top.
The quickest way around I can see would... |
|html|user-interface|select| |
How to concatenate strings of a string field in a PostgreSQL 'group by' query? |
|postgresql| |
I am going to answer my own question because I just found the answer, but thought it still worth posting here.
I am looking for a way to concatenate the strings of a field within a group by query. So for example, I have a table:
ID COMPANY_ID EMPLOYEE
1 1 Anna
2 1 ... |
I am going to answer my own question because I just found the answer, but thought it still worth posting here.
I am looking for a way to concatenate the strings of a field within a group by query. So for example, I have a table:
ID COMPANY_ID EMPLOYEE
1 1 Anna
2 1 Bil... |
|sql|postgresql|concat|group-by| |
It's created when it's executed and dropped when the session ends. |
Resources for building a Visual Studio plug-in? |
|visual-studio|plugin-development| |
I'd like to build a pretty simple plug-in for Visual Studio, but I don't really know how this has to be done. Is this doable in (non-managed) C++?
I'd like to know what resources you'd recommend me...
Thanks.
|
|visual-studio|add-in|plugin-development| |
Are you asking about FLV video files or Flash "movies" as in SWF?
*Just to clarify, an FLV is the Flash Video Format (or whatever the acronym is), a regular Flash movie/application/banner would be an SWF. These are very different file formats.* |
try:
ffmpeg -t 30 -i inputfile.mp3 outputfile.mp3 |
You might want to try [Mp3Splt][1].
I've used it before in a C# service that simply wrapped the mp3splt.exe win32 process. I assume something similar could be done in your Linux/PHP scenario.
[1]: http://mp3splt.sourceforge.net/mp3splt_page/home.php |
Be careful not to rely on this mod behavior in C/C++ on all OSes and architectures. If I recall correctly, I tried to rely on C/C++ code like
float x2 = x % n;
to keep x2 in the range from 0 to n-1 but negative numbers crept in when I would compile on one OS, but things would work fine on another OS. This mad... |
I've never tried, so I don't know about doing it in C++, but this website has loads of information: http://msdn.microsoft.com/en-us/vsx/default.aspx |