instruction stringlengths 0 30k ⌀ |
|---|
I'm not a beginner at C# but I really need to increase my understanding, so I've picked a classic deadlock problem to code to help teach myself some of the more advanced concepts of C#. The [Dining Philosophers Problem][1] seems like a good one, but I need a little help to get started. I know I need to approach the "diners" as objects, but to simulate the random delays between eating, should I look to threading with each diner in a separate thread? Do I need some kind of "master" to monitor all the actions? Any general design concept advice is welcome, but I'd like to do the grunt programming as an exercise. Thanks!
[1]: http://en.wikipedia.org/wiki/Dining_philosopher%27s_problem |
Yes, you can add the `/x` [Pattern Modifier](http://us.php.net/manual/en/reference.pcre.pattern.modifiers.php).
> This modifier turns on additional
> functionality of PCRE that is
> incompatible with Perl. Any backslash
> in a pattern that is followed by a
> letter that has no special meaning
> causes an error, thus reserving these
> combinations for future expansion. By
> default, as in Perl, a backslash
> followed by a letter with no special
> meaning is treated as a literal. There
> are at present no other features
> controlled by this modifier.
For your example try this:
preg_match('/
^J[0-9]{7}:\s+
(.*?) #Extract the Transaction Start Date msg
\s+J[0-9]{7}:\s+Project\sname:\s+
(.*?) #Extract the Project Name
\s+J[0-9]{7}:\s+Job\sname:\s+
(.*?) #Extract the Job Name
\s+J[0-9]{7}:\s+
/x', $this->getResultVar('FullMessage'), $atmp);
|
In PHP the comment syntax looks like this:<pre>(?# Your comment here)</pre>
preg_match('
^J[0-9]{7}:\s+
(.*?) (?#Extract the Transaction Start Date msg)
\s+J[0-9]{7}:\s+Project\sname:\s+
(.*?) (?#Extract the Project Name)
\s+J[0-9]{7}:\s+Job\sname:\s+
(.*?) (?#Extract the Job Name)
\s+J[0-9]{7}:\s+
', $this->getResultVar('FullMessage'), $atmp);
For more information see the [PHP Regular Expression Syntax Reference][1]
[1]:http://nl.php.net/manual/en/regexp.reference.php |
In PHP the comment syntax looks like this:<pre>(?# Your comment here)</pre>
preg_match('
^J[0-9]{7}:\s+
(.*?) (?#Extract the Transaction Start Date msg)
\s+J[0-9]{7}:\s+Project\sname:\s+
(.*?) (?#Extract the Project Name)
\s+J[0-9]{7}:\s+Job\sname:\s+
(.*?) (?#Extract the Job Name)
\s+J[0-9]{7}:\s+
', $this->getResultVar('FullMessage'), $atmp);
For more information see the [PHP Regular Expression Syntax Reference][1]
You can also use the PCRE_EXTENDED (or 'x') [Pattern Modifier][2] as Mark shows in his example.
[1]:http://nl.php.net/manual/en/regexp.reference.php
[2]:http://nl.php.net/manual/en/reference.pcre.pattern.modifiers.php |
I run XCode on a current-gen Macbook with only ONE GB of RAM and it runs fine, so long as I limit the amount of total applications running. |
Answering to the original question:
- ASCII is bad : I had to squint to find "WOW". Is this even correct? It could be "VVOVV" or whatever;
- Very simple arithmetic is good. Blind people will be able to answer. (But as Jarod said, beware of operator precedence.) I gather someone could write a parser, but it makes the spamming more costly.
- Trivia is OK, but you'll have to write each of them :-(
I've seen pictures of animals [what is it?]. Votes for comics use a picture of a character with their name written somewhere in the image [type in name]. Impossible to parse, not ok for blind people.
You could have an audio fallback reading alphanumerics (the same letters and numbers you have in the captcha).
Final line of defense: make spam easy to report (one click) and easy to delete (one recap screen to check it's a spam account, with the last ten messages displayed, one click to delete account). This is still time-expensive, though. |
It depends on the size of your development effort. Multiple teams working in parallel won't be able to work effectively all on the same code (trunk). If you have just a small group of people working and your main concern is cutting a branch so you can continue to work while going back to the branch for making bug-fixes to the current production code that would work. This is a trivial use of branching and not too burdensome.
If you have a lots of parallel development you'll want to have branches for each of the efforts but that'll also require more discipline: Making sure your branches are tested and ready to merge back. Scheduling merges so two groups aren't trying to merge at the same time etc.
Some branches are under development for so long that you have to permit merges from the trunk to the branch in order to reduce the number of surprises when finally merging back to the trunk.
You will have to experiment if you have a large group of developers and get a feel for what works in your situation. Here is a page from Microsoft that may be somewhat useful: <http://msdn.microsoft.com/en-us/library/aa730834(VS.80).aspx> |
Where do you live that you can get free bear!?
Subversion is complicated to set up -- if you have no experience with version control at all, I'd recommend using a distributed VCS because they don't require any server configuration. [Bazaar in five minutes](http://doc.bazaar-vcs.org/bzr.dev/en/mini-tutorial/index.html) is a good start.
For Subversion, you'll want to set up either `svnserve` or the `mod_dav_svn` Apache module. I prefer the Apache module, because it gives you basic web-based repository browsing in the bargain. You'll also need to create and configure a repository -- see the [SVN red book Chapter 5](http://svnbook.red-bean.com/en/1.4/svn.reposadmin.html) for more information on repository administration. Then read [chapter 2](http://svnbook.red-bean.com/en/1.4/svn.tour.html) to learn how to use Subversion itself. |
Eric Sink has an [excellent series][1] on source code control aimed at beginners. For Subversion specifics, including setting up and administering a server, the [Subversion book][2] is a great resource, and includes a section with examples of a typical session with Subversion (checkout, commit, merging and updating basics).
**Update:** I forgot to mention that for beginners, I'd also recommend messing around in a graphical client, which removes the command-line hassle from the learning experience. [RapidSVN][3] is a reasonable cross-platform client. You'll also find that common IDEs either come with Subversion support, or have plugins which can be installed, which allow most version control operations to be performed within that environment.
[1]: http://www.ericsink.com/scm/source_control.html
[2]: http://svnbook.red-bean.com/
[3]: http://rapidsvn.tigris.org/ |
Eric Sink has an [excellent series][1] on source code control aimed at beginners. For Subversion specifics, including setting up and administering a server, the [Subversion book][2] is a great resource, and includes a section with examples of a typical session with Subversion (checkout, commit, merging and updating basics).
**Update:** I forgot to mention that for beginners, I'd also recommend messing around in a graphical client, which removes the command-line hassle from the learning experience. [RapidSVN][3] is a reasonable cross-platform client. You'll also find that common IDEs either come with Subversion support, or have plugins which can be installed, which allow most version control operations to be performed within that environment.
**@John Millikin:** While setting up a Subversion server can be complicated, depending on one's general admin experience, don't forget that you don't need to do that just to mess about with a repository and get to grips with the basics - the client can interact with a repository in the local filesystem.
[1]: http://www.ericsink.com/scm/source_control.html
[2]: http://svnbook.red-bean.com/
[3]: http://rapidsvn.tigris.org/ |
What I would do for the particular case is:
1. Define the <body> tag in the masterpage as:
<body runat="server" id="masterpageBody">
2. In your content aspx page, register the MasterPage with the register:
<% MasterPageFile="..." %>
3. In the Content Page, you can now simply use `MasterPage.FindControl` and have access to all the properties of the control. Now, you can change whatever properties/style that you like! |
What I would do for the particular case is:
1. Define the body as a server side control `<body runat="server" id="masterpageBody>`
2. In your content aspx page, register the MasterPage with the register:
<% MasterPageFile="..." %>
3. In the Content Page, you can now simply use `MasterPage.FindControl` and have access to all the properties of the control. Now, you can change whatever properties/style that you like! |
What I would do for the particular case is:
i. Define the body as a server side control
`<body runat="server" id="masterpageBody>`
ii. In your content aspx page, register the MasterPage with the register:
`<% MasterPageFile="..." %>`
iii. In the Content Page, you can now simply use `MasterPage.FindControl()` and have access to all the properties of the control. Now, you can change whatever properties/style that you like! |
What I would do for the particular case is:
i. Define the body as a server side control
<body runat="server" id="masterpageBody">
ii. In your content aspx page, register the MasterPage with the register:
<% MasterPageFile="..." %>
iii. In the Content Page, you can now simply use
Master.FindControl("masterpageBody")
and have access to the control. Now, you can change whatever properties/style that you like! |
Personally I use [MediaWiki][1] for this purpose. I've tried a number of other free and paid wikis (including [Confluence][2]) and have always been impressed with MediaWiki's simplicity and ease of use.
I have MediaWiki installed on a thumb drive (using [XAMPP][3] from [PortableApps][4]), which I use mostly as a personal knowledge base/code snippet repository. I can take it with me wherever I go, and view/edit it from any computer I'm using.
[1]: http://www.mediawiki.org/wiki/MediaWiki
[2]: http://www.atlassian.com/software/confluence/
[3]: http://portableapps.com/apps/development/xampp
[4]: http://portableapps.com/ |
I am not aware of any plugin that does it natively, especially since Mono users seem to prefer [MonoDevelop][1].
However, it should be possible to use Cygwin and a custom MSBuild Task or Batch file in order to achieve that by using the native .deb creation tools.
[1]: http://www.monodevelop.com/Main_Page |
[Resharper][1] does this with the Ctrl-N keyword. Unfortunately it doesn't come for free.
Visual Studio doesn't have anything like this feature beyond Find.
[1]: http://www.jetbrains.com/resharper/ |
I think the "wisdom of crowds" work here. How did most people learn how to program? Many claim that they did so by copying programs of others, usually games they wanted to play in BASIC.
Maybe that route will work with him too? |
Answering the original question:
- ASCII is bad : I had to squint to find "WOW". Is this even correct? It could be "VVOVV" or whatever;
- Very simple arithmetic is good. Blind people will be able to answer. (But as Jarod said, beware of operator precedence.) I gather someone could write a parser, but it makes the spamming more costly.
- Trivia is OK, but you'll have to write each of them :-(
I've seen pictures of animals [what is it?]. Votes for comics use a picture of a character with their name written somewhere in the image [type in name]. Impossible to parse, not ok for blind people.
You could have an audio fallback reading alphanumerics (the same letters and numbers you have in the captcha).
Final line of defense: make spam easy to report (one click) and easy to delete (one recap screen to check it's a spam account, with the last ten messages displayed, one click to delete account). This is still time-expensive, though. |
OK, here's a solution:
preg_match(
'/(?x)^J[0-9]{7}:\s+
(.*?) #Extract the Transaction Start Date msg
\s+J[0-9]{7}:\s+Project\sname:\s+
(.*?) #Extract the Project Name
\s+J[0-9]{7}:\s+Job\sname:\s+
(.*?) #Extract the Job Name
\s+J[0-9]{7}:\s+/'
, $this->getResultVar('FullMessage'), $atmp);
The key is **(?x)** at the beginning which makes whitespace insignificant and allows comments.
It's also important that there's no whitespace between the starting and ending quotes and the start & end of the regex.
My first attempt like this gave errors:
preg_match('
/(?x)^J[0-9]{7}:\s+
(.*?) #Extract the Transaction Start Date msg
\s+J[0-9]{7}:\s+Project\sname:\s+
(.*?) #Extract the Project Name
\s+J[0-9]{7}:\s+Job\sname:\s+
(.*?) #Extract the Job Name
\s+J[0-9]{7}:\s+/
', $this->getResultVar('FullMessage'), $atmp);
What Konrad said also works and feels a little easier than sticking **(?x)** at the beginning. |
OK, here's a solution:
preg_match(
'/(?x)^J[0-9]{7}:\s+
(.*?) #Extract the Transaction Start Date msg
\s+J[0-9]{7}:\s+Project\sname:\s+
(.*?) #Extract the Project Name
\s+J[0-9]{7}:\s+Job\sname:\s+
(.*?) #Extract the Job Name
\s+J[0-9]{7}:\s+/'
, $this->getResultVar('FullMessage'), $atmp);
The key is **(?x)** at the beginning which makes whitespace insignificant and allows comments.
It's also important that there's no whitespace between the starting and ending quotes and the start & end of the regex.
My first attempt like this gave errors:
preg_match('
/(?x)^J[0-9]{7}:\s+
(.*?) #Extract the Transaction Start Date msg
\s+J[0-9]{7}:\s+Project\sname:\s+
(.*?) #Extract the Project Name
\s+J[0-9]{7}:\s+Job\sname:\s+
(.*?) #Extract the Job Name
\s+J[0-9]{7}:\s+/
', $this->getResultVar('FullMessage'), $atmp);
What [Konrad said](http://stackoverflow.com/questions/22552/passing-a-commented-multi-line-freespace-regex-to-pregmatch#22572) also works and feels a little easier than sticking **(?x)** at the beginning. |
What is the best architecture to bridge to XMPP? |
|architecture|xmpp|bridge| |
If I have a separate system with its own concept of users and presence, what is the most appropriate architecture for creating a bridge to an XMPP server network? As far as I can tell there are three primary ways:
1. Act as a server. This creates one touchpoint, but I fear it has implications for compatibility, and potentially creates complexity in my system for emulating a server.
2. Act as a clients. This seems to imply that I need one connection per user in my system, which just isn't going to scale well.
3. I've heard of an XMPP gateway protocol, but it's unclear if this is any better than the client solution. I also can't tell if this is standard or not.
Any suggestions or tradeoffs would be appreciated. For example, would any of these solutions require running code inside the target XMPP server (not likely something I can do). |
While nifty, the revision keyword trick only updates the file when it's changed in that revision - if you don't change the file, then it will continue to reflect the old revision.
If you want the software to always reflect the overall revision number, then you'll have to delve into the [relevant SVN entries file][1] and extract it, which isn't too difficult (it's an XML file).
Wikipedia does this on [their version page][2] to indicate the revision of the software that's running live; [the code is here][3] - look for the **getSvnRevision()** method.
[1]: http://svnbook.red-bean.com/en/1.1/ch08s03.html
[2]: http://en.wikipedia.org/wiki/Special:Version
[3]: http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/includes/specials/SpecialVersion.php |
You could add the DB2 database as a linked server in sql server and just join the two tables in a view/sproc in sql. I've done it, it's not hard and you'll get data in realtime. |
Another benefit of storing the images in the file system is that you don't have to do anything special to have the client cache them...
...unless of course the image isn't accessible via the document root (e.g. authentication barrier), in which case you'll need to check the cache-control headers your code is sending. |
http://blog.clickablebliss.com/2006/04/26/introduction-to-subversion-screencast/ explains how to use SVN very well. |
The solution really depends on what your needs are, and can be pretty complex (Thanks fully to Windows Vista). This is probably going to be beyond your need, but this will help others that find this page via search.
1. If you do not need the process to run with a GUI and you do not require elevation
2. If the user you want to run as is already logged into a session
2. If you need to run the process with a GUI, and the user may, or may not be logged in
3. If you need to run the process with elevation
**Regarding 1:**
In windows Vista there exists something called session 0 isolation. All services run as session 0 and you are not supposed to have a GUI in session 0. The first logged on user is logged into session 1. In previous versions of windows (pre Vista), the first logged on user was also ran fully in session 0.
You can run several different processes with different usernames in the same session. You can find a good document about session 0 isolation [here][1].
Since we're dealing with option 1), you don't need a GUI. Therefore you can start your process in session 0.
You'll want a call sequence something like this:
LogonUser, ExpandEnvironmentStringsForUser, GetLogonSID, LoadUserProfile, CreateEnvironmentBlock, CreateProcessAsUser.
Example code for this can be found via any search engine, or via [Google code search][2]
**Regarding 2:** If the user you'd like to run the process as is already logged in, you can simply use: WTSEnumerateSessions, and WTSQuerySessionInformation to get the session ID, and then WTSQueryUserToken to get the user token. From there you can just use the user token in the CreateProcessAsUser Win32 API.
This is a great method because you don't even need to login as the user nor know the user's username/password. I believe this is only possible via a service though running as local system account.
You can get the current session via WTSGetActiveConsoleSessionId.
**Regarding 3:**
You would follow the same steps as #1, but in addition you would use the STARTUPINFO's lpDesktop field. Set this to winsta0\\Default. You will also need to try to use the OpenDesktop Win32 API and if this fails you can CreateDesktop. Before using the station and desktop handles you should use SetSecurityInfo on each of them with SE_WINDOW_OBJECT, and GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION.
If the user in question later tries to login, he will actually see the running process.
**Regarding 4:**
This can be done as well, but it requires you to already be running an elevated process. A service running as local system account does run as elevated. I could also only get it to work by having an authenticode signed process that I wanted to start. The process you want to start also must have a manifest file associated with it with the requestedExecutionLevel level="requireAdministrator"
Other notes:
- You can set a token's session via SetTokenInformation and TokenSessionId
- You cannot change the session ID of an already running process.
- This whole process would be drastically more simple if Vista was not in the equation.
[1]: http://www.microsoft.com/whdc/system/vista/services.mspx
[2]: http://www.google.com/codesearch |
The best explanation of how the garbage collector works is in Jeff Richters [CLR via C#][1] book, (Ch. 20). Reading this gives a great grounding for understanding how objects persist.
One of the most common causes of rooting objects accidentally is by hooking up events outisde a class. If you hook up an external event
e.g.
SomeExternalClass.Changed += new EventHandler(HandleIt);
and forget to unhook to it when you dispose, then SomeExternalClass has a ref to your class.
As mentioned above, the [SciTech memory profiler][2] is excellent at showing you roots of objects you suspect are leaking.
But there is also a very quick way to check a particular type is just use WnDBG (you can even use this in the VS.NET immediate window while attached):
.loadby sos mscorwks
!dumpheap -stat -type <TypeName>
Now do something that you think will dispose the objects of that type (e.g. close a window). It's handy here to have a debug button somewhere that will run System.GC.Collect() a couple of times.
Then run !dumpheap -stat -type <TypeName> again. If the number didn't go down, or didn't go down as much as you expect, then you have a basis for further investigation.
(I got this tip from a seminar given by [Ingo Rammer][3]).
[1]: http://www.microsoft.com/MSPress/books/6522.aspx
[2]: http://memprofiler.com
[3]: http://www.thinktecture.com/staff/ingo |
The MAC address is as unique as a serial number printed on a manual/sticker.
Microsoft does hashing to prevent MAC address spoofing, and to allow a bit more privacy.
With the only MAC approach, you can easily match a device to a customer by only being in the same subnet. The hash prevents that, by being opaque to what criteria are used and no way to reverse engineer individual parts.
(see password hashing) |
The following adds -1 years to the current date:
SELECT ... From ... WHERE date > DATEADD(year,-1,GETDATE()) |
This [MSDN article][1] has some example Date strings that are parse-able is that what you're looking for?
string dateString = "5/1/2008 8:30:52 AM";
DateTime date1 = DateTime.Parse(dateString, CultureInfo.InvariantCulture);
[1]: http://msdn.microsoft.com/en-us/library/ey1cdcx8.aspx |
Look up dateadd in BOL
dateadd(yy,-1,getdate()) |
Stripes is a great framework. We converted a major project from a home grown framework to stripes and it took less than one week.
The book referenced above is a great resources, as is the mailing list.
There's also an active irc channel \#stripes on freenode.
It's a very powerful framework that doesn't get in your way.
|
Original form (The Right Hungarian Notation :) ) where prefix means type (i.e. length, quantity) of value stored by variable is OK, but not necessary in all type of applications.
The popular form (The Wrong Hungarian Notation) where prefix means type (String, int) is useless in most of modern programming languages.
Especially with meaningless names like strA. I can't understand we people use meaningless names with long prefixes which gives nothing. |
Ethernet MAC address as activation code for an appliance? |
|ethernet|drm|activation|licensing| |
This is much more concise:
where
datediff(day, date1, date2) = 0 |
In our scenario, we have a separate file server that both of our front end app servers write to, that way you either server has access to the same sets of files. |
While the question touches on a couple of very debatable issues (OOP, User authentication) I'll skip by those and second Konrad's comment about __autoload. Anyone who knows C/C++ knows how much of a pain including files can be. With autoload, a PHP5 addition, if you choose to use OOP (which I do almost exclusively) you only need use some standard file naming convention and (I would recommend) restricting a single class per file and PHP will do the rest for you. Cleans up the code and you no longer have to worry about remembering to remove includes that are no longer necessary (one of the many problems with includes). |
How will the user upload the photos? If you are writing an ASP page to accept the uploaded files then only the user that IIS runs as will need write permission to the folder, since IIS will be doing the file I/O. Your ASP page should check the file size and have some form of authentication to prevent hackers from filling your hard drive.
If you are setting up an FTP server or some other file transfer method, then the answer will be specific to the method you choose. |
The best solution for this is usually to provide the shared area on some form of SAN, which will be accessible from all servers and contain failover.
This also has the benefit that you don't have to provide sticky load balancing, the upload can be handled by one server, and the edit by another. |
ASP.NET Tutorials |
|asp.net|asp.net-mvc| |
can you recommend some good ASP.NET tutorials or a good book?
Should I jump right to ASP.NET MVC/html/javascript or learn web forms first?
Thanks |
this will remove time component from a date for you:
select dateadd(d, datediff(d, 0, current_timestamp), 0) |
It can be done without RegExp as
function IsNumeric(data){
return parseFloat(data)==data;
}
|
MVC www.asp.net/mvc great videos
Asp.net www.asp.net
|
Virtual Mac? |
|macos|iphone|virtualization| |
I’m thinking about trying some development for the iPhone, is it possible to install Leopard inside VMWare? I already have a pretty high spec PC with a comfy setup that I’d like to use, or do I need to buy a real Mac? |
Legally, you need to buy a Mac. It is "possible" to run (at least Tiger) in VMWare -- the experience is not optimal, but you can do it. It's also possible to run OS X on PC hardware; however, it's an exercise in illegal software and hacks. |
If you're going to use ASP.NET MVC, then go straight to it. But it's a fairly new technology, not even in beta yet, so have that in mind. However, the application model is totally different compared to ASP.NET, so it is not in fact a replacement. For tutorials, you can surely check out <http://www.asp.net> and <http://www.asp.net/mvc> - there's tons of information there. |
How can I reformat XAML efficiently? |
|.net|wpf|formatting|xaml| |
Visual Studio 2008's XAML editor (SP1) cannot reformat the XML into a consistent style.
Which tools can I use to get a nicely formatted XAML file? Studio integration preferred. |
How can I reformat XAML nicely in VS 2008? |
How does google make make those awesome PDF reports in Analytics and when you print a Google Doc etc? |
|pdf|google|pdf-generation| |
When you print from Google Docs (using the "print" link, not File/Print) you end up printing a nicely formated PDF file instead of relying on the print engine of the browser. Same is true for some of the reports in Google Analytics . . . the printed reports as PDF's are beautiful. How do they do that? I can't imagine they use something like Adobe Acrobat to facilitate it but maybe they do. I've seen some expensive HTML to PDF converters online from time to time but have never tired it. Any thoughts? |
You should be using `IllegalArgumentException` (IAE), not `NullPointerException` (NPE) for the following reasons:
First, the [NPE JavaDoc][1] explicitly lists the cases where NPE is appropriate. Notice that all of them are thrown <i>by the runtime</i> when `null` is used inappropriately. In contrast, the [IAE JavaDo][2]c couldn't be more clear: "Thrown to indicate that a method has been passed an illegal or inappropriate argument." Yup, that's you!
Second, when you see an NPE in a stack trace, what do you assume? Probably that someone dereferenced a null. When you see IAE, you assume the caller of the method at the top of the stack passed in an illegal value. Again, the latter assumption is true, the former is misleading.
Third, since IAE is clearly designed for validating parameters, you have to assume it as the default choice of exception, so why would you choose NPE instead? Certainly not for different behavior -- do you really expect calling code to catch NPE's separately from IAE and do something different as a result? Are you trying to communicate a more specific error message? But you can do that in the exception message text anyway, as you should for all other incorrect parameters.
Fourth, all other incorrect parameter data will be IAE, so why not be consistent? Why is it that an illegal `null` is so special that it deserves a separate exception from all other types of illegal arguments?
Finally, I accept the argument given by other answers that parts of the Java API use NPE in this manner. However, the Java API is inconsistent with everything from exception types to naming conventions, so I think just blindly copying (your favorite part) of the Java API isn't a good enough argument to trump these other considerations.
[1]: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/NullPointerException.html
[2]: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/IllegalArgumentException.html |
iTextSharp and iText are opensource and free PDF generation libraries for .NET and Java respectively.
I've used them to generate report PDF's before and was quite happy with the results.
http://itextsharp.sourceforge.net/
http://www.lowagie.com/iText/
|
I used to do that with FTP on windows (create a file of commands and shell out FTP.exe)
Xetius I tried to upvote yours and accept your answer too and I received an warning that I needed 25 rep to do that. Sorry. |
Well, one way is to compile it as x64 with VS2008
This runs as you would expect:
int normalInt = 5;
unsigned long long int num=285212672l;
printf(
"My number is %d bytes wide and its value is %ul.
A normal number is %d \n",
sizeof(num),
num,
normalInt);
return 0;
Output
My number is 8 bytes wide and its value is 285212672l. A normal number is 5
I can confirm that it fails using the 32 bit compiler, it is probably a bug in the 32 bit version of the standard library and how it deals with __int64 (which is what long long int really is) |
Well, one way is to compile it as x64 with VS2008
This runs as you would expect:
int normalInt = 5;
unsigned long long int num=285212672l;
printf(
"My number is %d bytes wide and its value is %ul.
A normal number is %d \n",
sizeof(num),
num,
normalInt);
For 32 bit code, we need to use the correct __int64 format specifier %I64u. So it becomes.
int normalInt = 5;
unsigned __int64 num=2852126721;
printf(
"My number is %d bytes wide and its value is %I64u.
A normal number is %d",
sizeof(num),
num, normalInt);
This code works for both 32 and 64 bit VS compiler. |
Well, one way is to compile it as x64 with VS2008
This runs as you would expect:
int normalInt = 5;
unsigned long long int num=2852126721;
printf(
"My number is %d bytes wide and its value is %ul.
A normal number is %d \n",
sizeof(num),
num,
normalInt);
For 32 bit code, we need to use the correct __int64 format specifier %I64u. So it becomes.
int normalInt = 5;
unsigned __int64 num=2852126721;
printf(
"My number is %d bytes wide and its value is %I64u.
A normal number is %d",
sizeof(num),
num, normalInt);
This code works for both 32 and 64 bit VS compiler. |
Well, one way is to compile it as x64 with VS2008
This runs as you would expect:
int normalInt = 5;
unsigned long long int num=285212672;
printf(
"My number is %d bytes wide and its value is %ul.
A normal number is %d \n",
sizeof(num),
num,
normalInt);
For 32 bit code, we need to use the correct __int64 format specifier %I64u. So it becomes.
int normalInt = 5;
unsigned __int64 num=285212672;
printf(
"My number is %d bytes wide and its value is %I64u.
A normal number is %d",
sizeof(num),
num, normalInt);
This code works for both 32 and 64 bit VS compiler. |
SQL Server 2008 has a new *date* datetype and this simplifies this problem to:
SELECT CAST(CAST(GETDATE() AS date) AS datetime) |
im not sure there's any other way than:
> $result = [ $result ] if ref($result) ne 'ARRAY';
> foreach ..... |
If you want to teach the basics of programming, without being language specific, there is an application called [Scratch][1] that was created in MIT. It's designed to help people develop programming skills. As users create Scratch projects, they learn to create conditions, loops, etc. There is a also a community of scratch projects, form which projects can be downloaded - that way you can explore other people's programs and see how they were built.
[1]: http://scratch.mit.edu/ |
Let's suppose you deploy a network-attached appliances (small form factor PCs) in the field. You want to allow these to call home after being powered on, then be identified and activated by end users.
Our current plan involves the user entering the MAC address into an activation page on our web site. Later our software (running on the box) will read the address from the interface and transmit this in a "call home" packet. If it matches, the server response with customer information and the box is activated.
We like this approach because it's easy to access, and usually printed on external labels (FCC requirement?).
Any problems to watch out for? (The hardware in use is small form factor so all NICs, etc are embedded and would be very hard to change. Customers don't normally have direct acccess to the OS in any way).
I know Microsoft does some crazy fuzzy-hashing function for Windows activation using PCI device IDs, memory size, etc. But that seems overkill for our needs. |
|licensing|drm|activation|ethernet| |
Let's suppose you deploy a network-attached appliances (small form factor PCs) in the field. You want to allow these to call home after being powered on, then be identified and activated by end users.
Our current plan involves the user entering the MAC address into an activation page on our web site. Later our software (running on the box) will read the address from the interface and transmit this in a "call home" packet. If it matches, the server response with customer information and the box is activated.
We like this approach because it's easy to access, and usually printed on external labels (FCC requirement?).
Any problems to watch out for? (The hardware in use is small form factor so all NICs, etc are embedded and would be very hard to change. Customers don't normally have direct acccess to the OS in any way).
I know Microsoft does some crazy fuzzy-hashing function for Windows activation using PCI device IDs, memory size, etc. But that seems overkill for our needs.
--
@Neall Basically, calling into our server, for purposes of this discussion you could call us the manufacturer.
Neall is correct, we're just using the address as a constant. We will read it and transmit it within another packet (let's say HTTP POST), not depending on getting it somehow from Ethernet frames. |
In addition to the other answers:
The C++ language actually has the `auto` keyword to explicitly declare the storage class of an object. Of course, it's completely needless because this is the implied storage class for local variables and cannot be used anywhere. The opposite of `auto` is `static` (both locally and globall).
The following two declarations are equivalent:
int main() {
int a;
auto int b;
}
Because the keyword is utterly useless, it will actually be recycled in the next C++ standard (“C++0x”) and gets a new meaning, namely, it lets the compiler infer the variable type from its initialization (like `var` in C#):
auto a = std::max(1.0, 4.0); // `a` now has type double. |
WPF setting a MenuItem.Icon in code |
|wpf| |
I have an images folder with a png in it. I would like to set a MenuItem's icon to that png. How do I write this in procedural code? |
I used to get these all the time on Apache1/fastcgi. I think it's caused by fastcgi hanging up before Ruby is done.
Switching to mongrel is a good first step, but there's more to do. It's a bad idea to cull from web services on live pages, particularly from Rails. Rails is not thread-safe. The number of concurrent connections you can support equals the number of mongrels (or Passenger processes) in your cluster.
If you have one mongrel and someone accesses a page that calls a web service that takes 10 seconds to time out, every request to your website will timeout during that time. Most of the load balancers just cycle through your mongrels blindly, so if you have two mongrels, every other request will timeout.
Anything that can be unpredictably slow needs to happen in a job queue. The first hit to /slow/action adds the job to the queue, and /slow/action keeps on refreshing via page refreshes or queries via ajax until the job is finished, and then you get your results from the job queue. There are a few job queues for Rails nowadays, but the oldest and probably most widely used one is [BackgroundRB][1].
Another alternative, depending on the nature of your app, is to cull the service every N minutes via cron, cache the data locally, and have your live page read from the cache.
[1]: http://backgroundrb.rubyforge.org/ |
Chris,
They're different beasts. WHS backup is pretty much automatic and uses deltas - Vista's is manual and I don't believe offers incremental updates.
While your solution (Vista + network copy) would preserve your data it has two problems I an see;
1. Your documents will only have the latest revision. If you find something was corrupted a month ago it could be very awkward to recover it. Vista's shadow copies may help though.
2. As soon as you install a program/patch/config your Vista backup is out of date and needs remade, or these repeated if you reinstall.
These might not be dealbreakers and indeed Vista's backup is pretty decent, it's just nowhere near as good as WHS. In my opinion WHS leaves almost everything else standing, you can be sure this tech will be in the "big brother" server versions shortly.
|
"Multi-agent computing" in simple terms |
|multi-agent| |
I've encountered the term "multi-agent computing" as of late, and I don't quite get what it is. I've read a book about it, but that didn't answer the fundamental question of what an agent was.
Does someone out there have a pointer to some reference which is clear and concise and answers the question without a load of bullshit/marketing speak? I want to know if this is something I should familiarise myself, or whether it's some crap I can probably ignore, because I honestly can't tell. |
On a two-column page, how can I grow the left div to the same height of the right div using CSS or Javascript? |
|javascript|html|css| |
I'm trying to make a two-column page using a div-based layout (no tables please!). Problem is, I can't grow the left div to match the height of the right one. My right div typically has a lot of content.
Here's is a paired down example of my template to illustrate the problem.
<div style="float:left; width: 150px; border: 1px solid;">
<ul>
<li>nav1</li>
<li>nav2</li>
<li>nav3</li>
<li>nav4</li>
</ul>
</div>
<div style="float:left; width: 250px">
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
....
</div>
![alt text][1]
[1]: http://involution.com/images/divlayout.png |
I am not sure what you are looking for this application to accomplish. If it is just to try some code without having to create a project and all the overhead to just test an idea, then [SnippetCompiler][1] could be a good fit.
I just wanted to give you another option.
[1]: http://www.sliver.com/dotnet/SnippetCompiler/ |
Have you tried CTRL K, D?
|
The shunting yard algorithm is the right tool for this. Wikipedia is really confusing about this, but basically the algorithm works like this:
Say, you want to evaluate 1 + 2 * 3 + 4. Intuitively, you "know" you have to do the 2 * 3 first, but how do you get this result? The key is to realize that when you're scanning the string from left to right, you will evaluate an operator when the operator that **follows** it has a lower (or equal to) precedence. In the context of the example, here's what you want to do:
1. Look at: 1 + 2, don't do anything.
2. Now look at 1 + 2 * 3, still don't do anything.
3. Now look at 1 + 2 * 3 + 4, now you know that 2 * 3 has to to be evaluated because the next operator has lower precedence.
How do you implement this?
You want to have two stacks, one for numbers, and another for operators. You push numbers onto the stack all the time. You compare each new operator with the one at the top of the stack, if the one on top of the stack has higher priority, you pop it off the operator stack, pop the operands off the number stack, apply the operator and push the result onto the number stack. Now you repeat the comparison with the top of stack operator.
Coming back to the example, it works like this:
N = []
Ops = []
* Read 1. N = [1], Ops = []
* Read +. N = [1], Ops = [+]
* Read 2. N = [1 2], Ops = [+]
* Read `*`. N = [1 2], Ops = [+ *]
* Read 3. N = [1 2 3], Ops = [+ *]
* Read +. N = [1 2 3], Ops = [+ *]
+ Pop 3, 2 and execute 2`*`3, and push result onto N. N = [1 6], Ops = [+]
+ `+` is left associative, so you want to pop 1, 6 off as well and execute the +. N = [7], Ops = [].
+ Finally push the [+] onto the operator stack. N = [7], Ops = [+].
* Read 4. N = [7 4]. Ops = [+].
* You're run out off input, so you want to empty the stacks now. Upon which you will get the result 11.
There, that's not so difficult, isn't it? And it makes no invocations to any grammars or parser generators. |
How do you determine how far to normalize a database? |
|database-design|language-agnostic| |
When creating a database structure, what are good guidelines to follow or good ways to determine how far a database should be normalized? Should you create an un-normalized database and split it apart as the project progresses? Should you create it fully normalized and combine tables as needed for performance? |
|language-agnostic|database-design|normalizing| |
Make a Java Swing application. That will not require Internet and it runs on Mac, Windows, and Linux. You can write to the file system for the lock. [System.getProperty("user.home")][1] gives you the home equivalent for the platform. You might have to include a jre in your CD.
[1]: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html |
When you do crontab -e, try this:
59 23 * * * /usr/sbin/myscript > /dev/null
That means: At 59 Minutes and 23 Hours on every day (*) on every month on every weekday, execute myscript.
See **man crontab** for some more info and examples. |
I used to teach programming and your brother has one main advantage over most of my students he wants to learn :)
If you decide to go with C [a friend has a site][1] that has the sort of programs those of use from older generations remember as basic type-ins. The more complex of them use ncurses which sort of negates their use as a teaching aid somewhat but some of them are tiny little things and you can learn loads without being taught to.
Personally I think Python and Ruby would make great first languages.
[1]: http://cymonsgames.retroremakes.com/ |
I used to teach programming and your brother has one main advantage over most of my students he wants to learn :)
If you decide to go with C [a friend has a site][1] that has the sort of programs those of use from older generations remember as basic type-ins. The more complex of them use ncurses which sort of negates their use as a teaching aid somewhat but some of them are tiny little things and you can learn loads without being taught to.
Personally I think Python and Ruby would make great first languages.
EDIT:
[list of beginner programming assignments][2] appeared overnight might be just what you are looking for.
[1]: http://cymonsgames.retroremakes.com/
[2]: http://cymonsgames.retroremakes.com/beginners-programming-homework/ |
'Best' Diff Algorithm |
|vb.net|diff| |
I need to implement a Diff algorithm in VB.NET to find the changes between two different versions of a piece of text. I've had a scout around the web and have found a couple of different algorithms.
Does anybody here know of a 'best' algorithm that I could implement?
Thanks,
- Chris |