instruction stringlengths 0 30k ⌀ |
|---|
Most languages have some way to make . match newlines:
* In Java: Pattern.compile("pattern", Pattern.MULTILINE);
* In Perl and Ruby: /pattern/m
In general it's not a good idea to use regexp to match XML/HTML, because XML/HTML tags can be nested, for example:
<div id="super_special">
<div>Nothi... |
Use [ccache](http://ccache.samba.org/). It will hash the inputs to a compilation, and cache the results, which will drastically increase the speed of these sorts of compiles.
If you wanted to detect the multiple includes, so that you could remove them, parsing the output of `gcc -E` might be a fruitful approach. F... |
Use [ccache](http://ccache.samba.org/). It will hash the inputs to a compilation, and cache the results, which will drastically increase the speed of these sorts of compiles.
If you wanted to detect the multiple includes, so that you could remove them, you could use makedepend as Iulian Șerbănoiu suggests:
m... |
Out of the box you can use the quite bizarre Esc-F to move to the beginning of the next word and Esc-B to move to the beginning of the current word. |
I'm not 100% sure what "reusable components" means in this context, but if you mean that you want certain common elements to appear on every page, such as banner, footer, navigation links, etc., then look no further than [SiteMesh][1]. My team has used it successfully on a couple of internationalised web applications.
... |
in the aspx page:
<asp:FileUpload ID="FileUpload1" runat="server" />
in the codebehind (c#):
string contentType = FileUpload1.PostedFile.ContentType
|
Namespaces offer the additional advantage of Koenig lookup. Using helper classes may make your code more verbose - you usually need to include the helper class name in the call.
Another benefit to namespaces is in readability later on. With classes, you need to include words like "Helper" to remind you later that th... |
The two examples below show a FULL scan and a FAST scan using an INDEX.
It's best to concentrate on your Cost and Cardinality. Looking at the examples the use of the index reduces the Cost of running the query.
It's a bit more complicated (and i don't have a 100% handle on it) but basically the Cost is the CPU co... |
As others have said, [GWT][1] is a very good option. To summarize some good points:
- **fast, very portable code** using deferred binding; only loads the code that works on the user's browser, and only loads functions that are actually called; also, they're compressed
- **reliability**; very few known issues... |
'Helper' functions in C++ |
|c++|class|namespaces| |
While refactoring some old code I have stripped out a number of public methods that should actually of been statics as they a) don't operate on any member data or call any other member functions and b) because they might prove useful elsewhere.
This led me to think about the best way to group 'helper' functions toge... |
For debugging Assembly code, there's [ALD][1].
[1]: http://ald.sourceforge.net/ |
The [Functional Java][1] library has an array wrapper class that equips arrays with handy methods like concatenation.
import static fj.data.Array.array;
...and then
Array<String> both = array(first).append(array(second));
To get the primitive array back out, call
String[] s = both.array();
... |
Though it depends on your application and etc., I would suggest keeping file repository scheme very simple for now, and decide on more elaborate strategy later. In other words, you make kind of "managed chaos" for a while; structure and strategy will come up later, when you will find out all requirements and domain spe... |
Why don't you just create an instance of `MethodLocalInner`, in `aMethod`, and call `bMethod` on the new instance?
|
In Delphi, I want to be able to create an private object that's associated with a class, and access it from all instances of that class. In Java, I'd use:
public class MyObject {
private static final MySharedObject mySharedObjectInstance = new MySharedObject();
}
Or, if MySharedObject needed mo... |
Yes, depending on the statement you are using. You are better off protecting yourself either by using Stored Procedures, or at least parameterised queries.
See <a href="http://en.wikipedia.org/wiki/SQL_injection#Preventing_SQL_Injection">WikiPedia</a> for prevention samples. |
We use a structure like this:
<ul>
<li>CompanyNameOrCoreProjectName
<ul>
<li>Branch
<ul>
<li>BranchName
<ul>
<li>CopyOfTrunk</li>
</ul>
</li>
</ul>
</li>
<li>Tr... |
As other people noted, the online book [Beginning Perl](http://www.perl.org/books/beginning-perl/) has a good reputation and is written by a very clueful expert and active Perl contributor. Other than that, I concentrated [resources for beginners in the Perl Beginners' Site](http://perl-begin.org/), and you can probabl... |
WMI does not give limited users this information.
If you can access Win32 functions from your language, you can call [GetVolumeInformation](http://msdn.microsoft.com/en-us/library/aa364993\(VS.85\).aspx). |
Can Unix shell script be used to manipulate databases? |
|java|unix|shell| |
I have to read data from some files and insert the data into different tables in a database. Is Unix shell script powerful enough to do the job?
Is it easy to do the job in shell script or should I go about doing this in Java? |
Most languages have some way to make . match newlines:
* In Java: Pattern.compile("pattern", Pattern.MULTILINE);
* In Perl and Ruby: /pattern/m
* In VB: Regex.IsMatch(s, "pattern", RegexOptions.Multiline)
In general it's not a good idea to use regexp to match XML/HTML, because XML/HTML tags can be nested, for e... |
You mentioned that you like dbDeploy and the fact that you do not want to install java on your server. Are you aware of the .NET port of this tool?
http://sourceforge.net/projects/dbdeploy-net
I used this recently with a team and we were very happy with it. In our case we were targeting SQL 2000, but it could... |
Liquid layouts can cause usability problems, though.
Content containers that become too wide become exceptionally difficult to read.
Many blogs have fixed width content containers specifically for this reason.
Alternatively, you can create multi-column content containers so that you get an effect like a newspa... |
I haven't tried it for so called *mobile device*, but I would guess its very similar to the method for a regular Cocoa application. Check out this tutorial:
[Embedded Cocoa Frameworks][1]
[1]: http://rentzsch.com/cocoa/embeddedFrameworks |
.NET (C#): Getting child windows when you only have a process handle or PID? |
|c#|.net|windows|user-interface| |
Kind of a special case problem:
- I start a process with System.Diagnostics.Process.Start(..)
- The process opens a splash screen -- this splash screen becomes the main window.
- The splash screen closes and the 'real' UI is shown. The main window (splash screen) is now invalid.
- I still have the Process object... |
This is a graph problem. Check out [BFS(breadth first search)][1] and [DFS(depth first search).][2]. You can google out those terms and find hundreds of implementations on the web.
[1]: http://en.wikipedia.org/wiki/Breadth-first_search
[2]: http://en.wikipedia.org/wiki/Depth-first_search |
any idea how if the following is possible in PHP as a single line ?:
<?php
$firstElement = functionThatReturnsAnArray()[0];
... It doesn't seem to 'take'. I need to do this as a 2-stepper:
<?php
$allElements = functionThatReturnsAnArray();
$firstElement = $allElements[0];
... just cur... |
In general, you might expect tuples to be slightly faster. However you should definitely test your specific case (if the difference might impact the performance of your program -- remember "premature optimization is the root of all evil").
Python makes this very easy: [timeit][1] is your friend.
$ python -m ... |
Best programming based games |
|assembly|ai| |
Back when I was in school, I remember tinkering with a Mac game where you programmed little robots in a sort of pseudo-assembler language which could then battle each other. They could move themselves around the arena, look for opponents in different directions, and fire some sort of weapon. Pretty basic stuff, but I r... |
|assembly|ai| |
|assembly|ai| |
Back when I was at school, I remember tinkering with a Mac game where you programmed little robots in a sort of pseudo-assembler language which could then battle each other. They could move themselves around the arena, look for opponents in different directions, and fire some sort of weapon. Pretty basic stuff, but I r... |
|assembler|ai| |
|ai| |
Unfortunately, that is not possible with PHP. You have to use two lines to do it. |
One minor catch. **IE** can only handle a **508** character URL in this format. If you save it in IE with a url longer than this, it will truncate without warning and thus fail.
If you need a really complex script, you'll need to use a "hosted" bookmarklet, where you have a short bookmark that injects a script tag ... |
The two examples below show a FULL scan and a FAST scan using an INDEX.
It's best to concentrate on your Cost and Cardinality. Looking at the examples the use of the index reduces the Cost of running the query.
It's a bit more complicated (and i don't have a 100% handle on it) but basically the Cost is a function... |
Inexperienced with help files here, and even moreso with Vista, but I can offer you a possible workaround...
Build a second application whose only job is to open a help file. You can pass the help file name as a command line argument.
You can easily check from your main application whether this help application i... |
You might want to take a look at the Builder pattern. GoF page 97.. |
Changing the default encoding for String(byte[]) |
|java|encoding| |
Is there a way to change the encoding used by the String(byte[]) constructor ?
In my own code I use String(byte[],String) to specify the encoding but I am using an external library that I cannot change.
String src = "with accents: é à";
byte[] bytes = src.getBytes("UTF-8");
System.out.println("UTF-8... |
Simply use [Valgrind](http://valgrind.org). It will point out all your memory allocation mistakes with excruciating preciseness.
|
In MbUnit, you might be able to use the RowTest attribute to specify parameters on your test.
[RowTest]
[Row(new ThisRepository())]
[Row(new ThatRepository())]
Public void GetFoo_NotNull_Test(IFooRepository repository)
{
var results = repository.GetFoo();
Assert.IsNotNull(resu... |
Grabbing every 4th file |
|bash|scripting| |
I have 16,000 jpg's from a webcan screeb grabber that I let run for a year pointing into the back year. I want to find a way to grab every 4th image so that I can then put them into another directory so I can later turn them into a movie. Is there a simple bash script or other way under linux that I can do this.
The... |
Well, I usually prefer the standard error output
$stderr.print("whatever")
Its simple and does the job. |
. . . uh about 50000000 other ways
maybe somthing like 5; drop table employees; --
resulting sql may be something like:
select * from somewhere where number = 5; drop table employees; -- and sadfsf
(-- starts a comment) |
It depends on how you put together the query, but in essence yes.
For example, in Java if you were to do this (deliberately egregious example):
String query = "SELECT name_ from Customer WHERE ID = " + request.getParameter("id");
then there's a good chance you are opening yourself up to an injection attac... |
Yes, absolutely: depending on your SQL dialect and such, there are many ways to achieve injection that do not use the apostrophe.
The only reliable defense against SQL injection attacks is using the parameterized SQL statement support offered by your database interface. |
Yes, there is. An excerpt from [Wikipedia][1]
`"SELECT * FROM data WHERE id = " + a_variable + ";"`
It is clear from this statement that the author intended a\_variable to be a number correlating to the "id" field. However, if it is in fact a string then the end user may manipulate the statement as they choose, ... |
Which Desktop Virtualization software runs most smoothly? |
|system-administration|vdi|remote-desktop| |
***Background:***
I'm running a full-time job and a part-time job in the weekends, and both my employers have supplied a laptop for me to work on. Of course I also have my powerful workstation at home to work from, and sometimes when I'm at the office at my weekend job (it's in another city) I'm working from yet anot... |
I tried Graffiti and DotNetNuke and thought both were troublesome, then I tried [Umbraco][1] based on a recommendation from a friend and I love it! So much that I recommended it to Kooshmoose... I should also note that dasBlog is not a CMS, it's just blog software (which I use on my personal site and love, but it's not... |
System.Media.**SoundPlayer** is a good, simple way of playing WAV files. WAV files have some advantages over MIDI, one of them being that you can control precisely what each instrument sounds like (rather than relying on the computer's built-in synthesizer). |
CUDA global (as in C) dynamic arrays allocated to device memory |
|cuda|nvidia| |
So, im trying to write some code that utilizes Nvidia's CUDA architecture. I noticed that copying to and from the device was really hurting my overall performance, so now I am trying to move a large amount of data onto the device.
As this data is used in numerous functions, I would like it to be global. Yes, I can p... |
I'm going through this exact process right now so while I don't have actual experience, I've spent many hours researching all the options. Here's what I've learned so far:
- *Sphinx - good reputation for speed and functionality but Sphinx needs integer keys and my model uses GUID; ThinkingSphinx recently announce... |
Include *one* of these lines at the top of your source file:
local $SIG{__WARN__} = \&Carp::confess;
local $SIG{__WARN__} = \&Carp::cluck;
The `confess` line will give a stack trace, and the `cluck` line is much more terse. |
Include this:
use Carp ();
Then include *one* of these lines at the top of your source file:
local $SIG{__WARN__} = \&Carp::confess;
local $SIG{__WARN__} = \&Carp::cluck;
The `confess` line will give a stack trace, and the `cluck` line is much more terse. |
I've always thought scanf() was dangerous as it can leave your input streams in an indeterminate state.
I prefer to use other (safer) commands to bring in a string (fgets and such) then use sscanf to process it. Then you can always back up to the start of the string and restart.
|
If you are creating an invoicing system, you have to think about the bank holidays, Easter, etc. It is not simple to compute it.
The best solution I have ever seen is to pregenerate a table with days and its type to SQL database (row per day = 365 rows per year) and then perform simple count query with proper selec... |
It's a bit strange because
DataLoadOptions o = new DataLoadOptions ( );
o.LoadWith<Listing> ( l => l.ListingStaffs );
o.LoadWith<ListingStaff> ( ls => ls.MerchantStaff );
ctx.LoadOptions = o;
IQueryable<Listing> listings = (from a in ctx.Listings
where a.IsActive == false
... |
There is no good solution. You can obfuscate the passwords a bit, but you can't secure them.
If you have control over your DB setup, you could try to connect by a named pipe (at least mysql supports that) without a password and let the OS handle the permissions.
You could also store the credentials in a file with... |
Are tags useful for navigation (on Stack Overflow or otherwise)? |
|user-interface|tags|usability|navigation| |
I've done some research on [using tags from social bookmarking sites for web search][1], but I'd like to learn more about other ways in which users might use tags for information retrieval.
Do you use the tags on sites like Stack Overflow for navigation? Do you think of them like filters (narrowing down a large l... |
Everyone mentions futures for the purpose of lazy calculation. However another use that isn't as advertised is the use of Futures for IO in general. Especially they're useful for loading files and waiting on network data |
The main advantage to using a namespace is that you can reopen it and add more stuff later, you can't do that with a class. This makes this approach better for loosely coupled helpers (for example you could have a Helpers namespace for your entire library, much like all of STL is in ::std)
The main advantage of a c... |
|logging|monitoring|distributed|log4j| |
In glorious [APL][1]:
×/⍳X
1. ⍳X expands X into an array of the integers 1..X
2. ×/ multiplies every element in the array
Or with the built-in operator:
!X
Source: [http://www.webber-labs.com/mpl/lectures/ppt-slides/01.ppt][2]
[1]: http://en.wikipedia.org/wiki/APL_(programming_language)... |
# [APL][1] (oddball/one-liner):
×/⍳X
1. ⍳X expands X into an array of the integers 1..X
2. ×/ multiplies every element in the array
Or with the built-in operator:
!X
Source: [http://www.webber-labs.com/mpl/lectures/ppt-slides/01.ppt][2]
[1]: http://en.wikipedia.org/wiki/APL_(programming_l... |
It sounds like the [decorator pattern][1] may be suitable, but hard to tell without more details.
[1]: http://en.wikipedia.org/wiki/Decorator_pattern |
The Symfony framework has a [mixin plugin for this][1], you might want to check it out -- even just for ideas, if not to use it.
The "design pattern" answer is to abstract the shared functionality into a separate component, and compose at runtime. Think about a way to abstract out the Invitation functionality out as... |
Are you calling the doPost and doGet methods manually in the unit tests? If so you can override the HttpServletRequest methods to provide mock objects.
myServlet.doGet(new HttpServletRequestWrapper() {
public HttpSession getSession() {
return mockSession;
}
...
... |
There are a two choices. Managed C++ (/clr:oldSyntax, no longer maintained) or C++/CLI (definitely maintained). You'll want to use /clr:safe for in-browser software, because you wnat the browser to be able to verify it. |
How can I detect the encoding/codepage of a text file |
|globalization|text|c#|.net| |
In our application, we receive text files (.txt, .csv, etc.) from diverse sources. When reading these files sometimes contain garbage, because the codepage these files where created in a different/unknown codepage.
Is there a way to (automatically) detect the codepage of a text file?
(I use .Net / C#). |
If you cannot change the sort-order on the database(best option), then the indexes on unknown case fields will not help. There is a way to do this and keep performance if the number of fields is manageable. You make an extra column MyFieldLower. You use a trigger to keep the field filled with a lower case of MyField... |
sizeof(bitfield_type) legal in ANSI C? |
|c| |
struct foo { unsigned x:1; } f;
printf("%d\n", (int)sizeof(f.x = 1));
What is the expected output and why? Taking the size of a bitfield lvalue directly isn't allowed. But by using the assignment operator, it seems we can still take the size of a bitfield type.
What is the "size of a bitfield in bytes"? Is it ... |
struct foo { unsigned x:1; } f;
printf("%d\n", (int)sizeof(f.x = 1));
What is the expected output and why? Taking the size of a bitfield lvalue directly isn't allowed. But by using the assignment operator, it seems we can still take the size of a bitfield type.
What is the "size of a bitfield in bytes"?... |
The version of Visio that comes with VS Enterprise Architect has a forward-engineer feature that will generate SQL. There is also a type library for the modelling engine, but (on older versions at least) it won't extract certain items such as comments. However, the generated SQL has the comments in a fairly simple st... |
Not my design but I've used it a few times, a typed-switch statement: http://community.bartdesmet.net/blogs/bart/archive/2008/03/30/a-functional-c-type-switch.aspx
Saved me so many if... else if... else if... else IF! statements |
How to find out the distinguished name of the information store to feed to IExchangeManageStore::GetMailboxTable? |
|exchange-server|mapi|outlook|c++| |
There is a [Microsoft knowledge base article][1] with sample code to open all mailboxes in a given information store. It works so far (requires a bit of [copy & pasting][2] on compilers newer than VC++ 6.0).
At one point it calls IExchangeManageStore::GetMailboxTable with the distinguished name of the information st... |