instruction
stringlengths
0
30k
The most common are probably database injection attacks and cross-site scripting attacks; mainly because those are the easiest to accomplish (that's likely because those are the ones programmers are laziest about).
When should I use type abstraction in embedded systems
|c|implementation|decisioms|
I've worked on a number of different embedded systems. They have all used typedefs (or #defines) for types such as UINT32. This is a good technique as it drives home the size of the type to the programmer and makes you more conscious of chances for overflow etc. etc. But on some systems you know that the compile...
|c|decisions|implementation|
|c|implementation|decisions|embedded-programming|
I've worked on a number of different embedded systems. They have all used typedefs (or #defines) for types such as UINT32. This is a good technique as it drives home the size of the type to the programmer and makes you more conscious of chances for overflow etc. But on some systems you know that the compiler and...
bool UserCredentialsOK(User user) { if (user.Name == "modesty") return false; else // perform other checks } ;)
Just to confuse things a bit more, sometimes you have to work with handles instead of pointers. Handles are pointers to pointers, so that the back end can move things in memory to defragment the heap. If the pointer changes in mid-routine, the results are unpredictable, so you first have to lock the handle to make sure...
You can see even on this site that the most damaging things you'll be looking after involve code injection into your application, so XSS (Cross Site Scripting) and SQL injection (@Patrick's suggestions) are your biggest concerns. Basically you're going to want to make sure that if your application allows for a user to...
|hacks|file-format|jpeg|steganography|
So, to simplify my life I want to be able to append from 1 to 7 additional characters on the end of some jpg images my program is processing*. These are dummy padding (fillers, etc - probably all 0x00) just to make the file size a multiple of 8 bytes for block encryption. Having tried this out with a few programs, ...
I think the ideal solution is to find a balance between the extremes. There is no way to write a rule that will fit in all situations; it comes with experience. Declaring each intermediate variable on its own line will make reading the code more difficult, which will also contribute to the difficulty in maintenance. ...
How do I find out if a process is already running using c#?
|c#|winforms|external-process|
I have C# winforms application that needs to start an external exe from time to time, but I do not wish to start another process if one is already running, but rather switch to it. So how in C# would I so this in the example below? using System.Diagnostics; ... Process foo = new Process(); ...
This should do it for ya. [Check Processes][1] [1]: http://www.dreamincode.net/code/snippet1541.htm <pre><code>//Namespaces we need to use using System.Diagnostics; public bool IsProcessOpen(string name) { //here we're going to get a list of all running processes on //the computer foreach (Proce...
Check out the [Library of Free Data Models][1] from DatabaseAnswers.org -- might be a good starting point. I can't vouch for the quality, but there is a lot here... [1]: http://databaseanswers.org/data_models/
Open source? [DB-UML might work for you][1]. EDIT: Oh! The [MySQL Workbench][2] is good. [1]: https://sourceforge.net/projects/dbuml#item3rd-1 [2]: http://dev.mysql.com/workbench/
[The mondial database.][1] Is used for learning about DBMSs. If you need something quick and dirty to bang around. [1]: http://www.dbis.informatik.uni-goettingen.de/Mondial/
There are a couple of ways to handle this, though neither is really all that great. First, add a column to your table that says that `TextField` is really a number. If you could do that and filter, you would have the most performant version. If that's not an option, then you will need to add a further filter. Whi...
In general you use the CLR if you have something that doesn't need to interface with the database much. So let's say you are parsing, or decoding a value. This is easier to do in the CLR and then return the value. Trying to do a compelx query in the CLR is just not the way to go. BTW this didn't change in 2008 e...
FDT is a plugin for Eclipse which many say (including myself) is the best editor when it comes to writing actionscript. FDT supports as2 & as3, including the new apis from Flash player 10. I haven't used Visual Studio myself but i'm guessing it's pretty much the same regarding intellisense (all versions of FDT). FDT En...
This is bizarre. LocalSystem definitely has the privileges to install applications (that's how Windows Update and software deployment in Active Directory work), so it should be able to uninstall as well. Perhaps the application is initially installed per-user instead of per-machine?
The best option is to disable keyboard navigation shortcuts in the shadowbox by setting the "enableKeys" option to false (see [this page][1]). Alternatively you could do what Robby suggests and modify the shadowbox.js file, **but only do this if you need to have the shadowbox keyboard navigation**. I think that you ...
How do you set focus to the HTML5 canvas element?
|javascript|focus|canvas|
I'm using the HTML5 `<canvas>` element in Firefox 2.0.0.16 and in Safari 3.1.2, both on my iMac. (I've tried this in Firefox 3.0 on Windows as well, also to no avail.) The tag looks like this: <td> <canvas id="display" width="500px" height="500px"> </canvas> ...
Implementing the IComparable interface in your object may provide you with the functionality you need. This will provide you a custom way to determine differences between objects without resorting to checksums which really won't help you track what the differences are in usable terms. Otherwise, there's no way to det...
Your second example does **not** create a new dataset. It's just a second _reference_ to an existing dataset.
If it's the **last** revision (HEAD) you can (**BACKING UP** your repo beforehand) delete that revision's files in `db\revs` and `db\revprops` and then run the following python script to fix what revision you repo thinks HEAD is. e.g. if head is 522 and the password was commited in 520, you'd have to deleted revisio...
You can simply enumerate processes using [Process.GetProcesses][1] method. [1]: http://msdn.microsoft.com/en-us/library/1f3ys1f9.aspx
I tend to err on the side of readability, not necessarily debuggability. The examples you gave should definitely be avoided, but I feel that judicious use of multiple expressions can make the code more concise and comprehensible.
I think the complete answer to your problem requires understanding of what happens when your application determines that an instance of foo.exe is already running i.e what does '//TODO: Switch to foo.exe process' actually mean?
I have used the AppActivate function in VB runtime to activate an existing process. You will have to import Microsoft.VisualBasic dll into the C# project. using System; using System.Diagnostics; using Microsoft.VisualBasic; namespace ConsoleApplication3 { class Program ...
@[Lars Truijens](#49540) suggested > Remember that PowerShell can access > .Net objects. The Start-Sleep as > suggested by Blair Conrad can be > replaced by a call to WaitForInputIdle > of the server process so you know when > the server is ready before starting > the client. This is more elegant than sleep...
@[Lars Truijens](#49540) suggested > Remember that PowerShell can access > .Net objects. The Start-Sleep as > suggested by Blair Conrad can be > replaced by a call to WaitForInputIdle > of the server process so you know when > the server is ready before starting > the client. This is more elegant than sleep...
Is there a way of selecting the last item of a list with CSS?
|css|css-selectors|
Say I have a list as follows: <ul> <li>item1</li> <li>item2</li> <li>item3</li> </ul> Is there a CSS selector that will allow me to directly select the last item of a list? In this case item 3. Cheers!
Can the Weblogic default handler display the list of contexts?
As alternative, log4net, though potentially dangerous, has given me better results than System.Diagnostics. Basically in log4net, you have a method for the various log levels, each with an Exception parameter. So, when you pass the second exception, it will print the stack trace to whichever appender you have config...
Open one of a series of files using a batch file
|command-line|batch-file|dos|cmd|
I have up to 4 files based on this structure (note the prefixes are dates) - 0830filename.txt - 0907filename.txt - 0914filename.txt - 0921filename.txt I want to open the the most recent one (0921filename.txt). how can i do this in a batch file? Thanks.
Typically relationships in XML are shown by the parent/child relationship. XML can handle graph data but not in this manner. To handle graphs in XML you should use the [xs:ID][1] and [xs:IDREF][2] schema types. In an example, assume that node/@id is an xs:ID type and that link/@ref is an xs:IDREF type. The following...
Out of curiousity, have you considered using an ORM for managing your data access. A lot of the functionality you're trying to implement could already be there. It may be something to look at because its best not to re-invent the wheel.
haXe and arrays Dynamic type
|haxe|array|loops|iterable|for-loop|
I know it's unlikely but maybe there is someone who knows haXe language. I have a variable of Dynamic type and I know for sure one of it's fields, lets call it an 'a' actually is an array. But when I'm writing var d : Dynamic = getDynamic(); for (t in d.a) { } I get a compilation error on line two...
|arrays|for-loop|haxe|iterable|loops|
If it's the **last** revision (HEAD) you can (**BACKING UP** your repo beforehand) delete that revision's files in `db\revs` and `db\revprops` and then run the following python script to fix what revision you repo thinks HEAD is. e.g. if head is 522 and the password was commited in 520, you'd have to deleted revisio...
If it's the **last** revision (HEAD) you can (**BACKING UP** your repo beforehand) delete that revision's files in `db\revs` and `db\revprops` and then run the following python script to fix what revision you repo thinks HEAD is. e.g. if head is 522 and the password was commited in 520, you'd have to delete revision...
CLR stored procedures are not meant to replace set-based queries. If you need to query the database, you are still going to need to put SQL into your CLR code, just as if it was embedded in regular code. This would be a waste of effort. CLR stored procedures are for two main things: 1) interaction with the OS, suc...
There are places for both well-written, well-thought-out T-SQL and CLR. If some function is not called frequently and if it required extended procedures in SQL Server 2000, CLR may be an option. Also running things like calculation right next to the data may be appealing. But solving bad programmers by throwing in new ...
Good Question! One approach I rather like is to create an iterator/generator object that emits instances of objects that are relevant to a specific context. Usually this object wraps some underlying database access stuff, but I don't need to know that when using it. For example, > An AnswerIterator object gen...
Nij, our difference in thinking comes from our different perspectives. I'm thinking about developing enterprise apps that predominantly use WinForms clients. In this instance the business logic is contained on an application server. Each client would need to know the phone number to dial, but placing it in the App.c...
|java|jakarta-ee|weblogic|
In Jetty, if there is no deployment at '/' then the [DefaultHandler](http://www.mortbay.org/jetty/jetty-6/xref/org/mortbay/jetty/handler/DefaultHandler.html) displays a list of known contexts. This is very useful during development. Is it possible to configure BEA Weblogic to provide a similar convenience?
I've never tried it, but it looks like you might be able to use a <a href="http://msdn.microsoft.com/en-us/library/ms141069(SQL.90).aspx">Derived Column transformation</a> to do it: set the expression for attribute1 to <code>"foo"</code> and the expression for attribute2 to <code>"bar"</code>. You'd then transform t...
Not that i'm aware of. The traditional solution is to tag the first & last items with class="first" & class="last" so you can identify them. The CSS psudo-class [first-child][1] will get you the first item but not all browsers support it. CSS3 will have [last-child too][2] (this is currently supported by Firefox, S...
You'll need to use ADSI objects. The <a href="http://msdn.microsoft.com/en-us/library/ms525753.aspx">IIsComputer.Backup</a> method is what you want. As far as how to access ADSI objects from C#, check out this <a href="http://support.microsoft.com/kb/315716">MSDN page</a>.
You'll need to use ADSI objects. The <a href="http://msdn.microsoft.com/en-us/library/ms525753.aspx">IIsComputer.Backup</a> method is what you want. As far as how to access ADSI objects from C#, check out this <a href="http://support.microsoft.com/kb/315716">MSDN page</a>. **EDIT:** Here's a <a href="http://www...
That's great! I didn't know you could do a comparison of (x, y, z) with the result of a SELECT statement. This works great with Oracle. As a side-note for other readers, the above query is missing a "=" after "(deptno,job,sal)". Maybe the Stack Overflow formatter ate it (?). Again, thanks Mark.
The following is slightly over-engineered, but is a good SQL pattern for "top x" queries. SELECT * FROM scott.emp WHERE (deptno,job,sal) (SELECT deptno, job, max(sal) FROM scott.emp WHERE deptno = 20 and jo...
The following is slightly over-engineered, but is a good SQL pattern for "top x" queries. SELECT * FROM scott.emp WHERE (deptno,job,sal) (SELECT deptno, job, max(sal) FROM scott.emp WHERE deptno = 20 and jo...
System::String has a constructor that takes a char*: const char* charstr = "Hello, world!"; String^ clistr = gcnew String(charstr); Console::WriteLine(clistr); Getting a char* back is a bit harder, but not too bad: IntPtr p = Marshal::StringToHGlobalAnsi(clistr); char *pNewCharStr = static_cast<ch...
While Keith is right, I suppose the example was simply badly chosen. Generally, it is better to initialize to the “right” object from the beginning and *not* construct an intermediate, empty object as in your case. Two reasons: 1. Performance. This should be obvious: Object creation costs time so creating less objec...
Well, if .net is an option, they have put a lot of effort into [Parallel Computing][1]. [1]: http://msdn.microsoft.com/en-us/concurrency/default.aspx
As Juan mentioned, xDebug is excellent. If you're on Windows, [WinCacheGrind][1] will let you look over the reports. [1]: http://sourceforge.net/projects/wincachegrind/
Custom Counter Creation Through Web Application
|.net|
I have a .NET 3.5 web application for which I have implemented a class called CalculationsCounterManager (code below). This class has some shared/static members that manage the creation and incrementing of two custom performance counters that monitor data calls to a SQL Server database. Execution of these data calls ...
I have a .NET 3.5 web application for which I have implemented a class called CalculationsCounterManager (code below). This class has some shared/static members that manage the creation and incrementing of two custom performance counters that monitor data calls to a SQL Server database. Execution of these data calls ...
I've had a few headaches with SVN when I've reorganized the folder layout from within Visual Studio. A folder moved within a solution will literally move the folder in the filesystem, including the hidden `.svn` folder. This causes commit problems because the `.svn` data is associated to the old path and I haven't fo...
Is DocumentBuilder.parse() thread safe?
|java|
Is the standard Java 1.6 [javax.xml.parsers.DocumentBuilder][1] class thread safe? Is it safe to call the parse() method from several threads in parallel? The JavaDoc doesn't mention the issue, but the [JavaDoc for the same class][2] in Java 1.4 specifically says that it *isn't* meant to be concurrent; so can I assu...
You will want to use `org.xml.sax.XMLReader` (<http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/XMLReader.html>).
This is also a short little presentation on security by one of wordpress's core developers. [Security in wordpress][1] it covers all of the basic security problems in web apps. [1]: http://markjaquith.wordpress.com/2008/08/16/secure-coding-with-wordpress-wordcamp-sf-2008-slides/
Need to test an ajax timeout condition
|asp.net|testing|ajax|
As the title mentions, I have a timeout callback handler on an ajax call, and I want to be able to test that condition but nothing is coming to mind immediately on ways I can force my application to hit that state, any suggestions?
That is true MySQL is $599 (one license is required per database server) for commercial use
I've used PHP/MySQL for a while, and I've used Rails, and I'm getting into ASP.NET right now. My incentive for switching to ASP.NET at the moment is similar to my incentive for digging into Rails--I find C# and Ruby to be much more enjoyable languages to code in. The object models are much more mature, and it feels...
SQL Injection. Cross Site Scripting.
As mentioned many times elsewhere, Just Do It. I was able to get started from scratch with Subversion under Windows in no time by reading the quick-start guide in the Red Book. Once I pointed TortoiseSVN at the repository, I was in business. It took me a while to get the finer points down, but they were minor humps to ...
> someone said that recompile is a lazy excuse! yeah lets see how lazy you feel when you have to recompile and deploy your app to 1000's of desktops, all because the DBA has told you that your ad-hoc Query is eating up too much Server time! is it good system architecture if you let connect 1000 desctops direcly to d...
> someone said that recompile is a lazy excuse! yeah lets see how lazy you feel when you have to recompile and deploy your app to 1000's of desktops, all because the DBA has told you that your ad-hoc Query is eating up too much Server time! is it good system architecture if you let connect 1000 desktops directly to ...
You could always run a server-side script that keeps running for a period of time. For example: <pre><code> &lt;?php sleep(10); //sleep for 10 seconds. print "This script has finished."; ?&gt; </code></pre>
SQL INJECTION ATTACKS. They are easy to avoid but all too common. NEVER EVER EVER EVER (did I mention "ever"?) trust user information passed to you from form elements. If your data is not vetted before being passed into other logical layers of your application, you might as well give the keys to your site to a stran...
Look into the plugin, [x_send_file][1] too. "The XSendFile plugin provides a simple interface for sending files via the X-Sendfile HTTP header. This enables your web server to serve the file directly from disk, instead of streaming it through your Rails process. This is faster and saves a lot of memory if you‘re us...
You might have more luck in cmd.exe if you opened it in UNICODE mode. Use "cmd /U". Others have proposed using a real programming language. That's fine, especially if you have a language you are very comfortable with. My friend on the C# team says that C# 3.0 (with Linq) is well-suited to whipping up quick, small...
You might have more luck in cmd.exe if you opened it in UNICODE mode. Use "cmd /U". Others have proposed using a real programming language. That's fine, especially if you have a language you are very comfortable with. My friend on the C# team says that C# 3.0 (with Linq) is well-suited to whipping up quick, small...
The answer to your question depends on how your are authoring your installer. For Visual Studio setup projects, create an installer class in one of your deployed assemblies. This is covered in the MSDN documentation, eg [http://msdn.microsoft.com/en-us/library/d9k65z2d(VS.80).aspx][1] For Wix projects, you can u...
The syntax is: ls > `pwd`.txt That is the '`' character up underneath the '~', not the regular single quote.
Eric, No one is stopping you from choosing the framework/approach that you would wish. If you are going to go the "data driven/stored procedure-powered" path, then by all means, go for it! Especially if it really, really helps you deliver your applications on-spec and on-time. The caveat being (a flipside to your...
The following is slightly over-engineered, but is a good SQL pattern for "top x" queries. SELECT * FROM scott.emp WHERE (deptno,job,sal) IN (SELECT deptno, job, max(sal) FROM scott.emp WHERE deptno = 20 and...
How do you do string comparison in javascript?
|javascript|string|basic|