instruction
stringlengths 0
30k
⌀ |
---|
I have an application that writes information to file. This information is used post-execution to determine pass/failure/correctness of the application. I'd like to be able to read the file as it is being written so that I can do these pass/failure/correctness checks in realtime. I assume it is possible to do this, but what are the gotchas involved when using Java. If the reading catches up to the writing, will it just wait for more writes up until the file is closed? or will the read throw an exception at this point and then what do I do? My intuition is currently pushing me towards BufferedStreams. Is this the way to go? |
Best way to cache data in .NET |
|.net|caching| |
I am in the process of figuring out a cache strategy for our current setup, currently have multiple web servers and wanted to know what is the best way to cache data in this environment. I have done research about MemCache and the native asp.net caching but wanted to get some feedback first. Should I go with a Linux box if I use MemCache or a win32 port of MemCache. Thanks! |
What about checking out Microsoft Velocity ([http://code.msdn.microsoft.com/velocity][1])?
Another option if you don't want to start using Microsoft CTP-ware is to check out Nache which allows distributed cache/session state management ([http://www.alachisoft.com/ncache/][2])
[1]: http://code.msdn.microsoft.com/velocity
[2]: http://www.alachisoft.com/ncache/ |
OP asked about diagramming views and view dependencies, SQL Management Studio and Enterprise Manager doesn't allow you to diagram views. I can't vouch for the other tools.
The LINQ to SQL designer for Visual Studio does allow you to drop views on the design surface but there isn't a easy way to model the dependencies between the views. I'm not sure which tool has this type of diagramming functionality. You could take a look at Red Gate's SQLDoc tool but it just provides text based output. |
Are there any alternatives to Gigaspaces? |
|java|jakarta-ee|gigaspaces| |
Anything thats as good and as stable and as feature-rich as gigaspaces? |
Yeah, the more I get into software, I start to see myself focusing less on the language and more on the design..
Yeah there are framework bits we need to get our head around but most of the time ( _most_ not all ) you can look those up as-and-when you need them..
But a good design head? That takes years of experience to start getting it working right..
And that is what the companies really pay for.. "Build it and they will come" and all that... |
Why don't you swap stacks and look at the LAMP stack?
Or how about a functional language like haskell?
Or write a DSL?
Or an app for your phone? |
In your Flex SDK folders you should see a 'runtimes\player\win\FlashPlayer.exe' which is a stand alone Flash player. Open your SWF with that and you'll see a 'Create Projector...' menu item in the File menu which will create the stand-alone EXE. |
Subversion with tortoisesvn. (tortoisesvn because you can see a lot of what goes on visually and will provide a good jumping off point for the command line stuff. ) There is tons of documentation out there and most likely you will see it at least one point in your career. Almost every company I have worked for and interviewed with runs SVN. |
@Jeff
I actually think this is an interesting question. I'm not sure how useful it is, but it is a valid question.
@Ed
Can you provide a little more info on this question? You said the dimension of the array is dynamic, but is the number of elements dynamic as well? |
@Jeff
I actually think this is an interesting question. I'm not sure how useful it is, but it is a valid question.
@Ed
Can you provide a little more info on this question? You said the dimension of the array is dynamic, but is the number of elements dynamic as well?
EDIT: I'm going to try and answer the question anyways. I can't give you the code off the top of my head (it would take a while to get it right without any compiler here on this PC), but I can point you in the right direction ...
Let's use 8 dimensions (0-7) with indexes 0 to 3 as an example. You care about only 1,2 and 6. This means you have two arrays. First, `array_care[4][4][4]` for 1,2, and 6. The `array_care[4][4][4]` will hold the end result.
Next, we want to iterate in a very specific way. We have the array `input[4][4][4][4][4][4][4][4]` to parse through, and we care about dimensions 1, 2, and 6.
We need to define some temporary indexes:
int dim[8] = {0,0,0,0,0,0,0,0};
We also need to store the order in which we want to increase the indexes:
int increase_index_order[8] = {7,5,4,3,0,6,2,1};
int i = 0;
This order is important for doing what you requested.
Define a termination flag:
bool terminate=false;
Now we can create our loop:
while (terminate)
{
array_care[dim[1]][dim[2]][dim[6]] += input[dim[0]][dim[1]][dim[2]][dim[3]][dim[4]][dim[5]][dim[6]][dim[7]];
while ((dim[increase_index_order[i]] = 3) && (i < 8))
{
dim[increase_index_order[i]]=0;
i++;
}
if (i < 8) {
dim[increase_index_order[i]]++; i=0;
} else {
terminate=true;
}
}
That should work for 8 dimensions, caring about 3 dimensions. It would take a bit more time to make it dynamic, and I don't have the time. Hope this helps. I apologize, but I haven't learned the code markups yet. :( |
**Polymorphic Tree Walking**, Python version
#!/usr/bin/python
class Node:
"""base class, you should not process one of these"""
def process(self):
raise('you should not be processing a node')
class BinaryNode(Node):
"""base class for binary nodes"""
def __init__(self, _left, _right):
self.left = _left
self.right = _right
def process(self):
raise('you should not be processing a binarynode')
class Plus(BinaryNode):
def process(self):
return self.left.process() + self.right.process()
class Minus(BinaryNode):
def process(self):
return self.left.process() - self.right.process()
class Mul(BinaryNode):
def process(self):
return self.left.process() * self.right.process()
class Div(BinaryNode):
def process(self):
return self.left.process() / self.right.process()
class Num(Node):
def __init__(self, _value):
self.value = _value
def process(self):
return self.value
def demo(n):
print n.process()
demo(Num(2)) # 2
demo(Plus(Num(2),Num(5))) # 2 + 3
demo(Plus(Mul(Num(2),Num(3)),Div(Num(10),Num(5)))) # (2 * 3) + (10 / 2)
The tests are just building up the binary trees by using constructors.
program structure:
abstract base class: Node
- all Nodes inherit from this class
abstract base class: BinaryNode
- all binary operators inherit from this class
- process method does the work of evaluting the expression and returning the result
binary operator classes: Plus,Minus,Mul,Div
- two child nodes, one each for left side and right side subexpressions
number class: Num
- holds a leaf-node numeric value, e.g. 17 or 42 |
Considering most develops want to reach the larger audience, it just means one more place to test. Since it uses Webkit, hopefully it will render almost identical to Safari.
Integrated Gears may mean a solid place for apps to be developed though. If you have an internal system it may be nicer to just put Chrome on all the machines than building an app that runs locally. |
Visual Studio comes with a [remote debugger][1] that you can run as an exe on your server. It works best if you can run it as the same domain user as your copy of visual studio. You can then do an attach to process from the debugger on your machine to the IIS process on the server and debug as if it was running on your machine. You get more options for .Net debugging, but there's support for older platforms too.
[1]: http://msdn.microsoft.com/en-us/library/bt727f1t(VS.71).aspx |
If you know a bound on the number of items then use the "IN" clause, as others have suggested:
UPDATE foo SET flag=true WHERE id in (1, 2, 3, 5, 6)
One warning though, is that depending on your db there may be a limit to the number of elements in the clause. Eg oracle 7 or 8 (?) used to have a limit of 256 items (this was increased significantly in later versions)
If you do iterate over a list use a transaction so you can rollback if one of the updates fails
|
Can't you just add an Exception at that point and inspect it? |
gvim with lots of useful plugins, i.e. taglist, c-syntax, matchit, vcscommand, bufexplorer and many more. gvim is also nice in conjunction with file manager Total Commander where F4 invokes gvim to edit the file under the cursor. |
Just follow closely the chain of events.
* Grab 10
* Grab 20
* Grab 30
* Grab EOF
Look at the second-to-last iteration. You grabbed 30, then carried on to check for EOF. You haven't reached EOF because the EOF mark hasn't been read yet ("binarically" speaking, its conceptual location is just after the 30 line). Therefore you carry on to the next iteration. x is still 30 from previous iteration. Now you read from the stream and you get EOF. x remains 30 and the ios::eofbit is raised. You output to stderr x (which is 30, just like in the previous iteration). Next you check for EOF in the loop condition, and this time you're out of the loop.
Try this:
while (true) {
int x;
iFile >> x;
if( iFile.eof() ) break;
cerr << x << endl;
}
|
Just follow closely the chain of events.
* Grab 10
* Grab 20
* Grab 30
* Grab EOF
Look at the second-to-last iteration. You grabbed 30, then carried on to check for EOF. You haven't reached EOF because the EOF mark hasn't been read yet ("binarically" speaking, its conceptual location is just after the 30 line). Therefore you carry on to the next iteration. x is still 30 from previous iteration. Now you read from the stream and you get EOF. x remains 30 and the ios::eofbit is raised. You output to stderr x (which is 30, just like in the previous iteration). Next you check for EOF in the loop condition, and this time you're out of the loop.
Try this:
while (true) {
int x;
iFile >> x;
if( iFile.eof() ) break;
cerr << x << endl;
}
By the way, there is another bug in your code. Did you ever try to run it on an empty file? The behaviour you get is for the exact same reason. |
I like this example, which for now, leaves out the check which you could add inside the while block:
ifstream iFile("input.txt"); // input.txt has integers, one per line
int x;
while (iFile >> x)
{
cerr << x << endl;
}
Not sure how safe it is... |
It depends on what your application is doing. You might want to throw individual exceptions in cases like
- The application is high availability
- Sending e-mail is particularly important
- The scope of the application is small and sending e-mail is a large part of it
- The application will be deployed to a site which is remote and you will only get logs for debugging
- You can recover from some subset of the exceptions encapsulated in the mailException but not others
In most cases I would say just log the text of the exception and don't waste your time granularizing already pretty granular exceptions. |
I'll echo the others who have endorsed Emacs. I program every day on, at a bare minimum, OS X, Windows, and Linux. Having the same IDE on all three systems gives me an enormous productivity boost. That said, the vanilla version of GNU Emacs...well, it sucks. I'd strongly encourage you to try [EmacsW32](http://ourcomments.org/Emacs/EmacsW32.html) instead. In much the way that Aquamacs makes an OS X-friendly version of Emacs, the EmacsW32 project makes Emacs out-of-the-box work just like a Windows text editor. Mind you, all of Emacs' power (and complexity) is there, but if you don't already have muscle memory built up, there's no reason not to use Ctrl-C/X/V as copy/cut/paste instead of M-w/C-k/C-y just to be cool. EmacsW32 also brings Windows-compliant open/save dialogs, sane CRLF file handling, and quite a bit more. If you've ever had an itch to try Emacs, give it a shot. You won't regret it. |
Hurray for pointers!
This code works by looking ahead 12 bits for each byte and copying the proper bits forward. 12 bits is the bottom half (nybble) of the next byte and the top half of 2 bytes away.
unsigned char length = 10;
unsigned char data[10] = {0x00, 0x00, 0x0A, 0xBC, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xBC};
unsigned char *shift = data;
while (shift < data+(length-2)) {
*shift = (*(shift+1)&0x0F)<<4 | (*(shift+2)&0xF0)>>4;
shift++;
}
*(data+length-2) = (*(data+length-1)&0x0F)<<4;
*(data+length-1) = 0x00;
> Jeremy wrote:
> @Mike, your solution works, but does not carry.
Well, I'd say a normal shift operation does just that (called overflow), and just lets the extra bits fall off the right or left. It's simple enough to carry if you wanted to - just save the 12 bits before you start to shift. Maybe you want a circular shift, to put the shifted 12 bits back at the bottom? Maybe you want to realloc the array and make it larger? You'd have to define what carry means to you.
unsigned char overflow[2];
*overflow = (*data&0xF0)>>4;
*(overflow+1) = (*data&0x0F)<<4 | (*(data+1)&0xF0)>>4;
while (shift < data+(length-2)) {
/* normal shifting */
}
/* now would be the time to copy it back if you want to carry it somewhere */
*(data+length-2) = (*(data+length-1)&0x0F)<<4 | (*(overflow)&0x0F);
*(data+length-1) = *(overflow+1);
/* You could return a 16-bit carry int,
* but endian-ness makes that look weird
* if you care about the physical layout */
unsigned short carry = *(overflow+1)<<8 | *overflow; |
Hurray for pointers!
This code works by looking ahead 12 bits for each byte and copying the proper bits forward. 12 bits is the bottom half (nybble) of the next byte and the top half of 2 bytes away.
unsigned char length = 10;
unsigned char data[10] = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0A,0xBC};
unsigned char *shift = data;
while (shift < data+(length-2)) {
*shift = (*(shift+1)&0x0F)<<4 | (*(shift+2)&0xF0)>>4;
shift++;
}
*(data+length-2) = (*(data+length-1)&0x0F)<<4;
*(data+length-1) = 0x00;
> Jeremy wrote:
> @Mike, your solution works, but does not carry.
Well, I'd say a normal shift operation does just that (called overflow), and just lets the extra bits fall off the right or left. It's simple enough to carry if you wanted to - just save the 12 bits before you start to shift. Maybe you want a circular shift, to put the shifted 12 bits back at the bottom? Maybe you want to realloc the array and make it larger? You'd have to define what carry means to you.
unsigned char overflow[2];
*overflow = (*data&0xF0)>>4;
*(overflow+1) = (*data&0x0F)<<4 | (*(data+1)&0xF0)>>4;
while (shift < data+(length-2)) {
/* normal shifting */
}
/* now would be the time to copy it back if you want to carry it somewhere */
*(data+length-2) = (*(data+length-1)&0x0F)<<4 | (*(overflow)&0x0F);
*(data+length-1) = *(overflow+1);
/* You could return a 16-bit carry int,
* but endian-ness makes that look weird
* if you care about the physical layout */
unsigned short carry = *(overflow+1)<<8 | *overflow; |
Hurray for pointers!
This code works by looking ahead 12 bits for each byte and copying the proper bits forward. 12 bits is the bottom half (nybble) of the next byte and the top half of 2 bytes away.
unsigned char length = 10;
unsigned char data[10] = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0A,0xBC};
unsigned char *shift = data;
while (shift < data+(length-2)) {
*shift = (*(shift+1)&0x0F)<<4 | (*(shift+2)&0xF0)>>4;
shift++;
}
*(data+length-2) = (*(data+length-1)&0x0F)<<4;
*(data+length-1) = 0x00;
> Jeremy wrote:
> @Mike, your solution works, but does not carry.
Well, I'd say a normal shift operation does just that (called overflow), and just lets the extra bits fall off the right or left. It's simple enough to carry if you wanted to - just save the 12 bits before you start to shift. Maybe you want a circular shift, to put the overflowed bits back at the bottom? Maybe you want to realloc the array and make it larger? Return the overflow to the caller? Return a boolean if non-zero data was overflowed? You'd have to define what carry means to you.
unsigned char overflow[2];
*overflow = (*data&0xF0)>>4;
*(overflow+1) = (*data&0x0F)<<4 | (*(data+1)&0xF0)>>4;
while (shift < data+(length-2)) {
/* normal shifting */
}
/* now would be the time to copy it back if you want to carry it somewhere */
*(data+length-2) = (*(data+length-1)&0x0F)<<4 | (*(overflow)&0x0F);
*(data+length-1) = *(overflow+1);
/* You could return a 16-bit carry int,
* but endian-ness makes that look weird
* if you care about the physical layout */
unsigned short carry = *(overflow+1)<<8 | *overflow; |
|html|css| |
|html|css|float| |
A good hash function has the following properties:
1. Given a hash of a message it is computationally infeasible for an attacker to find another message such that their hashes are identical.
2. Given a pair of message, m' and m, it is computationally infeasible to find two such that that h(m) = h(m')
The two cases are _not_ the same. In the first case, there is a pre-existing hash that you're trying to find a collision for. In the second case, you're trying to find _any_ two messages that collide. The second task is significantly easier due to the birthday "paradox."
Where performance is not that great an issue, you should always use a secure hash function. There are very clever attacks that can be performed by forcing collisions in a hash. If you use something strong from the outset, you'll secure yourself against these.
Don't use MD5 or SHA-1 in new designs. Most cryptographers, me included, would consider them broken. The principle source of weakness in both of these designs is that the second property, which I outlined above, does not hold for these constructions. If an attacker can generate two messages, m and m', that both hash to the same value they can use these messages against you. SHA-1 and MD5 also suffer from message extension attacks, which can fatally weaken your application if you're not careful.
A more modern has hash such as Whirpool is a better choice. It does not suffer from these message extension attacks and uses the same mathematics as AES uses to prove security against a variety of attacks.
Hope that helps! |
A good hash function has the following properties:
1. Given a hash of a message it is computationally infeasible for an attacker to find another message such that their hashes are identical.
2. Given a pair of message, m' and m, it is computationally infeasible to find two such that that h(m) = h(m')
The two cases are _not_ the same. In the first case, there is a pre-existing hash that you're trying to find a collision for. In the second case, you're trying to find _any_ two messages that collide. The second task is significantly easier due to the birthday "paradox."
Where performance is not that great an issue, you should always use a secure hash function. There are very clever attacks that can be performed by forcing collisions in a hash. If you use something strong from the outset, you'll secure yourself against these.
Don't use MD5 or SHA-1 in new designs. Most cryptographers, me included, would consider them broken. The principle source of weakness in both of these designs is that the second property, which I outlined above, does not hold for these constructions. If an attacker can generate two messages, m and m', that both hash to the same value they can use these messages against you. SHA-1 and MD5 also suffer from message extension attacks, which can fatally weaken your application if you're not careful.
A more modern hash such as Whirpool is a better choice. It does not suffer from these message extension attacks and uses the same mathematics as AES uses to prove security against a variety of attacks.
Hope that helps! |
Integers are immutable, which means that when you pass it as an argument it creates a copy rather than a reference to the same item. ([explanation][1]).
To get the behavior you're looking for, you can write your own class which is like Integer only mutable. Then, just pass it to the recursive function, it is incremented within the recursion, and when you access it again after the recursion is over it will still maintain its new values.
Edit: Note that using an int[] array is a variation on this method... In Java, arrays are also passed by reference rather than copied like primitives or immutable classes.
[1]: http://www.javaworld.com/javaworld/javaqa/2000-06/01-qa-0602-immutable.html |
First, accept the fact that problems with your app (code, usability, etc.) will be discovered.
Then, make sure you have a clear way for users to communicate with you (form mail, email, uservoice, etc.). The easier you make this the better. For example, there is a uservoice link on every page of SO.
One philosophy I strongly believe in: if it's confusing to your users, it's broken. Be willing to change your app (no matter how "beautiful" the design may be) if your users are confused or not liking it. This doesn't mean you have to cave on your decisions, just that you need to consider revisions to improve the user experience. |
In Visual Studio - Debug -> Exceptions -> Check the box by "Common Language Runtime Exceptions" in the Thrown Column |
In VS, if you look in the Locals area of your IDE while inside the catch block, you will have something to the effect of $EXCEPTION which will have all of the information for the exception that was just caught. |
You can write
catch (Exception ex) { }
Then when an exception is thrown and caught here, you can inspect ex. |
No it is impossible, because that code block says "I don't care about the exception". You could do a global find and replace with the following code to see the exception.
catch {}
with the following
catch (Exception exc) {
#IF DEBUG
object o = exc;
#ENDIF
}
What this will do is keep your current do nothing catch for Production code, but when running in DEBUG it will allow you to set break points on object o. |
HTML Help keyword location |
|indexing|chm|keywords| |
I'm writing a manual and some important keywords are repeated in several pages. In the project's index I defined the keywords like this:
<LI> <OBJECT type="text/sitemap">
<param name="Name" value="Stackoverflow">
<param name="Name" value="Overview">
<param name="Local" value="overview.html#stackoverflow">
<param name="Name" value="Cover">
<param name="Local" value="cover.html#stackoverflow">
<param name="Name" value="Intro">
<param name="Local" value="intro.html#stackoverflow">
</OBJECT>
It works but instead of the title the dialog shows the keyword and the name of the project repeated three times.
Here's how it looks: http://img54.imageshack.us/img54/3342/sokeywordjs9.png
How can I display the tile of the page that contains the keyword in that dialog? I would like to show like this:
Stackoverflow Overview
Stackoverflow Cover
Stackoverflow Intro
Thanks |
After you place a break point in them, you can also call them by name in the firebug console, and see the output of (or step through) any intermediate functions. This can help when the main entry point calls many other helper functions, and you are really just concerned with how these helpers are working.
That being said, I don't knwo anything about ASP.Net validators, so its possible this doesn't apply. |
Now, I'm not saying that this is the greatest name in the world, but here was the idea as I understand it.
The python keyword `open`, well, opens files. `Popen` was to open a Process and allow you to read and write from it's stdio like a file. Thus `Popen` is short for `ProccesOpen` in an attempt to kind of, sorta, look like open.
To have called it simply subprocess.open would have made:
from subprocess import open
problematic. And thus more unix/perl trained mindsets gave us Popen.
|
The . operator basically says "send this message to the object". In your example it is calling that particular method. The :: operator "drills down" to the scope defined to the left of the operator, and then calls the message defined on the right side of operator. |
The `.` operator basically says "send this message to the object". In your example it is calling that particular message. The `::` operator "drills down" to the scope defined to the left of the operator, and then calls the member defined on the right side of operator.
When you use `::` you have to be referencing members that are defined. When using `.` you are simply sending a message to the object. Because that message could be anything, auto-completion does not work for `.` while it does for `::`. |
The `.` operator basically says "send this message to the object". In your example it is calling that particular member. The `::` operator "drills down" to the scope defined to the left of the operator, and then calls the member defined on the right side of operator.
When you use `::` you have to be referencing members that are defined. When using `.` you are simply sending a message to the object. Because that message could be anything, auto-completion does not work for `.` while it does for `::`. |
Depending on what you are using in C++ (MFC, ATL, etc) you are probably going to have to install Visual Studio Professional (not express) as a lot of the libraries and headers are part of Visual Studio and not included in the SDK or Visual Studio Express (if you are doing managed C++ using .Net as the main framework then installing the SDK will be enough). We run our build boxes on VM's and so like to have as little installed as possible, so I spent a fair bit of time trying to get things working by installing as little as possible and for our C++ I ended up having to install Visual Studio. |
[WCF configuration default limits, concurrency and scalability][1]
[1]: http://weblogs.asp.net/paolopia/archive/2008/03/23/wcf-configuration-default-limits-concurrency-and-scalability.aspx |
[phpThumb][1] is a high-level abstraction that may be worth looking at.
[1]: http://phpthumb.sourceforge.net/ |
One explanation might be that negative numbers are stored using [2's complement](http://en.wikipedia.org/wiki/Two%27s_complement). When the python interpreter tries to do the modulo operation it converts to unsigned value. As such instead of doing (-2) % 5 it actually computes 0xFFFF_FFFF_FFFF_FFFD % 5 which is 3. |
[Google's Webmaster Tools][1] report that disallow always takes precedence over allow, so there's no easy way of doing this in a `robots.txt` file.
You could accomplish this by puting a `noindex,nofollow` `META` tag in the HTML every page but the home page.
[1]: http://google.com/webmasters/tools |
How do I write a While loop |
|conditional-statements|c#|vb.net| |
How do you write the syntax for a While loop?
## C`#`
> int i=0;
While (i! = 10)
{
Console.WriteLine(i);
i++;
}
## VB.Net
> Dim i As Integer = 0
While i <> 10
Console.WriteLine(i)
i += 1
End While
|
I think Windows' built-in Task Scheduler is the suggested tool for this job. That requires an outside application. |
I would vote for Option B. If you go with Option A and the assumption that if a user exists, they can get in, then you'll eventually run into the problem that you'll want to deny access to a user, without removing the user record.
There will be lots of cases where you'll want to lock a user out, but won't want to completely destroy their account. One such instance (not necessarily linked to your use case), is when you fail to pay, and they cut off your account until you start paying again. They don't want to delete the record, because they still want to enable it when you pay up again, instead of recreating the account from scratch, and losing all user history. |
Possibly a version of spawn() for python? <http://en.wikipedia.org/wiki/Spawn_(operating_system)> |
As you continue to gain more experience in ASP.Net, C#, etc - it's always good to go check out the competition and see if it sparks ideas on how you can do things better in what you're doing. Taking a look at something like Rails or Django might change how you look at designing or building your apps.
|
B. It allows for much better checks whether the data is complete (for example, when you add an allowable/deniable feature).
Also, table size should only be a consideration for tables that you know will contain many records (as in, 100,000+). You even taking the time to type the table size consideration into this question already cost more than the extra hard drive space it would take. |
Gigaspaces is top notch as far as a Javaspaces implementation goes for scalability and performance. Are you restricted to a Javaspaces implementation? Blitz Javaspaces is top notch for a free product. |
This may or may not be what you're looking for, but read this article, "[Simulate a Windows Service using ASP.NET to run scheduled jobs][1]". I think StackOverflow may use this method or it was at least talked about using it.
[1]: http://www.codeproject.com/kb/aspnet/aspnetservice.aspx |
If you're now proficient with the languages and technologies you use, then start spending more time focusing on the design, solution architecture, and systems integration. The "bigger picture" that will set you apart from your contemporaries.
Check out some Martin Fowler books like "Patterns of Enterprise Application Architecture", or Eric Evans' "Domain-Driven Design". |
javascript: in JS code (like in an onclick attribute) is just a label. It could be zipzambam: instead.
javascript: in the href attribute signifies a Javascript URI.
[Example](http://shadow2531.com/js/jsuri.html):
javascript:(function()%7Balert(%22test%22)%3B%7D)()%3B |
javascript: in JS code (like in an onclick attribute) is just a label for use with continue statements that may or may not be supported by the browser. It could be zipzambam: instead.
javascript: in the href attribute signifies a Javascript URI.
[Example](http://shadow2531.com/js/jsuri.html):
javascript:(function()%7Balert(%22test%22)%3B%7D)()%3B |
Hurray for pointers!
This code works by looking ahead 12 bits for each byte and copying the proper bits forward. 12 bits is the bottom half (nybble) of the next byte and the top half of 2 bytes away.
unsigned char length = 10;
unsigned char data[10] = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0A,0xBC};
unsigned char *shift = data;
while (shift < data+(length-2)) {
*shift = (*(shift+1)&0x0F)<<4 | (*(shift+2)&0xF0)>>4;
shift++;
}
*(data+length-2) = (*(data+length-1)&0x0F)<<4;
*(data+length-1) = 0x00;
> Justin wrote:
> @Mike, your solution works, but does not carry.
Well, I'd say a normal shift operation does just that (called overflow), and just lets the extra bits fall off the right or left. It's simple enough to carry if you wanted to - just save the 12 bits before you start to shift. Maybe you want a circular shift, to put the overflowed bits back at the bottom? Maybe you want to realloc the array and make it larger? Return the overflow to the caller? Return a boolean if non-zero data was overflowed? You'd have to define what carry means to you.
unsigned char overflow[2];
*overflow = (*data&0xF0)>>4;
*(overflow+1) = (*data&0x0F)<<4 | (*(data+1)&0xF0)>>4;
while (shift < data+(length-2)) {
/* normal shifting */
}
/* now would be the time to copy it back if you want to carry it somewhere */
*(data+length-2) = (*(data+length-1)&0x0F)<<4 | (*(overflow)&0x0F);
*(data+length-1) = *(overflow+1);
/* You could return a 16-bit carry int,
* but endian-ness makes that look weird
* if you care about the physical layout */
unsigned short carry = *(overflow+1)<<8 | *overflow; |
How do you get a custom id to render using HtmlHelper in MVC |
|asp.netmvc| |
|asp.net|mvc| |
Using [preview 4][1] of [ASP.NET MVC][2]
Code like:
<%= Html.CheckBox( "myCheckBox", "Click Here", "True", false ) %>
only outputs:
<input type="checkbox" value="True" name="myCheckBox" />
There is a `name` there for the form post back but no `id` for javascript or labels :-(
I was hoping that changing it to:
Html.CheckBox( "myCheckBox", "Click Here",
"True", false, new { id="myCheckBox" } )
would work - but instead I get an exception:
System.ArgumentException: An item with the same key has already been added.
As if there was already an id somewhere in a collection somewhere - I'm stumped!
The full exception for anyone interested follows (hey - wouldn't it be nice to attach files in here):
<pre>System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Web.Routing.RouteValueDictionary.Add(String key, Object value)
at System.Web.Mvc.TagBuilder2.CreateInputTag(HtmlInputType inputType, String name, RouteValueDictionary attributes)
at System.Web.Mvc.CheckBoxBuilder.CheckBox(String htmlName, RouteValueDictionary htmlAttributes)
at System.Web.Mvc.CheckBoxBuilder.CheckBox(String htmlName, String text, String value, Boolean isChecked, RouteValueDictionary htmlAttributes)
at System.Web.Mvc.CheckBoxExtensions.CheckBox(HtmlHelper helper, String htmlName, String text, String value, Boolean isChecked, Object htmlAttributes)
at ASP.views_account_termsandconditions_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\dev\myProject\Views\Account\Edit.ascx:line 108</pre>
[1]: http://www.codeplex.com/aspnet
[2]: http://asp.net/mvc |
Does JavaScript need access to cookies if AJAX is used? |
Are cookies required for an AJAX website? |
Are Http-Only cookies a viable option for an AJAX website? |
Does JavaScript need access to cookies if AJAX is used?
*Edit:* I'm sorry, I guess a lot of people don't understand the question, as evidenced by the edit to my question & the answers. Microsoft created a way to prevent XSS attacks by disallowing JavaScript access to cookies if Http-Only is specified. FireFox later adopted this. So my question is: If you are using AJAX on a site, like StackOverflow, are Http-Only cookies an option? |
JavaScript needs access to cookies if AJAX is used on a site with access restrictions based on cookies. Therefore, can we use Http-Only cookies. **Please look up Http-Onlybefore answering this question.**
*Edit:* I'm sorry, I guess a lot of people don't understand the question, as evidenced by the edit to my question & the answers. Microsoft created a way to prevent XSS attacks by disallowing JavaScript access to cookies if Http-Only is specified. FireFox later adopted this. So my question is: If you are using AJAX on a site, like StackOverflow, are Http-Only cookies an option?
*Edit 2:* Sorry people still don't understand the question. If the purpose of Http-Only is to prevent JavaScript access to cookies, and you can still retrieve the cookies via JavaScript through the AJAX Xml Object, **what is the point of Http-Only**? |
Are HttpOnly cookies a viable option for an AJAX website? |
|ajax|cookies|httponly| |
JavaScript needs access to cookies if AJAX is used on a site with access restrictions based on cookies. Will Http-Only cookies work on an AJAX site? **Please look up Http-Only before answering this question.**
*Edit:* I'm sorry, I guess a lot of people don't understand the question, as evidenced by the edit to my question & the answers. Microsoft created a way to prevent XSS attacks by disallowing JavaScript access to cookies if Http-Only is specified. FireFox later adopted this. So my question is: If you are using AJAX on a site, like StackOverflow, are Http-Only cookies an option?
*Edit 2:* Question 2. If the purpose of Http-Only is to prevent JavaScript access to cookies, and you can still retrieve the cookies via JavaScript through the XmlHttpRequest Object, **what is the point of Http-Only**? |
JavaScript needs access to cookies if AJAX is used on a site with access restrictions based on cookies. Will HttpOnly cookies work on an AJAX site? **Please look up HttpOnly before answering this question.**
*Edit:* I'm sorry, I guess a lot of people don't understand the question, as evidenced by the edit to my question & the answers. Microsoft created a way to prevent XSS attacks by disallowing JavaScript access to cookies if HttpOnly is specified. FireFox later adopted this. So my question is: If you are using AJAX on a site, like StackOverflow, are Http-Only cookies an option?
*Edit 2:* Question 2. If the purpose of HttpOnly is to prevent JavaScript access to cookies, and you can still retrieve the cookies via JavaScript through the XmlHttpRequest Object, **what is the point of HttpOnly**?
*Edit 3:* Here is a quote from Wikipedia:
>When the browser receives such a cookie, it is supposed to use it as usual in the following HTTP exchanges, but not to make it visible to client-side scripts.[32] The `HttpOnly` flag is not part of any standard, and is not implemented in all browsers. Note that there is currently no prevention of reading or writing the session cookie via a XMLHTTPRequest. [33].
I understand that `document.cookie` is blocked when you use HttpOnly. But it seems that you can still read cookie values in the XMLHttpRequest object, allowing for XSS. How does HttpOnly make you any safer than? By making cookies essentially read only?
In your example, I cannot write to your `document.cookie`, but I can still steal your cookie and post it to my domain using the XMLHttpRequest object.
<script type="text/javascript">
var req = null;
try { req = new XMLHttpRequest(); } catch(e) {}
if (!req) try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
if (!req) try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
req.open('GET', 'http://stackoverflow.com/', false);
req.send(null);
alert(req.getAllResponseHeaders());
</script>
|
Right click > TortoiseSVN > Settings > System Sounds..
Scroll down to the bottom. |
If you have somewhat of a legacy application and you're not allowed to change the visibility of your methods, best way to test private methods is to use Reflection. Internally we're using helpers to get/set <code>private</code> and <code>private static</code> variables as well as invoke <code>private</code> and <code>private static</code> methods. The following patterns will let you do pretty much anything related to the private methods and fields. Of course you can't change <code>private static final</code> variables through Reflection.
Method method = targetClass.getDeclaredMethod(methodName, argClasses);
method.setAccessible(true);
return (T) method.invoke(targetObject, argObjects);
And for fields:
Field field = targetClass.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(object, value);
The <code>setAccessible(true)</code> is required to play around with privates. |
If you have somewhat of a legacy application and you're not allowed to change the visibility of your methods, best way to test private methods is to use Reflection. Internally we're using helpers to get/set <code>private</code> and <code>private static</code> variables as well as invoke <code>private</code> and <code>private static</code> methods. The following patterns will let you do pretty much anything related to the private methods and fields. Of course you can't change <code>private static final</code> variables through Reflection.
Method method = targetClass.getDeclaredMethod(methodName, argClasses);
method.setAccessible(true);
return (T) method.invoke(targetObject, argObjects);
And for fields:
Field field = targetClass.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(object, value);
Notes:
* <code>targetClass.getDeclaredMethod(methodName, argClasses)</code> lets you look into <code>private</code> methods. Same thing applies for <code>getDeclaredField</code>.
* The <code>setAccessible(true)</code> is required to play around with privates.
|
If you have somewhat of a legacy application and you're not allowed to change the visibility of your methods, best way to test private methods is to use Reflection. Internally we're using helpers to get/set <code>private</code> and <code>private static</code> variables as well as invoke <code>private</code> and <code>private static</code> methods. The following patterns will let you do pretty much anything related to the private methods and fields. Of course you can't change <code>private static final</code> variables through Reflection.
Method method = targetClass.getDeclaredMethod(methodName, argClasses);
method.setAccessible(true);
return method.invoke(targetObject, argObjects);
And for fields:
Field field = targetClass.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(object, value);
Notes:
* <code>targetClass.getDeclaredMethod(methodName, argClasses)</code> lets you look into <code>private</code> methods. Same thing applies for <code>getDeclaredField</code>.
* The <code>setAccessible(true)</code> is required to play around with privates.
|
You can do this from the Sounds panel in Control Panel. |
How do you write the syntax for a While loop?
## C`#`
> int i=0;
while (i != 10)
{
Console.WriteLine(i);
i++;
}
## VB.Net
> Dim i As Integer = 0
While i <> 10
Console.WriteLine(i)
i += 1
End While
Edit: I searched on this site for how to do a while loop. The answer was not here, so I created the question and answered it for when this site goes public and Google indexes it. I know this was a easy question, but I saw a knowledge gap and decided to fill it. Feel free to edit or add more languages in the question. |
How do you write the syntax for a While loop?
## C`#`
> int i = 0;
while (i != 10)
{
Console.WriteLine(i);
i++;
}
## VB.Net
> Dim i As Integer = 0
While i <> 10
Console.WriteLine(i)
i += 1
End While
Edit: I searched on this site for how to do a while loop. The answer was not here, so I created the question and answered it for when this site goes public and Google indexes it. I know this was a easy question, but I saw a knowledge gap and decided to fill it. Feel free to edit or add more languages in the question. |
|c#|php|vb.net|conditional-statements| |
|c#|php|vb.net|python|conditional-statements| |
|c#|php|python|vb.net|conditional-statements| |
|c#|python|php|vb.net|conditional-statements| |
How do you write the syntax for a While loop?
## C`#`
> int i = 0;
while (i != 10)
{
Console.WriteLine(i);
i++;
}
## VB.Net
> Dim i As Integer = 0
While i <> 10
Console.WriteLine(i)
i += 1
End While
## PHP
<?php
while(CONDITION)
{
//Do something here.
}
?>
<?php
//MySQL query stuff here
$result = mysql_query($sql, $link) or die("Opps");
while($row = mysql_fetch_assoc($result))
{
$_SESSION['fName'] = $row['fName'];
$_SESSION['lName'] = $row['lName'];
//...
}
?>
Edit: I searched on this site for how to do a while loop. The answer was not here, so I created the question and answered it for when this site goes public and Google indexes it. I know this was a easy question, but I saw a knowledge gap and decided to fill it. Feel free to edit or add more languages in the question.
Edit: @Rob, Thank you for closing it. I was not looking for a Rep builder, I just want the next new programmer who searches for while loops to find this page and learn not only basic programming skills, but also introduced to all of your knowledge and be able to expand past while loops. |
How do you write the syntax for a While loop?
## C`#`
> int i = 0;
while (i != 10)
{
Console.WriteLine(i);
i++;
}
## VB.Net
> Dim i As Integer = 0
While i <> 10
Console.WriteLine(i)
i += 1
End While
## PHP
<?php
while(CONDITION)
{
//Do something here.
}
?>
<?php
//MySQL query stuff here
$result = mysql_query($sql, $link) or die("Opps");
while($row = mysql_fetch_assoc($result))
{
$_SESSION['fName'] = $row['fName'];
$_SESSION['lName'] = $row['lName'];
//...
}
?>
## Python
i = 0
while i != 10:
print i
i += 1
Edit: I searched on this site for how to do a while loop. The answer was not here, so I created the question and answered it for when this site goes public and Google indexes it. I know this was a easy question, but I saw a knowledge gap and decided to fill it. Feel free to edit or add more languages in the question.
Edit: @Rob, Thank you for closing it. I was not looking for a Rep builder, I just want the next new programmer who searches for while loops to find this page and learn not only basic programming skills, but also introduced to all of your knowledge and be able to expand past while loops. |
javascript: in JS code (like in an onclick attribute) is just a label for use with continue/goto label statements that may or may not be supported by the browser. It could be zipzambam: instead.
javascript: in the href attribute signifies a Javascript URI.
[Example](http://shadow2531.com/js/jsuri.html):
javascript:(function()%7Balert(%22test%22)%3B%7D)()%3B |
javascript: in JS code (like in an onclick attribute) is just a label for use with continue/goto label statements that may or may not be supported by the browser (probably not anywhere). It could be zipzambam: instead. Even if the label can't be used, browsers still accept it so it doesn't cause an error.
This means that if someone's throwing a useless label in an onclick attribute, they probably don't know what they're doing and are just copying and pasting or doing it out of habit from doing the below.
javascript: in the href attribute signifies a Javascript URI.
[Example](http://shadow2531.com/js/jsuri.html):
javascript:(function()%7Balert(%22test%22)%3B%7D)()%3B |
Have a look at the process management functions in the [os module](http://python.org/doc/2.5/lib/os-process.html). There are function for starting new processes in many different ways, both synchronously and asynchronously.
I should note also that Windows doesn't provide functionality that is exactly like fork() on other systems. To do multiprocessing on Windows, you will need to use the [threading](http://python.org/doc/2.5/lib/module-threading.html) module. |
Maybe learn more about Usability (best practices, testing, etc.) if you haven't already done so.
Steve Krug's "Don't Make Me Think" is a good book to start with. [Jakob Nielsen][1] always has interesting stuff as well.
[1]: http://www.useit.com/alertbox/ |
imaginaryboy gets it right, I believe. Btw, since you don't have Flex Builder, you might look into the free and open source FlashDevelop if you're on Windows. It's my favorite environment for developing anything Actionscript (the Flex support is pretty great, too). |
I found http://unfuddle.com saved me messing about with installing SVN or git. You can get a free account in there and use either of those - plus you can use your OpenID there.
Then you avoid having to mess about setting it up right and focus on how you're going to use it! |
There are a few ambiguities in your question. What operation needs to be successful?
For everything you want to know about drag and drop, browse through these search results (multiple pages worth):
[Raymond Chen on drag and drop][1]
[1]: http://www.google.com/search?q=drag+drop+site%3Ablogs.msdn.com%2Foldnewthing&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1 |
If it's only going to be Allow/Deny, then a simple linking table between Users and Resources would work fine. If there is an entry keyed to the User-Resource in the linking table, allow access.
UserResources
-------------
UserId FK->Users
ResourceId FK->Resources
and the sql would be something like
if exists (select 1 from UserResources
where UserId = @uid and ResourceId=@rid)
set @allow=1;
With a clustered index on (UserId and ResourceId), the query would be blindingly fast even with millions of records. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.