instruction stringlengths 0 30k ⌀ |
|---|
I'd use this code... (Basically what Lars said)
dialog := TDialogForm.Create( parentForm );
dialog.PopupParent := parentForm;
dialog.PopupMode := pmExplicit;
dialog.ShowModal(); |
I found [TinyMCE][1] pretty easy to implement. And it's light on bandwidth usage too.
[1]: http://tinymce.moxiecode.com |
If it is just an internal application, then you can avoid printing from the browser, and send a printout directly from the server to the nearest printer to the user. |
Switch branch names in git |
|git|branch| |
There may be more than one way to ask this question, so here's a desciption of the problem. I was working on master and committed some stuff and then decided I wanted to put that work on hold. I backed up a few commits and then branched from before I started my crap work. Practically this works fine, I just now have a different branch as my main development branch. I'm wondering how I could change things around so I'm working on master again but it doesn't have my junk work and said work is on a different branch.
Some ways this could be asked/solved:
How do I rename my master branch to something else and then rename something else to master?
How do I back up master and then cause all commits I've backed up past to be on a different branch?
Thanks! |
There may be more than one way to ask this question, so here's a desciption of the problem. I was working on master and committed some stuff and then decided I wanted to put that work on hold. I backed up a few commits and then branched from before I started my crap work. Practically this works fine, I just now have a different branch as my main development branch. I'm wondering how I could change things around so I'm working on master again but it doesn't have my junk work and said work is on a different branch.
Some ways this could be asked/solved:
How do I rename my master branch to something else and then rename something else to master?
How do I back up master and then cause all commits I've backed up past to be on a different branch?
Thanks for all the (quick) answers! They're all good. |
Not sure if it helps, but there's also a utility called [Microsoft LogParser](http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx) that you can supposedly use to parse text-based log files and use them as if they were a database. From the website:
> Log parser is a powerful, versatile
> tool that provides universal query
> access to text-based data such as log
> files, XML files and CSV files, as
> well as key data sources on the
> Windows® operating system such as the
> Event Log, the Registry, the file
> system, and Active Directory®. You
> tell Log Parser what information you
> need and how you want it processed.
> The results of your query can be
> custom-formatted in text based output,
> or they can be persisted to more
> specialty targets like SQL, SYSLOG, or
> a chart. Most software is designed to
> accomplish a limited number of
> specific tasks. Log Parser is
> different... the number of ways it can
> be used is limited only by the needs
> and imagination of the user. The
> world is your database with Log
> Parser.
I haven't used the program myself, but it seems quite interesting! |
Here's a good "How Do I" video that demonstrates data binding:
<http://windowsclient.net/learn/video.aspx?v=52579>
|
Set ASP.net executionTimeout in code / "refresh" request |
|c#|asp.net| |
i'll have an ASP.net page that creates some Excel Sheets and sends them to the user. The problem is, sometimes I get Http timeouts, presumably because the Request runs longer than executionTimeout (110 Seconds per default).
I just wonder what my options are to prevent this, without wanting to generally increase the executionTimeout in web.config?
In PHP, [set_time_limit][1] exists which can be used in a function to extend its life, but I did not see anything like that in C#/ASP.net?
How do you handle long-running functions in ASP.net?
[1]: http://fr.php.net/manual/en/function.set-time-limit.php |
I've not really had to face this issue to much yet myself, so please keep that in mind..
Is there not anyway you can run the process async and specify a callback method to occur once complete, and then keep the page in a "we are processing your request.." loop cycle.. You could then open this up to add some nice UI enhancements as well..
Just kinda thinking out loud.. That would probably be the sort of thing I would like to do :) |
I've actually done this (set up my own server using phpMyID). It's very easy and works quite well. One thing that annoys me to no end is the use of HTML redirects instead of HTTP. I changed that manually, based on some information gotten in the [phpMyID forum][1].
However, I have switched to [myOpenId][2] in the meantime. Rolling an own provider is fun and games but *it just isn't secure*! There are two issues:
* More generally, you have to act on faith. phpMyID is great but it's developed in someone's spare time. There could be many undetected security holes in it – and there have been some, in the past. While this of course applies to all security-related software, I believe the problem is potentially more severe with software developed in spare time, especially since the code is far from perfect in my humble opinion.
* Secondly, OpenID is highly susceptible to screen scraping and mock interfaces. It's just too easy for an attacker to emulate the phpMyID interface to obtain your credentials for another site. myOpenId offers two very important solutions to the problem.
* The first is its use of a cookie-stored picture that is embedded in the login page. If anyone screen-scapes the myOpenId login page, this picture will be missing and the fake can easily be identified.
* Secondly, myOpenId supports sign-in using strongly signed certificates that can be installed in the web browser.
I still have phpMyID set up as an alternative provider using [Yadis][3] but I wouldn't use it as a login on sites that I don't trust.
In any case, read Sam Ruby's [tutorial][4]!
[1]: https://www.siege.org/forum/viewforum.php?id=8
[2]: https://www.myopenid.com/
[3]: http://yadis.org/wiki/Main_Page
[4]: http://www.intertwingly.net/blog/2007/01/03/OpenID-for-non-SuperUsers |
As Chris Karcher said, you should probably use a user control. This will allow easy, VS-supported/-integrated reuse without having to manually fiddle with designer code. |
Have a look at the standard module [shlex][1] and modify one copy of it to match the syntax you use for your shell, it is a good starting point
If you want all the power of a complete solution for lexing/parsing, [ANTLR][2] can generate python too.
[1]: http://docs.python.org/lib/module-shlex.html
[2]: http://www.antlr.org/wiki/display/ANTLR3/Antlr3PythonTarget |
FWIW, the real problem was that I had included a semicolon at the end of my \set command:
> \set owner_password 'thepassword';
The semicolon was interpreted as an actual character in the variable:
> \echo :owner_password
> thepassword;
So when I tried to use it:
> CREATE ROLE myrole LOGIN UNENCRYPTED PASSWORD :owner_password NOINHERIT CREATEDB CREATEROLE VALID UNTIL 'infinity';
...I got this:
> CREATE ROLE myrole LOGIN UNENCRYPTED PASSWORD thepassword; NOINHERIT CREATEDB CREATEROLE VALID UNTIL 'infinity';
That not only failed to set the quotes around the literal, but split the command into 2 parts (the second of which was invalid as it started with "NOINHERIT").
The moral of this story: PostgreSQL "variables" are really macros used in text expansion, not true values. I'm sure that comes in handy, but it's tricky at first. |
An important point is that tail recursion is essentially equivalent to looping. It's not just a matter of compiler optimization, but a fundamental fact about expressiveness. This goes both ways: you can take any loop of the form
while(E) { S }; return Q
where `E` and `Q` are expressions and `S` is a sequence of statements, and turn it into a tail recursive function
f() = if E then { S; return f() } else { return Q }
Of course, `E`, `S`, and `Q` have to be defined to compute some interesting value over some variables. For example, the looping function
fibo(n) {
int i = 1, k = 0;
while( i <= n ) {
k += i;
++i;
}
return k;
}
is equivalent to the tail-recursive function(s)
fibo_aux(n,i,k) {
if( i <= n ) {
return fibo_aux(n,i+1,k+i);
} else {
return k;
}
}
fibo(n) {
fibo_aux(n,1,0);
}
(This "wrapping" of the tail-recursive function with a function with fewer parameters is a common functional idiom.) |
I've always done it exactly the way you're describing. I'm curious to see if there's a more accepted approach. |
> *is there a more standard pattern for doing stuff like this?*
No, it sounds like you're using the right approach.
If the dialog returns DialogResult.OK, assume that all the necessary properties in the dialog are valid. |
One final word on PSQL variables:
1. They don't expand if you enclose them in single quotes in the SQL statement.
Thus this doesn't work:
> SELECT * FROM FOO WHERE BAR = ':myvariable'
2. To expand to a string literal in a SQL statement, you have to include the quotes in the variable set. However, the variable value already has to be enclosed in quotes, which means that you need a _second_ set of quotes, and the inner set has to be escaped. Thus you need:
> \set myvariable '\'somestring\''
> SELECT * FROM FOO WHERE BAR = :myvariable
|
- [Gendarme][1] is an open source rules based static analyzer (similar to FXCop, but finds a lot of different problems).
- [Clone Detective][2] is a nice plug-in for Visual Studio that finds duplicate code.
- Also speaking of Mono, I find the act of compiling with the Mono compiler (if your code is platform independent enough to do that, a goal you might want to strive for anyway) finds tons of unreferenced variables and other Warnings that Visual Studio completely misses (even with the warning level set to 4).
[1]: http://www.mono-project.com/Gendarme
[2]: http://www.codeplex.com/CloneDetectiveVS |
> How can I display the tile of the page
> that contains the keyword in that
> dialog?
You can't. The Location column in the Topics Found dialog always contains the name of the source chm file of the topic. The only way to get around this is to use modular help, which comes with it's own share of problems and overhead.
The search and indexing features don't gracefully support topics with the same title within the same project. This seems shortsighted, but HTMLHelp is now over ten years old, so maybe they just planned to fix it later and never got around to it. |
Wny not use a table? Just have the first job update the table with it's status. The second job can use the table to check the status. That should do the trick if I am reading the question correctly. The table would (should) only have one row so it won't kill performance and shouldn't cause any deadlocking (of course, now that I write it, it will happen) :) |
Why not use a table? Just have the first job update the table with it's status. The second job can use the table to check the status. That should do the trick if I am reading the question correctly. The table would (should) only have one row so it won't kill performance and shouldn't cause any deadlocking (of course, now that I write it, it will happen) :)
@Jason: Yeah, you could monitor it or you could have a trigger start the second job when the end status is recieved. :) |
I believe anything non-trival you'll have to create a [Context Menu Handler][1].
http://msdn.microsoft.com/en-us/library/cc144171(VS.85).aspx
You'll have to create a COM object that will create the menus and carry out the commands as they're clicked.
[1]: http://msdn.microsoft.com/en-us/library/bb776881(VS.85).aspx |
I believe anything non-trival you'll have to create a [Context Menu Handler][1].
You'll have to create a COM object that will create the menus and carry out the commands as they're clicked. I've only done this using C++ and COM. I'm not sure if there are easier ways to do this.
[1]: http://msdn.microsoft.com/en-us/library/bb776881.aspx |
Best Practices for AS3 XML Parsing |
|xml|actionscript-3|flash|rss|fileparse| |
I've been having some trouble parsing various types of XML within flash (specifically FeedBurner RSS files and YouTube Data API responses). I'm using a `URLLoader` to load a XML file, and upon `Event.COMPLETE` creating a new XML object. 75% of the time this work fine, and every now and again I get this type of exception:
TypeError: Error #1085: The element type "link" must be terminated by the matching end-tag "</link>".
We think the problem is that The XML is large, and perhaps the `Event.COMPLETE` event is fired before the XML is actually downloaded from the `URLLoader`. The only solution we have come up with is to set off a timer upon the Event, and essentially "wait a few seconds" before beginning to parse the data. Surely this can't be the best way to do this.
Is there any surefire way to parse XML within Flash? |
|puzzle|algorithm|off-topic| |
|puzzle|algorithm| |
|algorithm|puzzle| |
100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100.
One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly permuted!).
Once inside room B, each prisoner gets to open 50 boxes (he chooses which one he opens). If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed.
Before entering room B, the prisoners can agree on a strategy (algorithm). There is no way to communicate between rooms (and no message can be left in room B!).
Find a strategy (algorithm) that maximizes the probability that all prisoners survive. What probability does your algorithm achieve?
Edits:
- Note that I did ask if it was OK to post puzzles. I'd like to get some feedback from people downvoting if possible!
- @Ross: doing things randomly (what you call 'no strategy') indeed gives a probability of 1/2 for each prisoner, but then the probability of all of them surviving is 1/2^100 (which is quite low). One can do much better!
- The prisoners are not allowed to reorder the boxes!
- Also, be assured that I do have an interesting solution. I'll post it in a week or so :) |
100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100.
One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly permuted!).
Once inside room B, each prisoner gets to open 50 boxes (he chooses which one he opens). If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed.
Before entering room B, the prisoners can agree on a strategy (algorithm). There is no way to communicate between rooms (and no message can be left in room B!).
Find a strategy (algorithm) that maximizes the probability that all prisoners survive. What probability does your algorithm achieve?
Edits:
- Note that I did ask if it was OK to post puzzles. I'd like to get some feedback from people downvoting if possible!
- @Ross: doing things randomly (what you call 'no strategy') indeed gives a probability of 1/2 for each prisoner, but then the probability of all of them surviving is 1/2^100 (which is quite low). One can do much better!
- The prisoners are not allowed to reorder the boxes!
- Also, be assured that I do have an interesting solution. I'll post it in a week or so :)
- @Sam Hasler: all prisoners are killed the first time a prisoner fails to find his number. *And* no communication is possible.
- Hint: one can save more than 30 prisoners on average, which is much more that (50/100) * (50/99) * [...] * 1
|
How to aggregate data from SQL Server 2005 |
|sql-server|ssas|reporting-services| |
I have about 150 000 rows of data written to a database everyday. These row represent outgoing articles for example. Now I need to **show a graph using [SSRS][1] that show the average number of articles per day over time**. **I also need to have a information about the actual number of articles from yesterday**.
The idea is to have a aggregated view on all our transactions and have something that can indicate that something is wrong (that we for example send out 20% less articles than the average).
My idea is to have yesterdays data moved into [SSAS][2] every night and there store the aggregated value of number of transactions and the actual number of transaction from yesterdays data. Using SSAS would hopefully speed up the reports.
**Do you thing this is the right idea? Should I skip SSAS and have reports straight on the raw data? I know how use reporting services on raw data using standard SQL queries but how would this change when querying SSAS? I don't know [SSAS][2] - where do I start ...**
[1]: http://www.microsoft.com/technet/prodtechnol/sql/2005/2005ssrs.mspx
[2]: http://www.microsoft.com/sql/technologies/analysis/default.mspx |
I have about 150 000 rows of data written to a database everyday. These row represent outgoing articles for example. Now I need to **show a graph using [SSRS][1] that show the average number of articles per day over time**. **I also need to have a information about the actual number of articles from yesterday**.
The idea is to have a aggregated view on all our transactions and have something that can indicate that something is wrong (that we for example send out 20% less articles than the average).
My idea is to have yesterdays data moved into [SSAS][2] every night and there store the aggregated value of number of transactions and the actual number of transaction from yesterdays data. Using SSAS would hopefully speed up the reports.
**Do you think this is the right idea? Should I skip SSAS and have reports straight on the raw data? I know how use reporting services on raw data using standard SQL queries but how would this change when querying SSAS? I don't know [SSAS][2] - where do I start ...**
[1]: http://www.microsoft.com/technet/prodtechnol/sql/2005/2005ssrs.mspx
[2]: http://www.microsoft.com/sql/technologies/analysis/default.mspx |
|sql-server|reporting-services|ssas| |
I have about 150 000 rows of data written to a database everyday. These row represent outgoing articles for example. Now I need to **show a graph using [SSRS][1] that show the average number of articles per day over time**. **I also need to have a information about the actual number of articles from yesterday**.
The idea is to have a aggregated view on all our transactions and have something that can indicate that something is wrong (that we for example send out 20% less articles than the average).
My idea is to have yesterdays data moved into [SSAS][2] every night and there store the aggregated value of number of transactions and the actual number of transaction from yesterdays data. Using SSAS would hopefully speed up the reports.
**Do you think this is the right idea? Should I skip SSAS and have reports straight on the raw data? I know how use reporting services on raw data using standard SQL queries but how would this change when querying SSAS? I don't know [SSAS][2] - where do I start ..?**
[1]: http://www.microsoft.com/technet/prodtechnol/sql/2005/2005ssrs.mspx
[2]: http://www.microsoft.com/sql/technologies/analysis/default.mspx |
How do you use script variables in PostgreSQL? |
|postgresql|variables|sql| |
In MS SQL Server, create my scripts to use customizable variables:
declare @somevariable int
select @somevariable = -1
insert into foo values ( @somevariable )
I'll then change the value of @somevariable at runtime, depending on the value that I want the particular situation. Since it's at the top of the script it's easy to see & remember.
How do I do the same with PostgreSQL?
Googling turned up <a href="http://www.postgresql.org/docs/8.1/static/app-psql.html#APP-PSQL-VARIABLES">PSQL variables</a>, but it's implied that they can only be used <em>within other slash commands</em>, not in actual SQL. |
|sql|postgresql|variables| |
In MS SQL Server, create my scripts to use customizable variables:
declare @somevariable int
select @somevariable = -1
insert into foo values ( @somevariable )
I'll then change the value of @somevariable at runtime, depending on the value that I want the particular situation. Since it's at the top of the script it's easy to see & remember.
How do I do the same with PostgreSQL?
Googling turned up <a href="http://www.postgresql.org/docs/8.1/static/app-psql.html#APP-PSQL-VARIABLES">PSQL variables</a>, but it's implied that they can only be used <em>within other slash commands</em>, not in actual SQL.
EDIT: Found my own answers, and they're actually fairly complicated. Sort the posts older->newer to follow my discoveries. |
I don't think this is a good idea just like reading files or accessing the database in unit tests isn't a good idea. Your tests will become dependent on the state of an external piece of software. Or you will have a lot of setup and teardown code. If you write tests this way you can expect you'll spend a lot of extra time maintaining your test-code. Setting up and maintaining a build server will become harder too and setting up the development environment for new programmers will take more time.
The way to go in cases like this is to set up an adapter class around the infrastructure for calling into AD and to use something like rhino-mocks or another mocking framework to setup a mock-active-directory in your tests. If you're not familiar with mocking it sounds like a lot of work. But in practice it's usually only a couple of lines of code per test. |
I would say exposing properties on your custom dialog is the idiomatic way to go because that is how standard dialogs (like the Select/OpenFileDialog) do it. Someone could argue it is more explicit and intention revealing to have a ShowBirthdayDialog() method that returns the result you're looking for, but following the framework's pattern is probably the wise way to go. |
The trick here is to not become a zealot.
One thing to note here is that no one in the pro file system camp has listed a particular file system. Does this mean that everything from FAT16 to ZFS handily beats every database?
No.
The truth is that many databases beat many files systems, even when we're only talking about raw speed.
The correct course of action is to make the right decision for your precise scenario, and to do that, you'll need some numbers and some use case estimates. |
ASP.NET MVC: Structuring Controllers |
|asp.net-mvc| |
So I'm embarking on an ASP.NET MVC project and while the experience has been a good one overall, I'm not quite as pleased with the spaghetti mess that my controllers have become. I've looked around online (CodeCampServer, etc...) and they all seem to suffer the same issue wherein controller methods violate SRP (single responsibility principle) pretty consistently - such as a controller method that simply renders the view if the request is a GET but updates the model if it's a POST. Now I've got controller methods responsible for multiple logical routes throughout the application - say it checks for which button was clicked on the form and acts accordingly. I could redirect each button click to a different form action using JavaScript, but something doesn't feel right there either... The other big issue is the proliferation of magic strings - ViewData["foo"] = blah; Long story short, how do you guys structure your controller logic? One giant model object per view? Lots of little controller methods and JavaScript is the router? My goal is maintainable code - as features get piled on I'm starting to slide down that slippery slope... |
@[Curt Hagenlocher](#12394) - that's back to front. I've no idea why so many have voted it up when it's wrong.
`IDisposable` is for *managed* resources.
Finalisers are for *unmanaged* resources.
As long as you only use managed resources both @[Jon Limjap](#12375) and [myself](#12380) are entirely correct.
For classes that use unmanaged resources (and bear in mind that the vast majority of .Net classes don't) [Patrik's answer](#12405) is comprehensive and best practice.
----------
I've removed the moderator comment from the original question in line with <http://stackoverflow.com/questions/14593/etiquette-for-modifying-posts>
|
@[Curt Hagenlocher](#12394) - that's back to front. I've no idea why so many have voted it up when it's wrong.
`IDisposable` is for *managed* resources.
Finalisers are for *unmanaged* resources.
As long as you only use managed resources both @[Jon Limjap](#12375) and [myself](#12380) are entirely correct.
For classes that use unmanaged resources (and bear in mind that the vast majority of .Net classes don't) [Patrik's answer](#12405) is comprehensive and best practice.
Avoid using GC.Collect - it is a slow way to deal with managed resources, and doesn't do anything with unmanaged ones unless you have correctly built your ~Finalizers.
----------
I've removed the moderator comment from the original question in line with <http://stackoverflow.com/questions/14593/etiquette-for-modifying-posts>
|
> Is Visual Studio prompting you for the
> path to the source file?
No.
> If it isn't then it doesn't think it has symbols
> for the callstack. Setting the source
> path should work without having to map
> the exact original location.
Symbols are loaded successfully. It shows the callstack, but double clicking on an entry doesn't bring me to the source code. I can of course search in files for the line in question, but this is hard work :) |
Looks like they've added controller.UpdateModel to address this issue, signature is:
UpdateModel(object model, string[] keys)
I haven't upgraded my app personally, so I'm not sure of the actual usage. I'll be interested to find out about this myself, as I'm using controller.ReadFromRequest as well. |
100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100.
One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly permuted!).
Once inside room B, each prisoner gets to open 50 boxes (he chooses which one he opens). If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed.
Before entering room B, the prisoners can agree on a strategy (algorithm). There is no way to communicate between rooms (and no message can be left in room B!).
Find a strategy (algorithm) that maximizes the probability that all prisoners survive. What probability does your algorithm achieve?
Edits:
- Note that I did ask if it was OK to post puzzles. I'd like to get some feedback from people downvoting if possible!
- @Ross: doing things randomly (what you call 'no strategy') indeed gives a probability of 1/2 for each prisoner, but then the probability of all of them surviving is 1/2^100 (which is quite low). One can do much better!
- The prisoners are not allowed to reorder the boxes!
- Also, be assured that I do have an interesting solution. I'll post it in a week or so :)
- @Sam Hasler: all prisoners are killed the first time a prisoner fails to find his number. *And* no communication is possible.
- Hint: one can save more than 30 prisoners on average, which is much more that (50/100) * (50/99) * [...] * 1
- @Rob Cooper: I get your point (no point in yelling!), however it reflects your opinion (and that of some others I'm sure), and I don't yet see a consensus on that matter. I do respect your opinion (didn't vote on your answer, or on any other by the way), but I'd really like to have this clarified (in the FAQ for example...).
|
100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100.
One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly permuted!).
Once inside room B, each prisoner gets to open 50 boxes (he chooses which one he opens). If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed.
Before entering room B, the prisoners can agree on a strategy (algorithm). There is no way to communicate between rooms (and no message can be left in room B!).
Find a strategy (algorithm) that maximizes the probability that all prisoners survive. What probability does your algorithm achieve?
Edits:
- Note that I did ask if it was OK to post puzzles. I'd like to get some feedback from people downvoting if possible!
- @Ross: doing things randomly (what you call 'no strategy') indeed gives a probability of 1/2 for each prisoner, but then the probability of all of them surviving is 1/2^100 (which is quite low). One can do much better!
- The prisoners are not allowed to reorder the boxes!
- Also, be assured that I do have an interesting solution. I'll post it in a week or so :)
- @Sam Hasler: all prisoners are killed the first time a prisoner fails to find his number. *And* no communication is possible.
- Hint: one can save more than 30 prisoners on average, which is much more that (50/100) * (50/99) * [...] * 1
- @Rob Cooper: I get your point (no point in yelling!), however it reflects your opinion (and that of some others I'm sure), and I don't yet see a consensus on that matter. I do respect your opinion (didn't vote on your answer, or on any other by the way), but I'd really like to have this clarified (in the FAQ for example...).
- @Jorge: I didn't get into the details of your solution yet, but I don't see how you can be sure to save prisoner #2 (if you achieve 50%, it means that if the first one finds his number, then all others are certain to find theirs, as 50% is the best that prisoner #1 can achieve).
|
I think what you're talking about is "obfuscation".
There are lots of articles about it on the net:
http://en.wikipedia.org/wiki/Obfuscation
The "standard" tool for obfuscation on .NET is by Preemptive Solutions:
http://www.preemptive.com/obfuscator.html
They have a community edition that ships with Visual Studio which you can use.
You mentioned ILDasm, have you looked at the .NET Reflector?
http://aisto.com/roeder/dotnet/
It gives you an even better idea as to what people can see if you release a manifest! |
How do you stop the Designer generating code for public properties on a User Control? |
|c#|winforms| |
How do you stop the designer from auto generating code that sets the value for public properties on a user control?
|
I would say this.. "How do we normally deal with differences between components?"
**Encapsulate what varies**..
You need to create an abstraction layer within you data access layer to get it to the point where it _doesn't care_ whether or not the database is MySQL or MS SQL.. |
Consolas for Visual Studio. It is the first thing I change when getting a new install setup. The second is inverting the main colors, white text on black background is much easier to stare at for hours in my opinion.
![Black text on white background][1]
Versus
![White text on black background][2]
The second one tends to make my eyes bleed less after long coding sessions. Could be my code however.
[1]: http://college-code.com/stackoverflow/black_on_white.PNG
[2]: http://college-code.com/stackoverflow/white_on_black.PNG |
How do I deal with quotes ' in SQL |
|sql|oracle-database| |
I have a database with names in it such as John Doe etc. Unfortunately some of these names contain quotes like Keiran O'Keefe. Now when I try and search for such names as follows:
SELECT * FROM PEOPLE WHERE SURNAME='O'Keefe'
I (understandably) get an error.
How do I prevent this error from occurring. I am using Oracle and PLSQL. |
I would buy a book - the Adam Nathan WPF book is good.
http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917 |
Found in under 30s on Google...
[Oracle SQL FAQ](http://www.orafaq.com/wiki/SQL_FAQ#How_does_one_escape_special_characters_when_writing_SQL_queries.3F) |
SSAS is an [ETL][1] tool. Basically you get data from somewhere (your outgoing articles), do something to it (aggregate), and put it somewhere else (your aggregates table, data warehouse, etc). Check the link for details.
You probably won't be keeping all of the rows in the DB indefinitely and if you want to be able to report on longer trends you need in any case do some kind of aggregating of historical data. So making the reports use this historical data store as their source makes sense. You can then use it to do all kinds of fancy reporting.
TL;DR: Define your aggregated history table with your future reporting needs in mind. Use the SSAS to populate the table and refresh it from the daily updates. Report from that table. Further reading: Star Schemas and data warehousing.
[1]: http://en.wikipedia.org/wiki/Extract,_transform,_load |
I've been having some trouble parsing various types of XML within flash (specifically FeedBurner RSS files and YouTube Data API responses). I'm using a `URLLoader` to load a XML file, and upon `Event.COMPLETE` creating a new XML object. 75% of the time this work fine, and every now and again I get this type of exception:
TypeError: Error #1085: The element type "link" must be terminated by the matching end-tag "</link>".
We think the problem is that The XML is large, and perhaps the `Event.COMPLETE` event is fired before the XML is actually downloaded from the `URLLoader`. The only solution we have come up with is to set off a timer upon the Event, and essentially "wait a few seconds" before beginning to parse the data. Surely this can't be the best way to do this.
Is there any surefire way to parse XML within Flash?
**Update** We have determined that even using the updated code ([here][1]) to account for `bytesLoaded` and `bytesTotal`, the parser still occasionally hiccups. We are now thinking it may have something to do with Feedburner.
We have discovered that Feedburner does not have a proper response header attachment for `Content-Length`. Does anyone know how flash handles documents loaded without a length?
[1]: #20639 |
|xml|flash|actionscript-3|rss|fileparse| |
I've been having some trouble parsing various types of XML within flash (specifically FeedBurner RSS files and YouTube Data API responses). I'm using a `URLLoader` to load a XML file, and upon `Event.COMPLETE` creating a new XML object. 75% of the time this work fine, and every now and again I get this type of exception:
TypeError: Error #1085: The element type "link" must be terminated by the matching end-tag "</link>".
We think the problem is that The XML is large, and perhaps the `Event.COMPLETE` event is fired before the XML is actually downloaded from the `URLLoader`. The only solution we have come up with is to set off a timer upon the Event, and essentially "wait a few seconds" before beginning to parse the data. Surely this can't be the best way to do this.
Is there any surefire way to parse XML within Flash?
**Update again** Turns out it is not an issue regarding Feedburner and Content-Length headers as i orignally thought (see the last revision), as we switched xml feeds and it still occasionally doesn't work. This is really baffling us.
[1]: #20639 |
I've been having some trouble parsing various types of XML within flash (specifically FeedBurner RSS files and YouTube Data API responses). I'm using a `URLLoader` to load a XML file, and upon `Event.COMPLETE` creating a new XML object. 75% of the time this work fine, and every now and again I get this type of exception:
TypeError: Error #1085: The element type "link" must be terminated by the matching end-tag "</link>".
We think the problem is that The XML is large, and perhaps the `Event.COMPLETE` event is fired before the XML is actually downloaded from the `URLLoader`. The only solution we have come up with is to set off a timer upon the Event, and essentially "wait a few seconds" before beginning to parse the data. Surely this can't be the best way to do this.
Is there any surefire way to parse XML within Flash?
**Update Sept 2 2008** We have concluded the following, the excption is fired [in the code][1] at this point:
[1]: #20639 "previously posted"
data = new XML(mainXMLLoader.data);
// calculate the total number of entries.
for each (var i in data.channel.item){
_totalEntries++;
}
I have placed a try/catch statement around this part, and am currently displaying an error message on screen when it occurs. My question is how would an incomplete file get to this point if the `bytesLoaded == bytesTotal`? |
The answer to this was found by [shog9][1]. The postData parameter needs to be a nsIMIMEInputStream object as detailed in
[http://developer.mozilla.org/index.php?title=En/Code_snippets/Post_data_to_window][2]
[1]: http://stackoverflow.com/questions/36958/stackoverflow-ubiquity-command#36962
[2]: http://developer.mozilla.org/index.php?title=En/Code_snippets/Post_data_to_window |
If you want results you can rely on you need to make the testing scenario as realistic as possible, which makes option 1 by far your best bet. As you point out if you get results that aren't good enough with the other options you won't be sure that it wasn't due to the different database behaviour.
How you generate the data will depend to a large degree on the problem domain. Can you take data sets from multiple customers and merge them into a single mega-dataset? If the data is time series then maybe it can be duplicated over a different range. |
I'd move to lists and solve it this way:<br/>
1. Sort both lists by id ascending using custom [Comparator](http://java.sun.com/j2se/1.5.0/docs/api/index.html?java/util/Comparator.html) if objects in lists aren't [Comparable](http://java.sun.com/j2se/1.5.0/docs/api/index.html?java/lang/Comparable.html)
2. Iterate over elements in both lists like in merge phase in [merge sort algorithm](http://en.wikipedia.org/wiki/Merge_sort), but instead of merging lists, you check your logic.
The code would be more or less like this:
/* Main method */
private void execute(Collection<Foo> oldSet, Collection<Foo> newSet) {
List<Foo> oldList = asSortedList(oldSet);
List<Foo> newList = asSortedList(newSet);
int oldIndex = 0;
int newIndex = 0;
// Iterate over both collections but not always in the same pace
while( oldIndex < oldList.size()
&& newIndex < newIndex.size()) {
Foo oldObject = oldList.get(oldIndex);
Foo newObject = newList.get(newIndex);
// Your logic here
if(oldObject.getId() < newObject.getId()) {
doRemove(oldObject);
oldIndex++;
} else if( oldObject.getId() > newObject.getId() ) {
doAdd(newObject);
newIndex++;
} else if( oldObject.getId() == newObject.getId()
&& isModified(oldObject, newObject) ) {
doUpdate(oldObject, newObject);
oldIndex++;
newIndex++;
} else {
...
}
}// while
// Check if there are any objects left in *oldList* or *newList*
for(; oldIndex < oldList.size(); oldIndex++ ) {
doRemove( oldList.get(oldIndex) );
}// for( oldIndex )
for(; newIndex < newList.size(); newIndex++ ) {
doAdd( newList.get(newIndex) );
}// for( newIndex )
}// execute( oldSet, newSet )
/** Create sorted list from collection
If you actually perform any actions on input collections than you should
always return new instance of list to keep algorithm simple.
*/
private List<Foo> asSortedList(Collection<Foo> data) {
List<Foo> resultList;
if(data instanceof List) {
resultList = (List<Foo>)data;
} else {
resultList = new ArrayList<Foo>(data);
}
Collections.sort(resultList)
return resultList;
} |
Best practices for versioning your services with WCF? |
100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100.
One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly permuted!).
Once inside room B, each prisoner gets to open 50 boxes (he chooses which one he opens). If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed.
Before entering room B, the prisoners can agree on a strategy (algorithm). There is no way to communicate between rooms (and no message can be left in room B!).
Find a strategy (algorithm) that maximizes the probability that all prisoners survive. What probability does your algorithm achieve?
Edits:
- Note that I did ask if it was OK to post puzzles. I'd like to get some feedback from people downvoting if possible!
- @Ross: doing things randomly (what you call 'no strategy') indeed gives a probability of 1/2 for each prisoner, but then the probability of all of them surviving is 1/2^100 (which is quite low). One can do much better!
- The prisoners are not allowed to reorder the boxes!
- Also, be assured that I do have an interesting solution. I'll post it in a week or so :)
- @Sam Hasler: all prisoners are killed the first time a prisoner fails to find his number. *And* no communication is possible.
- Hint: one can save more than 30 prisoners on average, which is much more that (50/100) * (50/99) * [...] * 1
- @Rob Cooper: I get your point (no point in yelling!), however it reflects your opinion (and that of some others I'm sure), and I don't yet see a consensus on that matter. I do respect your opinion (didn't vote on your answer, or on any other by the way), but I'd really like to have this clarified (in the FAQ for example...).
- @Jorge: I still didn't get into the details of your solution, but I believe that you can indeed do it this way. However, this is basically using time to communicate. The solution I have in mind doesn't involve any kind of communication (so people can't rely on time, for example).
- @chakrit: it would help if you provided the probability that your method achieves. In case it's too complicated to work out, running simulations (Monte-Carlo like) would give you an estimate!
|
100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100.
One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly permuted!).
Once inside room B, each prisoner gets to open 50 boxes (he chooses which one he opens). If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed.
Before entering room B, the prisoners can agree on a strategy (algorithm). There is no way to communicate between rooms (and no message can be left in room B!).
Find a strategy (algorithm) that maximizes the probability that all prisoners survive. What probability does your algorithm achieve?
Edits:
- Note that I did ask if it was OK to post puzzles. I'd like to get some feedback from people downvoting if possible!
- @Ross: doing things randomly (what you call 'no strategy') indeed gives a probability of 1/2 for each prisoner, but then the probability of all of them surviving is 1/2^100 (which is quite low). One can do much better!
- The prisoners are not allowed to reorder the boxes!
- Also, be assured that I do have an interesting solution. I'll post it in a week or so :)
- @Sam Hasler: all prisoners are killed the first time a prisoner fails to find his number. *And* no communication is possible.
- <b>Hint</b>: one can save more than 30 prisoners *on average*, which is much more that (50/100) * (50/99) * [...] * 1
- @Rob Cooper: I get your point (no point in yelling!), however it reflects your opinion (and that of some others I'm sure), and I don't yet see a consensus on that matter. I do respect your opinion (didn't vote on your answer, or on any other by the way), but I'd really like to have this clarified (in the FAQ for example...).
- @Jorge: I still didn't get into the details of your solution, but I believe that you can indeed do it this way. However, this is basically using time to communicate. The solution I have in mind doesn't involve any kind of communication (so people can't rely on time, for example).
- @chakrit: it would help if you provided the probability that your method achieves. In case it's too complicated to work out, running simulations (Monte-Carlo like) would give you an estimate!
|
|wcf| |
I'm starting to work with my model almost exclusively in WCF and wanted to get some practical approaches to versioning these services over time. Can anyone point me in the right direction? |
How to Throw an exception in a using block with .NET 2.0? |
|ado.net| |
I'm trying to leverage the using block more and more these days when I have an object that implements IDisposable but one thing I have not figured out is how to throw and exception as I would in a normal try/catch ... any code samples to point me in the right direction? |
|ado.net|.net-2.0|exception|error-handling| |
How to Catch an exception in a using block with .NET 2.0? |
I'm trying to leverage the using block more and more these days when I have an object that implements IDisposable but one thing I have not figured out is how to catch an exception as I would in a normal try/catch/finally ... any code samples to point me in the right direction? |
|exception|.net-2.0|ado.net|error-handling| |
I'm trying to leverage the using block more and more these days when I have an object that implements IDisposable but one thing I have not figured out is how to catch an exception as I would in a normal try/catch/finally ... any code samples to point me in the right direction?
Edit: The question was modified after reading through the replies. It was "How to Throw an exception in a using block with .NET 2.0?" but I was actually looking for a way to catch these exceptions inside a using block. |
This does what you want in VBA
Function GetNthExcelColName(n As Integer) As String
Dim s As String
s = Cells(1, n).Address
GetNthExcelColName = Mid(s, 2, InStr(2, s, "$") - 2)
End Function |
The data is typically CRM-like, i.e. contacts, projects, etc. It would be fine to simply duplicate the data (e.g., if I only have 20,000 rows, I'll copy them five times to get my desired 100,000 rows). Merging, on the other hand, would only work if we never deploy the benchmarking tool publicly, for obvious privacy reasons (unless, of course, I apply a function to each column that renders the original data unintelligible beyond repair? Similar to a hashing function, only without modifying the value's size too much).
To populate the rows, perhaps something like this would do:
WHILE (SELECT count(1) FROM benchmark) < 100000
INSERT INTO benchmark
SELECT TOP 100000 * FROM actualData |
@pek<br/>
Chained invocation is one of proposals for Java 7. It says that if a method return type is void, it should implicitly return **this**. If you're interested in this topic, there is a bunch of links and a simple example on [Alex Miller's Java 7 page](http://tech.puredanger.com/java7#chained).
|
How can I set breakpoints in an external JS script in Firebug |
Yes, there are many .NET Framework collection, that does not implement generic IEnumerable.
I think that's because after 2.0 there was no (at least not so match) development of the core part of FW.
Meanwhile I suggest you to make use of following workaround:
> using System.Link; ... var nodes =
> GetTreeNodeCollection().OfType<TreeNode>(); |
Yes, there are many .NET Framework collection, that does not implement generic IEnumerable.
I think that's because after 2.0 there was no (at least not so match) development of the core part of FW.
Meanwhile I suggest you to make use of following workaround:
using System.Link;
...
var nodes = GetTreeNodeCollection().OfType<TreeNode>(); |
I suppose the name was chosen because the functionality <code>subprocess</code> is replacing was formerly in the <code>os</code> module as the <code>os.popen</code> function. There could be even ways to automate migration between the two. |
`subprocess.Popen` replaces the group of `os.popenX` POSIX functions (which have a long history). I suppose that the name `Popen` makes it more likely for people used to the old functions to find and use the new ones.
The [PEP for subprocess (PEP 324)][1] has a little bit of discussion on the name of the module but not of class `Popen`. The [list of PEPs][2] (Python enhancement proposals) is in general an excellent place to start if you're looking for the rationale for features of Python.
[1]: http://www.python.org/dev/peps/pep-0324/
[2]: http://www.python.org/dev/peps/ |
I think the reason is to ensure that any result can be encompassed. so the natural choice is double as it is the largest data type. |
Floating point constants should have the available highest precision. The result can be assigned to a float without undue trouble. |