instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>Do you use ILMerge? Do you use ILMerge to merge multiple assemblies to ease deployment of dll's? Have you found problems with deployment/versioning in production after ILMerging assemblies together?</p> <p>I'm looking for some advice in regards to using ILMerge to reduce deployment friction, if that is even possible.</p>
<p>I use ILMerge for almost all of my different applications. I have it integrated right into the release build process so what I end up with is one exe per application with no extra dll's. </p> <p>You can't ILMerge any C++ assemblies that have native code. You also can't ILMerge any assemblies that contain XAML for WPF (at least I haven't had any success with that). It complains at runtime that the resources cannot be located.</p> <p>I did write a wrapper executable for ILMerge where I pass in the startup exe name for the project I want to merge, and an output exe name, and then it reflects the dependent assemblies and calls ILMerge with the appropriate command line parameters. It is much easier now when I add new assemblies to the project, I don't have to remember to update the build script.</p>
<p>It seems to me like the #1 ILMerge Best Practice is Don't Use ILMerge. Instead, use <a href="http://www.red-gate.com/products/smartassembly/index.htm" rel="nofollow noreferrer">SmartAssembly</a>. One reason for this is that the #2 ILMerge Best Practice is to always run PEVerify after you do an ILMerge, because ILMerge does not guarantee it will correctly merge assemblies into a valid executable.</p> <p>Other ILMerge disadvantages:</p> <ul> <li>when merging, it strips XML Comments (if I cared about this, I would use an obfuscation tool)</li> <li>it doesn't correctly handle creating a corresponding .pdb file</li> </ul> <p>Another tool worth paying attention to is Mono.Cecil and the Mono.Linker [2] tool.</p> <p>[2]: http:// www.mono-project.com/Linker</p>
3,080
<p>For example, will SQL Server warn you or does it just die?</p>
<p>SQL Server 2005 will throw the following error when you overflow the IDENTITY column. </p> <pre><code>Server: Msg 8115, Level 16, State 1, Line 1 Arithmetic overflow error converting IDENTITY to data type int. Arithmetic overflow occurred. </code></pre> <p>Your identity column need not be constrained to an INT and indeed can be set to BIGINT if you suspect that INT will not be large enough.</p> <p>INT (32-bit signed) will go up to 2,147,483,647 and BIGINT (64-bit signed) to 9,223,372,036,854,775,807 (that's 9 quintillion, enough for 1.3 billion id's per person on the planet).</p>
<p>It would likely do both. </p>
49,759
<p>I have started printing with PETG so I can create objects that won't deform if I leave them in my car.</p> <p>My first prints look good, but have strings of material coming off the print in places.</p> <p>What should I try to prevent that? </p> <p>I haven't had this problem with PLA. </p>
<p>I've had similar experiences switching from PLA to PETG, and haven't gotten it fully figured out yet.</p> <p>From what I know so far, to reduce petg strings:</p> <ul> <li>Increase retraction</li> <li>Lower temperature</li> </ul>
<p>I've had similar experiences switching from PLA to PETG, and haven't gotten it fully figured out yet.</p> <p>From what I know so far, to reduce petg strings:</p> <ul> <li>Increase retraction</li> <li>Lower temperature</li> </ul>
671
<p>Why are flat text files the state of the art for representing source code?</p> <p>Sure - the preprocessor and compiler need to see a flat file representation of the file, but that's easily created.</p> <p>It seems to me that some form of XML or binary data could represent lots of ideas that are very difficult to track, otherwise.</p> <p>For instance, you could embed UML diagrams right into your code. They could be generated semi-automatically, and annotated by the developers to highlight important aspects of the design. Interaction diagrams in particular. Heck, embedding any user drawing might make things more clear.</p> <p>Another idea is to embed comments from code reviews right into the code.</p> <p>There could be all sorts of aids to make merging multiple branches easier.</p> <p>Something I'm passionate about is not just tracking code coverage, but also looking at the parts of code covered by an automated test. The hard part is keeping track of that code, even as the source is modified. For instance, moving a function from one file to another, etc. This can be done with GUIDs, but they're rather intrusive to embed right in the text file. In a rich file format, they could be automatic and unobtrusive.</p> <p>So why are there no IDEs (to my knowledge, anyway) which allow you to work with code in this way?</p> <p><strong>EDIT:</strong> On October 7th, 2009.</p> <p>Most of you got very hung up on the word "binary" in my question. I retract it. Picture XML, very minimally marking up your code. The instant before you hand it to your normal preprocessor or compiler, you strip out all of the XML markup, and pass on just the source code. In this form, you could still do all of the normal things to the file: diff, merge, edit, work with in a simple and minimal editor, feed them into thousands of tools. Yes, the diff, merge, and edit, directly with the minimal XML markup, does get a tad more complicated. But I think the value could be enormous.</p> <p>If an IDE existed which respected all of the XML, you could add so much more than what we can do today.</p> <p>For instance, your DOxygen comments could actually <em>look</em> like the final DOxygen output.</p> <p>When someone wanted to do a code review, like Code Collaborator, they could mark up the source code, in place.</p> <p>The XML could even be hidden behind comments.</p> <pre><code>// &lt;comment author="mcruikshank" date="2009-10-07"&gt; // Please refactor to Delegate. // &lt;/comment&gt; </code></pre> <p>And then if you want to use vi or emacs, you can just skip over the comments.</p> <p>If I want to use a state-of-the-art editor, I can see that in about a dozen different helpful ways.</p> <p>So, that's my rough idea. It's not "building blocks" of pictures that you drag on the screen... I'm not that nuts. :)</p>
<ul> <li>you can diff them</li> <li>you can merge them</li> <li>anyone can edit them</li> <li>they are simple and easy to deal with</li> <li>they are universally accessible to thousands of tools</li> </ul>
<p>The code of your program define the structure that would be created with xml or the binary format. Your programming language is a more direct representation of your program's structure than an XML or Binary representation would be. Have you ever noticed how Word misbehaves on you as you give structure to your document. WordPerfect at least would 'reveal codes' to allow you to see what lay beneath your document. Flat files do the same thing for your program. </p>
19,419
<p>I am currently using...</p> <pre><code>select Table_Name, Column_name, data_type, is_Nullable from information_Schema.Columns </code></pre> <p>...to determine information about columns in a given database for the purposes of generating a DataAccess Layer.</p> <p><strong>From where can I retrieve information about if these columns are participants in the primary key of their table?</strong></p>
<p>Here is one way (replace 'keycol' with the column name you are searching for):</p> <pre><code>SELECT K.TABLE_NAME , K.COLUMN_NAME , K.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS C JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS K ON C.TABLE_NAME = K.TABLE_NAME AND C.CONSTRAINT_CATALOG = K.CONSTRAINT_CATALOG AND C.CONSTRAINT_SCHEMA = K.CONSTRAINT_SCHEMA AND C.CONSTRAINT_NAME = K.CONSTRAINT_NAME WHERE C.CONSTRAINT_TYPE = 'PRIMARY KEY' AND K.COLUMN_NAME = 'keycol'; </code></pre>
<p>this query return column with is primary key.</p> <pre><code>SELECT col.COLUMN_NAME , col.DATA_TYPE , col.CHARACTER_MAXIMUM_LENGTH ln , CAST(ISNULL(j.is_primary, 0) AS BIT) is_primary FROM INFORMATION_SCHEMA.COLUMNS col LEFT JOIN ( SELECT K.TABLE_NAME , K.COLUMN_NAME , CASE WHEN K.CONSTRAINT_NAME IS NULL THEN 0 WHEN K.CONSTRAINT_NAME IS NOT NULL THEN 1 END is_primary FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS C JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS K ON C.TABLE_NAME = K.TABLE_NAME AND C.CONSTRAINT_CATALOG = K.CONSTRAINT_CATALOG AND C.CONSTRAINT_SCHEMA = K.CONSTRAINT_SCHEMA AND C.CONSTRAINT_NAME = K.CONSTRAINT_NAME WHERE C.CONSTRAINT_TYPE = 'PRIMARY KEY' AND C.TABLE_NAME = 'tablename' ) j ON col.COLUMN_NAME = j.COLUMN_NAME WHERE col.TABLE_NAME = 'tablename' </code></pre>
27,412
<p>In class, we learned about the halting problem, Turing machines, reductions, etc. A lot of classmates are saying these are all abstract and useless concepts, and there's no real point in knowing them (i.e., you can forget them once the course is over and not lose anything).</p> <p>Why is theory useful? Do you ever use it in your day-to-day coding? </p>
<p>When I graduated from college, I assumed that I was on par with everyone else: "I have a BS in CS, and so do a lot of other people, and we can all do essentially the same things." I eventually discovered that my assumption was false. I stood out, and my background had a lot to do with it--particularly my degree.</p> <p>I knew that there was one "slight" difference, in that I had a "B.S." in CS because my college was one of the first (supposedly #2 in 1987) in the nation to receive accreditation for its CS degree program, and I graduated in the second class to have that accreditation. At the time, I did not think that it mattered much.</p> <p>I had also noticed during high school and in college that I did particularly well at CS--much better than my peers and even better than many of my teachers. I was asked for help a lot, did some tutoring, was asked to help with a research project, and was allowed to do independent study when no one else was. I was happy to be able to help, but I did not think much about the difference.</p> <p>After college (USAFA), I spent four years in the Air Force, two of which were applying my CS degree. There I noticed that very few of my coworkers had degrees or even training related to computers. The Air Force sent me to five months of certification training, where I again found a lack of degrees or training. But here I started to notice the difference--it became totally obvious that many of the people I encountered did not REALLY know what they were doing, and that included the people with training or degrees. Allow me please to illustrate.</p> <p>In my Air Force certification training were a total of thirteen people (including me). As Air Force officers or the equivalent, we all had BS degrees. I was in the middle based on age and rank (I was an O-2 amongst six O-1s and six O-3s and above). At the end of this training, the Air Force rubber-stamped us all as equally competent to acquire, build, design, maintain, and operate ANY computer or communication system for ANY part of the Department of Defense.</p> <p>However, of the thirteen of us, only six had any form of computer-related degree; the other seven had degrees ranging from aeronautics to chemistry/biology to psychology. Of the six of us with CS degrees, I learned that two had never written a program of any kind and had never used a computer more than casually (writing papers, playing games, etc.). I learned that another two of us had written exactly one program on a single computer during their CS degree program. Only one other person and myself had written more than one program or used more than one kind of computer--indeed, we found that we two had written many programs and used many kinds of computers.</p> <p>Towards the end of our five-month training, our class was assigned a programming project and we were divided into four groups to separately undertake it. Our instructors divided up the class in order to spread the "programming talent" fairly, and they assigned roles of team lead, tech lead, and developer. Each group was given a week to implement (in Ada) a full-screen, text-based user interface (this was 1990) for a flight simulator on top of an instructor-provided flight-mechanics library. I was assigned as tech lead for my team of four.</p> <p>My team lead (who did not have a computer degree) asked the other three of us to divide up the project into tasks and then assigned a third of them to each of us. I finished my third of the tasks by the middle of that first day, then spent the rest of the day helping my other two teammates, talking to my team lead (BSing ;^), and playing on my computer.</p> <p>The next morning (day two), my team lead privately informed me that our other two teammates had made no progress (one could not actually write an "if" statement that would compile), and he asked me to take on their work. I finished the entire project by mid-afternoon, and my team spent the rest of the day flying the simulator.</p> <p>The other guy with the comparable CS degree was also assigned as a tech lead for his team, and they finished by the end of day three. They also began flying their simulator. The other two teams had not finished, or even made significant progress, by the end of the week. We were not allowed to help other teams, so it was left at that.</p> <p>Meanwhile, by the middle of day three, I had noticed that the flight simulator just seemed to behave "wrong". Since one of my classmates had a degree in aeronautics, I asked him about it. He was mystified, then confessed that he did not actually know what made a plane fly!?! I was dumbfounded! It turns out that his entire degree program was about safety and crash investigations--no real math or science behind flight. On the other hand, I had maybe a minor in aeronautics (remember USAFA?), but we had designed wings and performed real wind tunnel tests. Therefore, I quietly spent the rest of the week rewriting the instructor-provided flight-mechanics library until the simulator flew "right".</p> <p>Since then, I have spent nearly two decades as a contractor and occasionally as an employee, always doing software development plus related activities (DBA, architect, etc.). I have continued to find more of the same, and eventually I gave up on my youthful assumption.</p> <p>So, what exactly have I discovered? Not every one is equal, and that is okay--I am not a better person because I can program effectively, but I am more useful IF that is what you need from me. I learned that my background really mattered: growing up in a family of electricians and electrical engineers, building electronics kits, reading LITERALLY every computer book in the school/public libraries because I did not have access to a real computer, then moving to a new city where my high school did have computers, then getting my own computer as a gift, going to schools that had computers of many different sizes and kinds (PCs to mainframes), getting an accredited degree from a VERY good engineering school, having to write lots of programs in different languages on different kinds of computers, having to write hard programs (like my own virtual machine with a custom assembly language, or a Huffman compression implementation, etc.), having to troubleshoot for myself, building my own computers from parts and installing ALL the software, etc.</p> <p>Ultimately, I learned that my abilities are built on a foundation of knowing how computers work from the electrical level on up--discrete electronic components, circuitry, subsystems, interfaces, protocols, bits, bytes, processors, devices, drivers, libraries, programs, systems, networks, on up to the massive enterprise-class conglomerates that I routinely work on now. So, when the damn thing misbehaves, I know exactly HOW and WHY. And I know what cannot be done as well as what can. And I know a lot about what has been done, what has been tried, and what is left relatively unexplored.</p> <p>Most importantly, after I have learned all that, I have learned that I don't know a damned thing. In the face of all that there is potentially to know, my knowledge is miniscule.</p> <p>And I am quite content with that. But I recommend that you try.</p>
<p>I guess it depends on which field you go into. </p>
29,140
<p>My question is, how do I version control the production environment in a good way?</p> <p>This is our current environment:</p> <ul> <li>(Internal server) Development - Version controlled source code</li> <li>(Customer server) Acceptance test environment</li> <li>(Customer server) Staging environment</li> <li>(Customer server) Production environment</li> </ul> <p>When we release new functionality for acceptance testing, we make a publish in Visual Studio, zip up the changes and apply them on the Test Server. There we make a backup folder (so that we can revert the changes) and we make a release folder so that we can move these changes to Staging when they're approved.</p> <p>This is a lot of manual labour creating backup folders, release folders, recreating the directory structure and try to track what functionality that goes into what release. It is teadious and there is always problem with some developer not following the release procedure.</p> <hr> <p>In theory I could make a repository for the test environment. (forget source code, this is about the published application) On every release the developer do a commit and supply a comment about the functionality he's releasing.</p> <p>When functionality should be moved from Test to Staging we export changes made from the last date Staging environment was updated and copy them into the Staging application. There we do a commit that later can be extracted for release to Production environment.</p> <p>The drawbacks of this is that using subversion will clutter the application with those .svn directories. This may be mended by disallowing access to those directories in the IIS or web.config. Another solution would be using Git on the directory above the root directory of the application. But Git is harder to work with for an unexperienced developer in a windows environment.</p> <p>Does anyone have experience of this problem? How do you version control your production environment? What if you need to revert a release, do you have a backup folder that you created before the release?</p> <p>I've discussed this with our developers, and they can't see any problem with using subversion for versioning and backup of the test/staging/production environment. Quite the opposite would they be happy not to create release/backup folders every time they need to release new functionality.</p> <p>At the same time there is some insecurity about this. None have heard of this before, having the application in a version control system and we are unsure what the drawbacks would be.</p> <p>If you have experience of a scenario like this, I would be happy to hear about it.</p> <p>Mikael Lundin</p>
<p>Another way to do things would be to use a build server. Every time you check in code the build server builds and packages up the new build inside the development environment. Then checks in the deployable package with your code.</p> <p>You can then deploy the packaged build to the other environments. This way you don't have to back up the versions there because you already have all the built versions in your main repository. If you make sure deployment is fully automated and can be done with one command (powershell?) there's no need to keep backups on the servers anymore.</p> <p>This is actually better and more maintainable than the solution you propose. Because every version of the build is kept alongside the code you can always find a complete development environment for any build package. If you version-control your servers separately and you find a bug somewhere it can be hard to find the version of the code that causes the bug.</p>
<p>Thank you for your answers and suggestions.</p> <p>I see that I need to rethink the way we handle releases to these environments. Having a build server with all the releases ever made could solve a part of the problem. I will get the commit comments on the source code, and much better control of what feature goes into what build. I still need to keep track on what build is in what environment to be able to revert a release if something went wrong.</p> <p>@Jonke I will take a look at Mercurial. Maybe a version controlled production environment is overkill if you have a build system where each revision has version controlled source code. But I would still like to have a fast way to revert changes to a previous revision if anything goes wrong during deployment of new functionality. I also like the way you get version controlled configuration files on the server, since production environment always have different configuration from the development environment.</p> <p>Maybe I'm looking for the silver bullet :)</p>
33,149
<ol> <li>What's the best delimiter to use when exporting data?</li> <li>What's the best way to work with NULL data if you have an INT field in the table?</li> </ol>
<p>I'm not sure what the asker (nice name, :JPnoui38f) is trying to do. Sql Server management Studio has the ability to dump your data in a number of different ways. You don't have to worry about how to handle nulls or what delimeter to use. The tools take care of that.</p> <p>Here's an <a href="http://www.databasejournal.com/features/mssql/article.php/3580216" rel="nofollow noreferrer">article about the Import/Export wizard</a>. Another option is the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=56E5B1C5-BF17-42E0-A410-371A838E570A" rel="nofollow noreferrer">database publishing wizard</a>, which dumps your data to sql scripts.</p>
<ol> <li><p>If you have data with embedded control characters you may want to do a prefix based export using bcp instead of delimited text. The prefix prepends a column with a length indicator and the import reads this rather than looking for the delimiter.</p></li> <li><p>For some reason that I cannot fathom and cannot find documentation of, bcp will not import null values into numeric columns, even if they are nullable. You need to make a staging table with all varchar columns and then postprocess the data.</p></li> </ol>
21,433
<p>In my fieldset I have labels next (side) to my textboxes, but for some reason, they are towards the top and not middle. Here is my CSS for the fieldset:</p> <pre><code>fieldset { clear: both; font-size: 100%; border-color: #000000; border-width: 1px 0 0 0; border-style: solid none none none; padding: 10px; margin: 0 0 0 0; } label { font: bold 12px Verdana, Arial, Helvetica, sans-serif, MS UI Gothic; float: left; width: 12em; text-align:right; vertical-align:text-bottom; } </code></pre> <p>What am I missing?</p>
<p>Try adjusting the <strong>line-height</strong> property for the label element. You may need to increase or decrease it.</p>
<p>To me this is the most frustrating thing about css... Zack is right it will probably take some tweaking with the line-height, sometimes <b>lots</b> of tweaking (like 20px). i think that floating the element causes line height to be difficult?? if you want it in the middle of the line you should set vertical-align:middle; too. </p> <p>hope this helps...</p>
32,181
<p>How do I "name" a browser window in ROR, such that I can open a page in it later, from another (popup) window (using the target="name" html parameter)</p>
<p>You have to use JavaScript for this:</p> <pre><code>&lt;script type="text/javascript"&gt; window.name = "MyWindow"; &lt;/script&gt; </code></pre> <p>Of course you could easily package this up into a Rails helper method. For example, in <code>app/helpers/application_helper.rb</code> add a new method:</p> <pre><code>def window_name(name) content_for(:window_name) do "&lt;script type=\"text/javascript\"&gt;window.name = \"#{name}\";&lt;/script&gt;" end end </code></pre> <p>Next, in your layout file, add this line somewhere within the HTML <code>&lt;head&gt;</code> element:</p> <pre><code>&lt;%= yield :window_name %&gt; </code></pre> <p>Finally, in your view templates, simply add a line like this (can be anywhere you want) to output the correct JavaScript:</p> <pre><code>&lt;% window_name 'MyWindow' %&gt; </code></pre>
<p>You could try below:</p> <pre><code>var x=window.open("", "myWindow"); var y="&lt;head&gt;&lt;title&gt;my window&lt;/title&gt;&lt;/head&gt;&lt;body&gt;my window&lt;/body&gt;"; x.document.write(y); </code></pre>
5,675
<p>In Delphi 2009 I'm finding that any time I use TThread.CurrentThread in an application, I'll get an error message like the following when the application closes:</p> <pre><code>Exception EAccessViolation in module ntdll.dll at 0003DBBA. Access violation at address 7799DBBA in module 'ntdll.dll'. Write of address 00000014. </code></pre> <p>Unless it's just my machine, you can replicate this in a few seconds: create a new Delphi Forms Application, add a button to the form, and use something like the following for the button's event handler:</p> <pre><code>procedure TForm1.Button1Click(Sender: TObject); begin TThread.CurrentThread; end; </code></pre> <p>On both my Vista machine and my XP machine I'm finding that, if I <em>don't</em> click the button everything's fine, but if I <em>do</em> click the button I get the above error message when I close the application.</p> <p>So... I'm wondering if this is a bug, but at the same time I think it's rather likely that I'm simply not understanding something very basic about how you're supposed to work with TThreads in Delphi. I am a bit of a Delphi newbie I'm afraid.</p> <p>Is there something obviously wrong with using TThread.CurrentThread like that?</p> <p>If not, and you have Delphi 2009, do you get the same problem if you implement my simple sample project?</p> <hr> <h2><strong>Update: As François noted below, this actually is a bug in Delphi 2009 at the moment - you can <a href="http://qc.codegear.com/wc/qcmain.aspx?d=67726" rel="noreferrer">vote for it here</a>.</strong></h2> <hr> <h2><strong>Update: This bug was fixed in Delphi 2010.</strong></h2>
<p>Unfortunately it seems like a bug linked to the call order of the finalization section in the Classes unit: </p> <p><code>DoneThreadSynchronization</code> clears the <code>ThreadLock</code> structure, then<br> <code>FreeExternalThreads</code> wants to destroy the Thread object you just created when calling <code>CurrentThread</code>, and<br> that requires the ThreadLock to be already initialized in the call to<br> <code>EnterCriticalSection(ThreadLock)</code> in <code>TThread.RemoveQueuedEvents</code>...</p> <p><strong>UPDATE</strong>:<br> There is now a <strong>workaround patch</strong> in the <a href="http://qc.codegear.com/wc/qcmain.aspx?d=67726" rel="nofollow noreferrer"><strong>QC report</strong></a>.</p>
<p>I think CurrentThread is added in 2009 (or 2007). I have 2006 at home. But are you sure it is a class property?</p>
22,825
<p>I got a Tronxy X5S-400, I assembled it and when I power it on, I see on the screen one of the below images and gets stuck there.</p> <p>Is the firmware broken? If yes, where can I get a <code>configuration.h</code> file?</p> <p>I verified that the two buses between the screen and the mainboard are not loose or incorrectly connected.</p> <p><a href="https://i.stack.imgur.com/ilwaq.jpg" rel="nofollow noreferrer" title="Marlin splash screen"><img src="https://i.stack.imgur.com/ilwaq.jpg" alt="Marlin splash screen" title="Marlin splash screen"></a></p> <p><a href="https://i.stack.imgur.com/IIkog.jpg" rel="nofollow noreferrer" title="Screen corruption"><img src="https://i.stack.imgur.com/IIkog.jpg" alt="Screen corruption" title="Screen corruption"></a></p> <p>The board is a MKS Melzi v2.0 clone</p> <p><a href="https://i.stack.imgur.com/Hhtaw.jpg" rel="nofollow noreferrer" title="Controller"><img src="https://i.stack.imgur.com/Hhtaw.jpg" alt="Controller" title="Controller"></a></p>
<p>It looked like the firmware wasn't flashed correctly in the factory. What I did was to flash a bootloader using an Arduino compatible board and to flash the Marlin software e.g. according to <a href="https://www.youtube.com/watch?v=3gwWVFtdg-4" rel="nofollow noreferrer">videos from this guy</a>.</p> <p>Next, the menu wasn't displayed correctly so I added, in the <code>Configuration.h</code> the following lines:</p> <pre><code>#define ST7920_DELAY_1 DELAY_NS(63) #define ST7920_DELAY_2 DELAY_NS(100) #define ST7920_DELAY_3 DELAY_NS(125) </code></pre> <p>Now the display is working fine, and the Marlin firmware can be directly flashed from the computer because the bootloader remains there.</p> <p>I also had a problem with the heating bed which was heating very slow and I had to raise consistently the <code>TEMP_BED_RESIDENCY_TIME</code> and decrease <code>TEMP_BED_HYSTERESIS</code> to 1.</p>
<p>If the controller is one of Tronxy's new Chitu boards, you will not have the option of recompiling the firmware, since they are locked down. Apart from checking that the PSU is delivering the correct voltage, your only option may be to request a new main board from the vendor.</p>
1,286
<p>I remember reading about an automation program for windows that would accept a list of commands like this:</p> <pre><code>press the ok button put "hello world" into the text control press the add button </code></pre> <p>etc etc. Can anyone name this program? A thousand thankyous.</p>
<p>Take a look at watin. <a href="http://watin.sourceforge.net/" rel="nofollow noreferrer">http://watin.sourceforge.net/</a> Combined with Microsoft Oslo DSL. You can achieve this easily</p>
<p>Maybe look for a port of AppleScript to Windows? Assuming such a beast does not exist, perhaps something like <a href="http://www.autohotkey.com/" rel="nofollow noreferrer">AutoHotKey</a> or <a href="http://www.autoitscript.com/autoit3/index.shtml" rel="nofollow noreferrer">AutoIt</a> might be close enough?</p>
38,022
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/249760/how-to-convert-unix-timestamp-to-datetime-and-vice-versa">How to convert UNIX timestamp to DateTime and vice versa?</a> </p> </blockquote> <p>I've got the following class:</p> <pre><code>[DataContractAttribute] public class TestClass { [DataMemberAttribute] public DateTime MyDateTime { get; set; } } </code></pre> <p>Here's the JSON:</p> <pre><code>{ "MyDateTime":"1221818565" } </code></pre> <p>The JSON is being returned from a PHP webservice.</p> <p>What I need to do, is convert that epoch string into a valid C# DateTime. What's the best way of doing this?</p> <p>I can do this:</p> <pre><code>[IgnoreDataMemberAttribute] public DateTime MyDateTime { get; set; } [DataMemberAttribute(Name = "MyDateTime")] public Int32 MyDateTimeTicks { get { return this.MyDateTime.Convert(...); } set { this.Created = new DateTime(...); } } </code></pre> <p>But the trouble with this is, the MyDateTimeTicks is public (changing it to private causes an exception in the serialization process)</p>
<p>Finishing what you posted, AND making it private seemed to work fine for me.</p> <pre><code>[DataContract] public class TestClass { private static readonly DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); [IgnoreDataMember] public DateTime MyDateTime { get; set; } [DataMember(Name = "MyDateTime")] private int MyDateTimeTicks { get { return (int)(this.MyDateTime - unixEpoch).TotalSeconds; } set { this.MyDateTime = unixEpoch.AddSeconds(Convert.ToInt32(value)); } } } </code></pre>
<p>What you want is the following:</p> <pre><code>DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); DateTime dotnetTime = unixEpoch.AddSeconds(Convert.ToDouble(ticks)); </code></pre> <p>where <code>ticks</code> is the value passed to you by PHP.</p>
31,055
<p>I have two web applications running in the same Tomcat Instance. In one of these applications the user will have the ability to upload files such as images and pdf files. I would like the uploaded files to be available to the second application. </p> <p>Is there a best practice for such a scenario? Or just a pointer to a technology would be fine.</p> <p>I considered using web services but wondered if it was overkill.</p> <p>Thanks Vincent</p>
<p>Cheap, bad answer - have both applications softlink to a shared directory. This has the benefit of being stupid-simple to do but has evil transactional-type issues. Since you say that only one application is changing the data, and the other is read-only you might be able to get away with it, as long as the second app can't observe files in a partially created state.</p> <p>Using a db is transactionally safe but is going to be pretty unpleasant as the files get larger.</p>
<p>You could shove the files into a shared database... this also lets you store meta data along with them.</p>
24,072
<p>I have seen the official demos on lwjgl.org but I would like to see some more tutorial level examples.</p>
<p>Google "import org.lwjgl" to find lots of examples, as all code that uses LWJGL must contain that string to import parts of the package.</p>
<p>The <a href="http://lwjgl.org/wiki/index.php?title=Main_Page" rel="nofollow">LWJGL wiki</a> contains several examples with explanations. Since most work in LWJGL directly reflects OpenGL (e.g. 'glBegin()'), you could just look up some OpenGL tutorials.</p>
20,919
<p>I want to get virtual path of a web page from a web service. Is there any way to do this?. suppose i have an aspx page like aa, i want to get full path as a url for that page from my web service.</p> <p>Regards, Harsh Suman</p>
<p>What type of web-service? asmx? or wcf (svc)?</p> <p>With asmx, you can use <code>HttpContext.Current</code> to get the current ASP.NET request, so you can get pretty-much anything you can get with ASP.NET; try looking at the <code>.Request</code> property of <code>HttpContext.Current</code>.</p> <p>With wcf, this is not recommended - but it can be made to work if you enable ASP.NET compatibility.</p>
<p>I agree with the post above. You can use the HttpContext.Current.Request object to get at virtual path and request URL.</p> <pre><code>string path = HttpContext.Current.Request.ApplicationPath; </code></pre> <p>or if you want the full URL:</p> <pre><code>string path = HttpContext.Current.Request.Url.OriginalString; </code></pre>
45,489
<p>I am a self-taught embedded developer. I mostly use AVRs programmed in C and ASM, but I have dabbled with other systems. I am looking to move onto more complex devices like CPLDs and FPGAs, but I have no idea where to start. So my one and a half questions are:</p> <ol> <li>Do you prefer VHDL or Verilog and why?</li> <li>What is a good way for one with no prior experience in HDLs get started in learning such a beast?</li> </ol>
<p>Buy a cheap starter kit from Xilinx or Altera (the two big FPGA players). A Xilinx Spartan3 starter kit is $200.</p> <p>I personally prefer VHDL. It is strongly typed and has more advanced features than Verilog. VHDL is more popular in Europe and Verilog is dominating in the US. </p> <p>Buy a book (e.g. Peter Ashendens The Designers Guide to VHDL) and start simulating your designs in a free simulator. ModelSim from Mentor Graphis is a good one and there are free versions available (with crippled simulation speed).</p> <p>Make up some interesting project (mini cpu, vga graphics, synthesizer) and start designing. Always simulate and make sure your design works before putting your design into the hardware ...</p> <p>If you have no background in digital electronics buy a book in that subject as well.</p>
<p>Before plunging into Verilog/VHDL or buying an FPGA dev kit I'd recommend taking an introductory class on digital design. There are good online <a href="http://ocw.mit.edu/OcwWeb/web/home/home/index.htm" rel="nofollow noreferrer">OpenCourseWare MIT </a>classes. </p> <p>Good luck.</p>
21,388
<p>The GetVersions() call to the Versions.asmx web service in SharePoint 2003 returns a localised date format, with no way of determining what the format is. It's the site regional setting of date format, but I can't find a way to get even that out of SharePoint 2003. Locally, it looks like SPRegionalSettings can be used (<a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spregionalsettings.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spregionalsettings.aspx</a>) but what about a web service version of this?</p>
<p>Sadly, it isn't available. However, you can specify a query option to specify that you want the values returned in UTC:</p> <p><a href="http://www.sharepointblogs.com/pm4everyone/archive/2006/10/03/sharepoint-2003-querying-with-gmt-datetime.aspx" rel="nofollow noreferrer"><a href="http://www.sharepointblogs.com/pm4everyone/archive/2006/10/03/sharepoint-2003-querying-with-gmt-datetime.aspx" rel="nofollow noreferrer">http://www.sharepointblogs.com/pm4everyone/archive/2006/10/03/sharepoint-2003-querying-with-gmt-datetime.aspx</a></a></p>
<p>Sadly, it isn't available. However, you can specify a query option to specify that you want the values returned in UTC:</p> <p><a href="http://www.sharepointblogs.com/pm4everyone/archive/2006/10/03/sharepoint-2003-querying-with-gmt-datetime.aspx" rel="nofollow noreferrer"><a href="http://www.sharepointblogs.com/pm4everyone/archive/2006/10/03/sharepoint-2003-querying-with-gmt-datetime.aspx" rel="nofollow noreferrer">http://www.sharepointblogs.com/pm4everyone/archive/2006/10/03/sharepoint-2003-querying-with-gmt-datetime.aspx</a></a></p>
17,728
<p>Does anyone know how I can get a list of products belonging to a specific category from within a view file in <a href="http://www.magentocommerce.com/" rel="noreferrer">Magento</a>?</p>
<p>You can use magento object to filter.</p> <p>Example:</p> <pre><code>$categoryId = 123; // a category id that you can get from admin $category = Mage::getModel('catalog/category')-&gt;load($categoryId); $products = Mage::getModel('catalog/product') -&gt;getCollection() -&gt;addCategoryFilter($category) -&gt;load(); print_r($products); </code></pre>
<p>You should always avoid putting code like this into a view, it's very bad practice. You can also run into issues as views can be cached, leading to unexpected behaviour.</p> <p>you should override the block you are using, placing code there. you can then call any new methods inside your view files.</p> <p>for example, you could copy Mage_Catalog_Block_Product_List </p> <p>from: app/code/core/Catalog/Block/Product/List.php </p> <p>to: app/code/local/Catalog/Block/Product/List.php </p> <p>you could then add a new method, possibly using some of the code mentioned in the above posts. your new method would then be available inside your view file (list.phtml or any view using this block)</p>
34,356
<p>Any ideas how i can best drive a USB POS printer from c#. POS printers are usually serial, TCP/IP or USB based. I know how to accomplish serial and TCP/IP but have no idea about communications through USB in C#. I know that there is a layer available from Microsoft called POS.NET, but I want to try and avoid using this. Any ideas or any C# libraries that people can recomend would be really appreciated. Thanks</p>
<p>You should really consider using POS for .NET and OPOS or .NET service objects (Epson, for example provides both). POS for .NET conforms to the UnifiedPOS industry standard for interfacing with these devices.</p>
<p>There is a C# wrapper for Win32 USP api's from the icsharpcode guys <a href="http://www.icsharpcode.net/opensource/sharpusblib/" rel="nofollow noreferrer">here</a>, and I've seen at least <a href="http://weblogs.asp.net/israelio/archive/2005/08/15/422637.aspx" rel="nofollow noreferrer">one</a> other reference to USB stuff in .Net.</p> <p>What may be tricky is whether or not the Printer requires OPOS in order to function. I did some work on a POS project in .Net a few years back, and from what I remember OPOS is pretty much the standard for the hardware side of things (And at the time all OPOS APIs utilized COM interop). The devices sometimes also have a documented proprietary communications protocol, in which case you should be able to utilize that to talk to the device using the USB library.</p>
22,704
<p>How do I get a patch from a commit in order to send it to another developer? And how do I best avoid a merge conflict with this patch when merging our trees at a later date?</p> <p>If you know how please explain how to do this in your VCS of choice such as subversion, git, Mercurial, bzr or etc.</p>
<p>In <a href="http://git.or.cz/" rel="noreferrer">git</a> you can pipe the output of <a href="http://git-scm.com/docs/git-diff" rel="noreferrer"><code>git-diff</code></a> between two commits like this:</p> <pre><code>git diff fa1afe1 deadbeef &gt; patch.diff </code></pre> <p>Send the <code>patch.diff</code> to the developer and let him <a href="http://www.kernel.org/pub/software/scm/git/docs/git-apply.html" rel="noreferrer"><code>git-apply</code></a> it to his workspace like this:</p> <pre><code>git apply patch.diff </code></pre> <p>If the other developer already has the commits available in his repository he could always pipe it in himself without merging like this:</p> <pre><code>git apply &lt; git diff fa1afe1 deadbeef </code></pre> <p>You can then <a href="http://www.kernel.org/pub/software/scm/git/docs/git-add.html" rel="noreferrer">add</a> and <a href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html" rel="noreferrer">commit</a> the changes in the diff <a href="http://www.kernel.org/pub/software/scm/git/docs/everyday.html" rel="noreferrer">the usual way</a>.</p> <hr> <p>Now here comes the interesting part when you have to merge the patch back to the master branch (that is public). Consider the following revision tree where <code>C*</code> is the applied patch from <code>C</code> in the master branch:</p> <pre><code>A---B---C---D master, public/master \ E---C*---F feature_foo </code></pre> <p>You can use <a href="http://git-scm.com/docs/git-rebase" rel="noreferrer"><code>git-rebase</code></a> to update the topic branch (in this example named <code>feature_foo</code>) with it's upstream head. What that means is when you type in the following:</p> <pre><code>git rebase master feature_foo </code></pre> <p>Git will rearrange the revision tree like this and will also apply the patch itself:</p> <pre><code>A---B---C---D master, public/master \ E*---F* feature_foo </code></pre> <p>Merging to the upstream branch will now be an easy fast-forward merge. Also check that the new commits <code>E*</code> and <code>F*</code> work as the previous <code>E</code> and <code>F</code> respectively.</p> <p>You can do the same thing against another developer's branch using the same steps but instead of doing it on a public repo, you'll be <a href="http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html" rel="noreferrer">fetching</a> revisions from the developer's repository. This way you won't have to ask the other developer for a patch if it is already available from what he published at his repo.</p> <p>Please note to <strong>never rebase a public branch</strong> because the command will rewrite git history which is something you don't want to do on branches that people depend on and will create a mess when merging to remote repositories. Also never forget to <a href="http://en.wikipedia.org/wiki/Continuous_Integration" rel="noreferrer">integrate often</a> so others in your team can take part of your changes. </p>
<p>In SVN you can simply make your changes then before commiting, pipe the output of the svn diff to a file as such</p> <pre><code>svn diff &gt; mypatch.diff </code></pre> <p>you can then revert your changes and apply the patch at a later date using</p> <pre><code>patch -p0 -i mypatch.diff </code></pre> <p>As always don't blindly apply patches to your code and always inspect them first.</p> <p>You may also find that the patch will break your source code if the source files have changed significantly enough since the patch was taken.</p> <p>You also can not guarantee that there will not be merge conflicts when you attempt to check in the code.</p>
37,496
<p>I have an application which is supposed to work on both windows and Mac and is localized in Portuguese, Spanish and German. I have an ini file from where the localized strings are read from. But the ini file doesn't work with same encoding for the files on both platforms. For Windows I have to have the file in ANSI format or else the accented letters in the localized strings get messed up and on the Mac the same file should be in Western( Mac OS) encoding or else the same result. Is there any way I can get a single file to work on both platforms?</p>
<p>(1) There is no such thing as <em>the</em> ANSI format. That's an unfortunate term for what on Windows means "the local codepage". In particular, this means that in Europe the interpretation of bytes 128-255 as "ANSI format" will differ between countries. So, I am strongly inclined to argue that it won't even work on your first platform, let alone both.</p> <p>The solution you will eventually migrate to is Unicode. That works everywhere, with all characters, and the number of a character does not depend on the country or the current date (See introduction of €).</p>
<p><a href="http://www.gnu.org/software/gettext/" rel="nofollow noreferrer">gettext</a> is a widely used framework for translation of applications, websites, etc.</p>
20,173
<p>I have a core dump file from a process that has probably a file descriptor leak (it opens files and sockets but apparently sometimes forgets to close some of them). Is there a way to find out which files and sockets the process had opened before crashing? I can't easily reproduce the crash, so analyzing the core file seems to be the only way to get a hint on the bug.</p>
<p>If you have a core file and you have compiled the program with debugging options (-g), you can see where the core was dumped:</p> <pre><code>$ gcc -g -o something something.c $ ./something Segmentation fault (core dumped) $ gdb something core </code></pre> <p>You can use this to do some post-morten debugging. A few gdb commands: bt prints the stack, fr jumps to given stack frame (see the output of bt).</p> <p>Now if you want to see which files are opened at a segmentation fault, just handle the SIGSEGV signal, and in the handler, just dump the contents of the /proc/PID/fd directory (i.e. with system('ls -l /proc/PID/fs') or execv).</p> <p>With these information at hand you can easily find what caused the crash, which files are opened and if the crash and the file descriptor leak are connected.</p>
<p>Another way to find out what files a process has opened - again, only during runtime - is looking into /proc/PID/fd/ , which contains symlinks to open files.</p>
8,297
<p>I run Jetty6 yet gladly place Apache in the front if needs be.</p> <p>I would like to have two webserver instances running on the same machine on different ports. I would like the instance on port 80 to redirect the second public domain name to the second webserver on port 8080.</p> <p>This should not be visible to web users.</p> <p>Thank you.</p>
<p><a href="http://nginx.net/" rel="nofollow noreferrer">nginx</a> setup as a proxy is a common method for doing this. It has a good reputation and I personally know of several high traffic sites using it with good results. </p> <p>The <a href="http://wiki.codemongers.com/Main" rel="nofollow noreferrer">twiki</a> has lots of info, and <a href="http://wiki.codemongers.com/NginxTurboGearsProxy" rel="nofollow noreferrer">this proxy setup</a> is probably similar to what you're looking for.</p>
<p>If I understand your question correctly, you need to enable mod_proxy in Apache, then use this line on the web server running on port 80.</p> <p>ProxyPassReverse / <a href="http://localhost:8080/" rel="nofollow noreferrer">http://localhost:8080/</a></p> <p>This will reverse proxy all requests to port 80 onto port 8080.</p>
33,126
<p>How do I force Postgres to use an index when it would otherwise insist on doing a sequential scan?</p>
<p>Assuming you're asking about the common "index hinting" feature found in many databases, PostgreSQL doesn't provide such a feature. This was a conscious decision made by the PostgreSQL team. A good overview of why and what you can do instead can be found <a href="http://blog.2ndquadrant.com/hinting_at_postgresql/" rel="noreferrer">here</a>. The reasons are basically that it's a performance hack that tends to cause more problems later down the line as your data changes, whereas PostgreSQL's optimizer can re-evaluate the plan based on the statistics. In other words, what might be a good query plan today probably won't be a good query plan for all time, and index hints force a particular query plan for all time.</p> <p>As a very blunt hammer, useful for testing, you can use the <code>enable_seqscan</code> and <code>enable_indexscan</code> parameters. See:</p> <ul> <li><a href="http://www.postgresql.org/docs/current/static/indexes-examine.html" rel="noreferrer">Examining index usage</a></li> <li><a href="http://www.postgresql.org/docs/current/static/runtime-config-query.html" rel="noreferrer"><code>enable_</code> parameters</a></li> </ul> <p>These are <em>not suitable for ongoing production use</em>. If you have issues with query plan choice, you should see <a href="http://www.postgresql.org/docs/current/static/performance-tips.html" rel="noreferrer">the documentation for tracking down query performance issues</a>. Don't just set <code>enable_</code> params and walk away.</p> <p>Unless you have a very good reason for using the index, Postgres may be making the correct choice. Why?</p> <ul> <li>For small tables, it's faster to do sequential scans.</li> <li>Postgres doesn't use indexes when datatypes don't match properly, you may need to include appropriate casts.</li> <li>Your planner settings might be causing problems.</li> </ul> <p>See also <a href="http://archives.postgresql.org/pgsql-sql/2006-02/msg00188.php" rel="noreferrer">this old newsgroup post</a>.</p>
<p>Apparently there are cases where Postgre can be hinted to using an index by repeating a similar condition twice.</p> <p>The specific case I observed was using PostGIS <code>gin</code> index and the <a href="https://postgis.net/docs/ST_Within.html" rel="nofollow noreferrer">ST_Within</a> predicate like this:</p> <pre class="lang-sql prettyprint-override"><code>select * from address natural join city natural join restaurant where st_within(address.location, restaurant.delivery_area) and restaurant.delivery_area ~ address.location </code></pre> <p>Note that the first predicate <code>st_within(address.location, restaurant.delivery_area)</code> is automatically decomposed by PostGIS into <code>(restaurant.delivery_area ~ address.location) AND _st_contains(restaurant.delivery_area, address.location)</code> so adding the second predicate <code>restaurant.delivery_area ~ address.location</code> is completely redundant. Nevertheless, the second predicate convinced the planner to use spatial index on <code>address.location</code> and in the specific case I needed, improved the running time 8 times.</p>
39,913
<p>i want to have some shared code (code library, controls, utilities, helper classes, etc) in Visual Studio. i do not mean shared assemblies, i mean shared code (i.e. i want to ship one assembly with my application, the executable assembly).</p> <p>The technique in other development environments way is to have the common source code in a path on my machine, and the IDE is given a list of paths to search for code files.</p> <p>Visual Studio does not support code search paths.</p> <p>The back-up hack solution is to copy the source-code over and over into every project. But then in order to keep them all as one version, they are shared in source control. This works well when your source control provider is Microsoft Visual SourceSafe - which supports shared files.</p> <p>But other source control products (CVS, Subversion, Microsoft Team Foundation Source Save Server, SVN) do not support shared files.</p> <p>So how does everyone else avoid shipping DLL's with their executable?</p> <hr> <p><strong>Update 1</strong></p> <p>It is an issue of single file deployment. ClickOnce generates 18 files in 3 folders (i.e. more than one file)</p>
<p>I could propose two solutions:</p> <ol> <li>Visual Studio allows you to add a link to a file. Choose "Add Existing Item", pick your file and then click the arrow next to the "Add" button. A popup will display and you should choose "Add as link" from there. Now you can store your common code in one location (folder).</li> </ol> <p><img src="https://i.stack.imgur.com/hnpEC.png" alt="enter image description here"></p> <ol start="2"> <li>Compile your common code in reusable assemblies and use them in your projects. Use <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=22914587-B4AD-4EAE-87CF-B14AE6A939B0&amp;displaylang=en" rel="nofollow noreferrer">ILMerge</a> to merge all assemblies into one when deploying. I personally prefer this option.</li> </ol>
<p>We use ClickOnce deployment, which has been very reliable. With ClickOnce, there is <em>conceptually</em> a single object, the application, although many files (including DLLS) are downloaded, although hidden to the user. Shared code is then dealt with through shared projects.</p> <p>But if you actually physically require just a single file, ClickOnce won't work for you...</p>
32,814
<p>The application uses Oracle DataAccess ver. 1.1. , VS 2008, .Net Framework 3.5 w/SP1</p> <pre><code>OracleConnection connection = new OracleConnection(ConnectionStringLogon); connection.Open(); OracleParameter selectParam = new OracleParameter(":applicationName", OracleDbType.Varchar2, 256); selectParam.Value = applicationName; if (connection.State != ConnectionState.Open) connection.Open(); OracleCommand cmd = new OracleCommand(); cmd.Connection = connection; cmd.CommandText = "Select ApplicationId from Applications where AppName = 'appName'"; cmd.CommandType = CommandType.Text; if (selectParam != null) { cmd.Parameters.Add(selectParam); } object lookupResult = cmd.ExecuteScalar(); cmd.Parameters.Clear(); if (lookupResult != null) </code></pre> <p>The procedure fails on object lookupResult = cmd.ExecuteScalar(); with this error:</p> <p>Event Type: Error Event Source: App Log Event Category: None Event ID: 9961 Date: 9/30/2008 Time: 4:42:11 PM User: N/A Computer: Server15 Description: System.NullReferenceException: Object reference not set to an instance of an object. at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior) at Oracle.DataAccess.Client.OracleCommand.ExecuteReader() at Oracle.DataAccess.Client.OracleCommand.ExecuteScalar() at Membership.OracleMembershipProvider.GetApplicationId(String applicationName, Boolean createIfNeeded) in OracleMembershipProvider.cs:line 1626</p> <p>I've looked at this from every angle that I can conceive of... basically, no matter how I wrap it, the Execute fails.</p>
<p>if you're using apache you may want to take a look at <a href="http://httpd.apache.org/docs/2.0/programs/ab.html" rel="noreferrer">apache ab</a></p>
<p>We use Loadrunner to do bandwidth and traffic simulation in our App. Loadrunner is can start agents on various machines and you can simulate one machine as running on dialup modem v/s another on DSL v/s another on Cable internet. We also use Loadrunner to simulate various kinds of traffic conditions from 10 user run to 500 user run. We can also insert think times in the script and simulate a real user executing the http request. The best part is that it comes with a recording studio where it will plug in with Internet explorer and you can record the whole scenario/Usecase that can be as simple as hitting one page to a full blown 50-60 page script or more.</p>
18,785
<p>What is the best C++ IDE for a *nix envirnoment? I have heard the C/C++ module of Eclipse is decent as well as Notepad++ but beyond these two I have no real idea. Any thoughts or comments?</p>
<p>On Ubuntu, some the IDEs that are available in the repositories are:</p> <ul> <li><a href="http://www.kdevelop.org/" rel="noreferrer">Kdevelop</a></li> <li><a href="http://geany.uvena.de/" rel="noreferrer">Geany</a></li> <li><a href="http://anjuta.sf.net/" rel="noreferrer">Anjuta</a></li> </ul> <p>There is also: </p> <ul> <li><a href="http://eclipse.org" rel="noreferrer">Eclipse</a> (Recommended you don't install from repositories, due to issues with file/folder permissions) </li> <li><a href="http://www.codeblocks.org/" rel="noreferrer">Code::blocks</a></li> </ul> <p>And of course, everyone's favourite text-based editors:</p> <ul> <li>vi/vim</li> <li>emacs</li> </ul> <p>Its true that vim and emacs are very powerful tools, but the learning curve is very steep.. </p> <p>I really don't like <strong>Eclipse</strong> that much, I find it buggy and a bit too clunky.<br> I've started using <strong>Geany</strong> as a bare-bones but functional and <em>usable</em> IDE. It has a basic code-completion feature, and is a nice, clean [Gnome] interface.<br> <strong>Anjuta</strong> I tried for a day, didn't like it at all. I didn't find it as useful as Geany.</p> <p><strong>Kdevelop</strong> and <strong>code::blocks</strong> get a bunch of good reviews, but I haven't tried them. I use gnome, and I'm yet to see a KDE app that looks good in gnome (sorry, I'm sure its a great program).</p> <p>If only bloodshed dev-c++ was released under linux. That is a fantastic (but windows-only) program. You could always run it under Wine ;)</p> <p>To a degree, it comes down to personal preference. My advice is to investigate Kdevelop, Geany and code::blocks as a starting point. </p>
<p>I can't really vouch for the Eclipse module, but that might be attributed to the fact that I'm on Windows and have nearly no idea what I'm doing. </p> <p>Can't go wrong with your favorite text editor though.</p>
10,456
<p>When developing Java applications, I often override Object methods (usually equals and hashCode). I would like some way to systematically check that I'm adhering to the contract for Object methods for every one of my classes. For example, I want tests that assert that for equal objects, the hash code is also equal. I'm using the JUnit test framework, so preferably I'd like some JUnit solution where I can automatically generate these tests, or some test case that can somehow visit all of my classes and make sure that the contract is upheld.</p> <p>I'm using JDK6 and JUnit 4.4.</p>
<pre> public static void checkObjectIdentity(Object a1, Object a2, Object b1) { assertEquals(a1, a2); assertEquals(a2, a1); assertNotSame(a1, a2); assertEquals(a1.hashCode(), a2.hashCode()); assertFalse(a1.equals(b1)); assertFalse(a2.equals(b1)); assertFalse(b1.equals(a1)); assertFalse(b1.equals(a2)); } </pre> <p>Usage:</p> <pre> checkObjectIdentity(new Integer(3), new Integer(3), new Integer(4)); </pre> <p>Can't think of anything better. Add new calls to checkObjectIdentity when you find a bug.</p>
<p>I think VonC's on the right track, but I would even settle for something less sophisticated, such as a parameterized test that takes in the .class object (for which the Object methods are being tested), followed by a variable number of constructor args. Then, you'd have to use reflection to find the constructor that matches the types for the passed-in arguments, and call the constructor. This test would assume that the parameters being passed into it would create a valid instance of the object.</p> <p>The downside to this solution is that you have to "register" each class you want to test with this test class, and you have to make sure that valid input is given to the constructor, which would not always be easy. In that light, I'm on the fence as to whether or not this would be more or less work than manually writing all the tests for each class anyway.</p> <p>Vote up if you think this could work...leave a comment if you want me to flush it out more (if it turns out to be a feasible solution, I may just do this anyway)</p>
23,056
<p>I have a question about how to do something "The Rails Way". With an application that has a public facing side and an admin interface what is the general consensus in the Rails community on how to do it?</p> <p>Namespaces, subdomains or forego them altogether?</p>
<p>There's no real "Rails way" for admin interfaces, actually - you can find every possible solution in a number of applications. DHH has implied that he prefers namespaces (with HTTP Basic authentication), but that has remained a simple implication and not one of the official Rails Opinions.</p> <p>That said, I've found good success with that approach lately (namespacing + HTTP Basic). It looks like this:</p> <p>routes.rb:</p> <pre><code>map.namespace :admin do |admin| admin.resources :users admin.resources :posts end </code></pre> <p>admin/users_controller.rb:</p> <pre><code>class Admin::UsersController &lt; ApplicationController before_filter :admin_required # ... end </code></pre> <p>application.rb</p> <pre><code>class ApplicationController &lt; ActionController::Base # ... protected def admin_required authenticate_or_request_with_http_basic do |user_name, password| user_name == 'admin' &amp;&amp; password == 's3cr3t' end if RAILS_ENV == 'production' || params[:admin_http] end end </code></pre> <p>The conditional on <code>authenticate_or_request_with_http_basic</code> triggers the HTTP Basic auth in production mode or when you append <code>?admin_http=true</code> to any URL, so you can test it in your functional tests and by manually updating the URL as you browse your development site.</p>
<p>Thanks to everyone that answered my question. Looks like the consensus is to use namespaces if you want to as there is no DHH sponsored Rails Way approach. :)</p> <p>Again, thanks all!</p>
14,499
<p>I want to build my own custom log4j (network) adapter to solve my problem <a href="https://stackoverflow.com/questions/29505/deserialize-in-a-different-language">that I posted here.</a></p> <p>I have looked at the documentation on the log4j and I cant see where/if the developers go into how to do this.</p> <p>Can anyone point me in the right direction to get started?</p>
<p><a href="http://www.javaworld.com/javaworld/jw-12-2004/jw-1220-toolbox.html" rel="nofollow noreferrer">Write custom appenders for log4j</a></p>
<p>May I suggest that you leverage the existing SyslogAppender?</p>
6,933
<p>Huge files take forever to load and work with in vim, due to syntax-highlighting.</p> <p>I'm looking for a way to limit size of highlighted files, such that files larger than (say) 10MB will be colorless.</p>
<p>Adding the following line to _vimrc does the trick, with a bonus: it handles gzipped files, too (which is a common case with huge files):</p> <pre><code>autocmd BufWinEnter * if line2byte(line("$") + 1) &gt; 1000000 | syntax clear | endif </code></pre>
<p>vim -c 'syntax off' filename.ext</p>
21,481
<p>Working to get DateTimes for any time zone. I'm using DateTimeOffset, and a string, and an XmlElement attribute. When I do, I get the following error:</p> <blockquote> <p>[InvalidOperationException: 'dateTime' is an invalid value for the XmlElementAttribute.DataType property. dateTime cannot be converted to System.String.]<br> System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) +450</p> <p>[InvalidOperationException: There was an error reflecting type 'System.String'.]<br> System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) +1621<br> System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +8750<br> System.Xml.Serialization.XmlReflectionImporter.ImportFieldMapping(StructModel parent, FieldModel model, XmlAttributes a, String ns, RecursionLimiter limiter) +139<br> System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter) +1273</p> <p>[InvalidOperationException: There was an error reflecting property 'creationTimeX'.] ...</p> </blockquote> <p>Code:</p> <pre><code> [System.Xml.Serialization.XmlElement(ElementName = "creationTime", DataType="dateTime")] public string creationTimeX { get { return this.creationTimeField.ToString("yyyy-MM-ddTHH:mm:sszzz"); } set { DateTimeOffset.TryParse(value, out this.creationTimeField); } } [System.Xml.Serialization.XmlIgnoreAttribute()] public System.DateTimeOffset creationTime { get { return this.creationTimeField; } set { this.creationTimeField = value; } } </code></pre>
<p>Take a look at this StackOverflow question about serializing dates and UTC:</p> <p><a href="https://stackoverflow.com/questions/65164/best-practices-for-datetime-serialization-in-net-framework-35sql-server-2008">Best practices for DateTime serialization in .Net framework 3.5/SQL Server 2008</a></p> <p>No need to create a special property just to accomplish the serialization.</p>
<p>The datatype of the property <code>creationTimeX</code> is string while the XmlSerialization datatype is <code>DateTime</code>. That's why you are getting that exception.</p> <p>You can fix this by changing the datatype to <code>DateTime</code>.</p> <p>Also for your issue of the current time for any timezone, you would have to apply a <code>DateTime.Now.ToUniveralTime()</code> and apply appropriate DateTimeFormat pattern on it.</p> <p><a href="http://msdn.microsoft.com/en-us/library/k494fzbf.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/k494fzbf.aspx</a></p>
39,565
<p>When indenting java code with annotations, vim insists on indenting like this:</p> <pre><code>@Test public void ... </code></pre> <p>I want the annotation to be in the same column as the method definition but I can't seem to find a way to tell vim to do that, except maybe using an indent expression but I'm not sure if I can use that together with regular cindent.</p> <p>edit: The filetype plugin was already turned on I just got a bit confused about indenting plugins. The accepted answer may be a bit hackish but works for me as well.</p>
<p>Edit: I cannot delete my own answer because it has already been accepted, but <a href="https://stackoverflow.com/a/4414015/2844">@pydave's answer</a> seems to be the better (more robust) solution. <hr> You should probably be using the indentation file for the java FileType (instead of using cindent) by setting <code>filetype plugin indent on</code>. </p> <p>That said, the indentation file coming with the Vim 7.1 from my linux distribution (looking at the current vim svn this is still true for 7.2) doesn't account for annotations yet. I therefore copied <code>/usr/share/vim/vim71/indent/java.vim</code> (see <a href="https://vim.svn.sourceforge.net/svnroot/vim/branches/vim7.1/runtime/indent/java.vim" rel="nofollow noreferrer">https://vim.svn.sourceforge.net/svnroot/vim/branches/vim7.1/runtime/indent/java.vim</a>) to <code>~/.vim/indent/java.vim</code> and added the following lines right before the end:</p> <pre><code>let lnum = prevnonblank(v:lnum - 1) let line = getline(lnum) if line =~ '^\s*@.*$' let theIndent = indent(lnum) endif </code></pre> <p>I'm not sure if this breaks any of the other indentations, but it works for me.</p>
<p>I found pydave's suggestion <em>almost</em> what I wanted, but I wanted this:</p> <pre><code>@Override public void ... </code></pre> <p><strong>and</strong> this:</p> <pre><code>@Override public void ... </code></pre> <p>so I replaced the regex (as per pydave's, place in <code>~/.vim/after/indent/java.vim</code>):</p> <pre><code>setlocal indentexpr=GetJavaIndent_improved() function! GetJavaIndent_improved() let theIndent = GetJavaIndent() let lnum = prevnonblank(v:lnum - 1) let line = getline(lnum) if line =~ '^\s*@[^{]*$' let theIndent = indent(lnum) endif return theIndent endfunction </code></pre>
24,530
<p>I recently turned on Windows Firewall logging on my computer and started tracking incoming and outgoing connections. Something curious about the logfiles is that I have noticed numerous UDP packets (in fact, it constitutes basically all of my incoming traffic) that don't have my host as destination or source showing up in the logs.</p> <p>I thought this might be a implementation detail for UDP (the packets are hopping over my computer in the subnet) but Wikipedia'ing UDP didn't enlighten me any more, and I don't see why my computer should be forwarding these packets in the first place.</p> <p>Any ideas?</p> <p><strong>Edit 1:</strong> Here is what a log file line with the mysterious UDP packet looks like:</p> <pre><code>2008-10-11 16:04:31 ALLOW UDP 18.243.7.218 239.255.255.250 49152 3702 0 - - - - - - - RECEIVE </code></pre> <p>Is 239.255.255.250 a broadcast address? Now that you mention it, the UDP packets I'm seeing have very specific destinations, basically 224.0.0.252, 239.255.255.250, 18.243.255.255. I also get phantom ICMP pings addressed to 224.0.0.1.</p>
<p>The packets addressed to IPs starting with 239 and 224 are <a href="http://en.wikipedia.org/wiki/Multicast" rel="noreferrer">multicast packets</a>. This is a way to address traffic to a group of computers without broadcasting it to an entire network. It is used by various legitimate protocols.</p> <p>224.0.0.252 is the address used by the <a href="http://en.wikipedia.org/wiki/Link-local_Multicast_Name_Resolution" rel="noreferrer">Link Local Name Resolution protocol</a>.</p> <p>239.255.255.250 is the address used by the <a href="http://en.wikipedia.org/wiki/Simple_Service_Discovery_Protocol" rel="noreferrer">Simple Service Discovery Protocol</a>.</p> <p>224.0.0.1 is the <a href="http://tldp.org/HOWTO/Multicast-HOWTO-2.html" rel="noreferrer">all hosts address</a>, used by your router to see who on your network is willing to participate in multicast conversations.</p> <p>The ones addressed to 18.243.255.255 look like broadcasts, again this is used by many legitimate protocols such as Bonjour.</p> <p>As recommended by Luka, a good protocol analyzer like <a href="http://www.wireshark.org/" rel="noreferrer">Wireshark</a> will tell you precisely what each of these packets are and what they contain.</p>
<p>Hard to say without analyzing the log data, but they could be broadcast packets on the segment, in which case you're system would listen to them. This is possible in IPv4 and IPv6.</p> <p>Your system should not be forwarding them unless it's set up to route, but it can certainly be listening to packets all the time (various network protocols use UDP).</p>
23,639
<p>I have a working TYPO3 extension. It is attached <a href="http://wiki.orbeon.com/forms/doc/developer-guide/form-runner-typo3-extension" rel="nofollow noreferrer">this wiki page</a>. How can I change the code of this extension so it is of the USER_INT type? I.e. I don't want TYPO3 to cache the output of this plugin, and want TYPO3 to invoke the extension ever time a page that uses the extension, i.e. disable the caching for this extension.</p>
<p>To disable caching for your extension go to your piX/class.tx_XXX_piX.php file and remove the following line (below your class declaration):</p> <pre><code>var $pi_checkCHash = true; </code></pre> <p>You also need to add the following line in the main method (below $this->pi_loadLL();):</p> <pre><code>$this-&gt;pi_USER_INT_obj=1; // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object! </code></pre>
<p>When you have created your extension with Kickstarter you also have to go to the file [yourextension]/ext_localconf.php and change this line</p> <pre><code>t3lib_extMgm::addPItoST43($_EXTKEY,'piX/class.tx_yourextension_piX.php','_piX','list_type',0); </code></pre> <p>to this:</p> <pre><code>t3lib_extMgm::addPItoST43($_EXTKEY,'piX/class.tx_yourextension_piX.php','_piX','list_type',1); </code></pre>
37,396
<p>I'm receiving a recovery feed from an exchange for recovering data missed from their primary feed.</p> <p>The exchange <strong>strongly</strong> recommends listening to the recovery feed only when data is needed, and leaving the multicast once I have recovered the data I need.</p> <p>My question is, if I am using asio, and not reading from the NIC when I don't need it, what is the harm? The messages have sequence numbers, so I can't accidentally process an old message "left" on the card.</p> <p>Is this really harming my application?</p>
<p>It's likely <strong>not</strong> harming your application so much as harming your machine - since the nic is still configured into the multicast group, it's still listening to those messages and passing them up, before your software ignores them and they get discarded. That's a lot of extra work that your network stack and kernel are doing, and therefore a lot of extra load on the machine in general, not just your app.</p>
<p>An addition to <a href="https://stackoverflow.com/users/6306/muz">muz's</a> comment...</p> <p>It's unlikely that this will make any difference to your system, but it's worth being aware that there is an overhead associated with maintaining a multicast membership (assuming that you're using IGMP - which is probably reasonable given the restriction about "leaving the multicast")</p> <p>IGMP requires the sending and processing of multicast group memberships at regular intervals. And (as alluded to in muz's comment) if you have any switches or routers between you and the multicast source that are capable of igmp snooping then they are able to disable the multicast for a given network.</p>
9,888
<p>Portfolio A → Fund 1</p> <p>Portfolio A → Fund 2</p> <p>Portfolio A → Fund 3</p> <p>I couldn't frame my sentence without not using is/has. But between 1 &amp; 2,</p> <p>1) has a:</p> <pre><code>class PortfolioA { List&lt;Fund&gt; obj; } </code></pre> <p>2) is a:</p> <pre><code>class PortfolioA : List&lt;Fund&gt; { } </code></pre> <p>which one do you think is better from the point of extensibility, usability? I can still access my funds either way, albeit with a small syntactical change.</p>
<p>I vote with the other folks who say HAS-A is better in this case. You ask in a comment:</p> <blockquote> <p>when I say that a Portfolio is just a collection of funds, with a few attributes of its own like TotalPortfolio etc, does that fundamentally not become an "is-a"?</p> </blockquote> <p>I don't think so. If you say <code>Portfolio</code> IS-A <code>List&lt;Fund&gt;</code>, what about other properties of the Portfolio? Of course you can add properties to this class, but is it accurate to model those properties as properties of the List? Because that's basically what you're doing.</p> <p>Also what if a Portfolio is required to support more than one <code>List&lt;Fund&gt;</code>? For instance, you might have one List that shows the current balance of investments, but another List that shows how new contributions are invested. And what about when funds are discontinued, and a new set of funds is used to succeed them? Historical information is useful to track, as well as the current fund allocation.</p> <p>The point is that all these properties are not correctly properties of a List, though they may be properties of the Portfolio.</p>
<p><strong>IS-A relation ship</strong> represents inheritances and <strong>HAS-A relation ship</strong> represents composition. For above mentioned scenario we prefer composition as PortfolioA has a List and it is not the List type. Inheritances use when Portfolio A is a type of List but here it is not. Hence for this scenario we should prefer Composition. </p>
32,969
<p>I've been attempting to learn C in my spare time, and other languages (C#, Java, etc.) have the same concept (and often the same operators)...</p> <p>At a core level, what does bit-shifting (<code>&lt;&lt;</code>, <code>&gt;&gt;</code>, <code>&gt;&gt;&gt;</code>) do, what problems can it help solve, and what gotchas lurk around the bend? In other words, an absolute beginner's guide to bit shifting in all its goodness.</p>
<p>The bit shifting operators do exactly what their name implies. They shift bits. Here's a brief (or not-so-brief) introduction to the different shift operators.</p> <h2>The Operators</h2> <ul> <li><code>&gt;&gt;</code> is the arithmetic (or signed) right shift operator.</li> <li><code>&gt;&gt;&gt;</code> is the logical (or unsigned) right shift operator.</li> <li><code>&lt;&lt;</code> is the left shift operator, and meets the needs of both logical and arithmetic shifts.</li> </ul> <p>All of these operators can be applied to integer values (<code>int</code>, <code>long</code>, possibly <code>short</code> and <code>byte</code> or <code>char</code>). In some languages, applying the shift operators to any datatype smaller than <code>int</code> automatically resizes the operand to be an <code>int</code>.</p> <p>Note that <code>&lt;&lt;&lt;</code> is not an operator, because it would be redundant.</p> <p>Also note that <strong>C and C++ do not distinguish between the right shift operators</strong>. They provide only the <code>&gt;&gt;</code> operator, and the right-shifting behavior is implementation defined for signed types. The rest of the answer uses the C# / Java operators.</p> <p>(In all mainstream C and C++ implementations including GCC and Clang/LLVM, <code>&gt;&gt;</code> on signed types is arithmetic. Some code assumes this, but it isn't something the standard guarantees. It's not <em>undefined</em>, though; the standard requires implementations to define it one way or another. However, left shifts of negative signed numbers <em>is</em> undefined behaviour (signed integer overflow). So unless you need arithmetic right shift, it's usually a good idea to do your bit-shifting with unsigned types.)</p> <hr /> <h2>Left shift (&lt;&lt;)</h2> <p>Integers are stored, in memory, as a series of bits. For example, the number 6 stored as a 32-bit <code>int</code> would be:</p> <pre><code>00000000 00000000 00000000 00000110 </code></pre> <p>Shifting this bit pattern to the left one position (<code>6 &lt;&lt; 1</code>) would result in the number 12:</p> <pre><code>00000000 00000000 00000000 00001100 </code></pre> <p>As you can see, the digits have shifted to the left by one position, and the last digit on the right is filled with a zero. You might also note that shifting left is equivalent to multiplication by powers of 2. So <code>6 &lt;&lt; 1</code> is equivalent to <code>6 * 2</code>, and <code>6 &lt;&lt; 3</code> is equivalent to <code>6 * 8</code>. A good optimizing compiler will replace multiplications with shifts when possible.</p> <h3>Non-circular shifting</h3> <p>Please note that these are <em>not</em> circular shifts. Shifting this value to the left by one position (<code>3,758,096,384 &lt;&lt; 1</code>):</p> <pre><code>11100000 00000000 00000000 00000000 </code></pre> <p>results in 3,221,225,472:</p> <pre><code>11000000 00000000 00000000 00000000 </code></pre> <p>The digit that gets shifted &quot;off the end&quot; is lost. It does not wrap around.</p> <hr /> <h2>Logical right shift (&gt;&gt;&gt;)</h2> <p>A logical right shift is the converse to the left shift. Rather than moving bits to the left, they simply move to the right. For example, shifting the number 12:</p> <pre><code>00000000 00000000 00000000 00001100 </code></pre> <p>to the right by one position (<code>12 &gt;&gt;&gt; 1</code>) will get back our original 6:</p> <pre><code>00000000 00000000 00000000 00000110 </code></pre> <p>So we see that shifting to the right is equivalent to division by powers of 2.</p> <h3>Lost bits are gone</h3> <p>However, a shift cannot reclaim &quot;lost&quot; bits. For example, if we shift this pattern:</p> <pre><code>00111000 00000000 00000000 00000110 </code></pre> <p>to the left 4 positions (<code>939,524,102 &lt;&lt; 4</code>), we get 2,147,483,744:</p> <pre><code>10000000 00000000 00000000 01100000 </code></pre> <p>and then shifting back (<code>(939,524,102 &lt;&lt; 4) &gt;&gt;&gt; 4</code>) we get 134,217,734:</p> <pre><code>00001000 00000000 00000000 00000110 </code></pre> <p>We cannot get back our original value once we have lost bits.</p> <hr /> <h1>Arithmetic right shift (&gt;&gt;)</h1> <p>The arithmetic right shift is exactly like the logical right shift, except instead of padding with zero, it pads with the most significant bit. This is because the most significant bit is the <em>sign</em> bit, or the bit that distinguishes positive and negative numbers. By padding with the most significant bit, the arithmetic right shift is sign-preserving.</p> <p>For example, if we interpret this bit pattern as a negative number:</p> <pre><code>10000000 00000000 00000000 01100000 </code></pre> <p>we have the number -2,147,483,552. Shifting this to the right 4 positions with the arithmetic shift (-2,147,483,552 &gt;&gt; 4) would give us:</p> <pre><code>11111000 00000000 00000000 00000110 </code></pre> <p>or the number -134,217,722.</p> <p>So we see that we have preserved the sign of our negative numbers by using the arithmetic right shift, rather than the logical right shift. And once again, we see that we are performing division by powers of 2.</p>
<p>Be aware of that only 32 bit version of PHP is available on the Windows platform.</p> <p>Then if you for instance shift &lt;&lt; or >> more than by 31 bits, results are unexpectable. Usually the original number instead of zeros will be returned, and it can be a really tricky bug.</p> <p>Of course if you use 64 bit version of PHP (Unix), you should avoid shifting by more than 63 bits. However, for instance, MySQL uses the 64-bit BIGINT, so there should not be any compatibility problems.</p> <p>UPDATE: From PHP 7 Windows, PHP builds are finally able to use full 64 bit integers: <em>The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18, except on Windows prior to PHP 7, where it was always 32 bit.</em></p>
17,105
<p>How do I Unit Test a MVC redirection?</p> <pre><code>public ActionResult Create(Product product) { _productTask.Save(product); return RedirectToAction("Success"); } public ActionResult Success() { return View(); } </code></pre> <p>Is <a href="http://www.ayende.com/Blog/archive/2007/12/13/Dont-like-visibility-levels-change-that.aspx" rel="nofollow noreferrer">Ayende's</a> approach still the best way to go, with preview 5:</p> <pre><code> public static void RenderView(this Controller self, string action) { typeof(Controller).GetMethod("RenderView").Invoke(self,new object[] { action} ); } </code></pre> <p>Seems odd to have to do this, especially as the MVC team have said they are writing the framework to be testable.</p>
<pre><code>[TestFixture] public class RedirectTester { [Test] public void Should_redirect_to_success_action() { var controller = new RedirectController(); var result = controller.Index() as RedirectToRouteResult; Assert.That(result, Is.Not.Null); Assert.That(result.Values["action"], Is.EqualTo("success")); } } public class RedirectController : Controller { public ActionResult Index() { return RedirectToAction("success"); } } </code></pre>
<p>You can assert on the ActionResult that is returned, you'll need to cast it to the appropriate type but it does allow you to use state-based testing. A search on the Web should find some useful links, here's <a href="http://sebastienlachance.com/2008/05/06/testing-controllers-in-aspnet-mvc-aka-actionresult/" rel="nofollow noreferrer">just one</a> though.</p>
8,286
<p>We're experimenting with various ways to throttle user actions in a <strong>given time period</strong>:</p> <ul> <li>Limit question/answer posts</li> <li>Limit edits</li> <li>Limit feed retrievals</li> </ul> <p>For the time being, we're using the Cache to simply insert a record of user activity - if that record exists if/when the user does the same activity, we throttle.</p> <p>Using the Cache automatically gives us stale data cleaning and sliding activity windows of users, but how it will scale could be a problem.</p> <p>What are some other ways of ensuring that requests/user actions can be effectively throttled (emphasis on stability)?</p>
<p>Here's a generic version of what we've been using on Stack Overflow for the past year:</p> <pre><code>/// &lt;summary&gt; /// Decorates any MVC route that needs to have client requests limited by time. /// &lt;/summary&gt; /// &lt;remarks&gt; /// Uses the current System.Web.Caching.Cache to store each client request to the decorated route. /// &lt;/remarks&gt; [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class ThrottleAttribute : ActionFilterAttribute { /// &lt;summary&gt; /// A unique name for this Throttle. /// &lt;/summary&gt; /// &lt;remarks&gt; /// We'll be inserting a Cache record based on this name and client IP, e.g. "Name-192.168.0.1" /// &lt;/remarks&gt; public string Name { get; set; } /// &lt;summary&gt; /// The number of seconds clients must wait before executing this decorated route again. /// &lt;/summary&gt; public int Seconds { get; set; } /// &lt;summary&gt; /// A text message that will be sent to the client upon throttling. You can include the token {n} to /// show this.Seconds in the message, e.g. "Wait {n} seconds before trying again". /// &lt;/summary&gt; public string Message { get; set; } public override void OnActionExecuting(ActionExecutingContext c) { var key = string.Concat(Name, "-", c.HttpContext.Request.UserHostAddress); var allowExecute = false; if (HttpRuntime.Cache[key] == null) { HttpRuntime.Cache.Add(key, true, // is this the smallest data we can have? null, // no dependencies DateTime.Now.AddSeconds(Seconds), // absolute expiration Cache.NoSlidingExpiration, CacheItemPriority.Low, null); // no callback allowExecute = true; } if (!allowExecute) { if (String.IsNullOrEmpty(Message)) Message = "You may only perform this action every {n} seconds."; c.Result = new ContentResult { Content = Message.Replace("{n}", Seconds.ToString()) }; // see 409 - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html c.HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict; } } } </code></pre> <p>Sample usage:</p> <pre><code>[Throttle(Name="TestThrottle", Message = "You must wait {n} seconds before accessing this url again.", Seconds = 5)] public ActionResult TestThrottle() { return Content("TestThrottle executed"); } </code></pre> <p>The ASP.NET Cache works like a champ here - by using it, you get automatic clean-up of your throttle entries. And with our growing traffic, we're not seeing that this is an issue on the server.</p> <p>Feel free to give feedback on this method; when we make Stack Overflow better, you get your <a href="https://stackoverflow.blog/2009/05/31/the-stack-overflow-trilogy/">Ewok fix</a> even faster :)</p>
<p>Since the highly voted answers to this question are too old, I am sharing the latest solution which worked for me.</p> <p>I tried using the Dynamic IP restrictions as given in an <a href="https://stackoverflow.com/a/584689/3085520">answer</a> on this page but when I tried to use that extension, I found that this extension has been discontinued by Microsoft and on the <a href="https://www.iis.net/downloads/microsoft/dynamic-ip-restrictions" rel="nofollow noreferrer">download page</a> they have clearly written the below message.</p> <pre><code>Microsoft has discontinued the Dynamic IP Restrictions extension and this download is no longer available. </code></pre> <p>So I researched further and found that the Dynamic IP Restrictions is now by default included in IIS 8.0 and above. The below information is fetched from the Microsoft Dynamic IP Restrictions page.</p> <p>In IIS 8.0, Microsoft has expanded the built-in functionality to include several new features:</p> <ul> <li>Dynamic IP address filtering, which allows administrators to configure their server to block access for IP addresses that exceed the specified number of requests.</li> <li>The IP address filtering features now allow administrators to specify the behavior when IIS blocks an IP address, so requests from malicious clients can be aborted by the server instead of returning HTTP 403.6 responses to the client.</li> <li>IP filtering now feature a proxy mode, which allows IP addresses to be blocked not only by the client IP that is seen by IIS but also by the values that are received in the x-forwarded-for HTTP header</li> </ul> <p>For step by step instructions to implement Dynamic IP Restrictions, please visit the below link:</p> <p><a href="https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-dynamic-ip-address-restrictions" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-dynamic-ip-address-restrictions</a></p> <p>I hope it helps someone stuck in a similar problem.</p>
5,412
<p>As a followup to my <a href="https://stackoverflow.com/questions/227143/java-what-is-javaawtcomponentgetname-and-setname-used-for">question about the java.awt.Component.getName() property</a>, I'm wondering if there is a way of squirreling an arbitrary object somewhere in a Component, similar to the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.tag.aspx" rel="nofollow noreferrer">tag property in .NET</a>? This would be really handy for any code that does work to a component but doesn't necessarily know what that component is.</p> <p>For example, say I'm trying to implement an application-wide help system that knows to look at any component currently pointed to by the mouse, reach into that component and pull out it's help text and display it in it's own pane on the screen (no, I don't want to use a tooltip). My answer currently is to use the Name (getName()/setName()) to store the help text, and this will work, but the Name has to be a string. If I wanted to get fancier and store anything other than a string, I think I'd be stuck.</p>
<p>I generally create a hash and put (component, cookie) whenever I add a component to the screen. When you need your cookie object back (in an event perhaps), the event always gets a copy of the component, and then you are just a get(component) away from your cookie.</p> <p>In some extreme conditions, I've subclassed the control and just added a field. It's a quick and dirty fix since subclassing the component is just like a few lines of code and can go in the same class the file where you are generating your screen. This is only useful if you just need to store your data connected to a single type of control.</p>
<p>Yeah, you could use the get/setName to set some kind of identifier, then use that identifier for mapping to your help. the JavaHelp CSH stuff works kind of like that, except that i believe that is putting the component itself into a map?</p>
28,119
<p>I'm trying to add an SVN repository to Eclipse. </p> <p>I've installed <a href="http://subclipse.tigris.org/" rel="noreferrer">Subclipse</a>, and it seems to be working fine. But, when I try to "add a new SVN repository", I input this, for example:</p> <p><em><a href="http://svn.python.org/projects/peps/trunk" rel="noreferrer">http://svn.python.org/projects/peps/trunk</a></em></p> <p>I get this:</p> <blockquote> <p>Error validating location: "org.tigris.subversion.javahl.ClientException: RA layer request failed svn: OPTIONS of '<a href="http://svn.python.org/projects/peps/trunk" rel="noreferrer">http://svn.python.org/projects/peps/trunk</a>': could not connect to server (<a href="http://svn.python.org" rel="noreferrer">http://svn.python.org</a>) " Keep location anyway?</p> </blockquote> <p>I know that my Eclipse can connect to the Internet, because I downloaded Subclipse earlier (I had to change my proxy settings). </p> <p>I get a similar message for other SVN locations I've tried to add. </p> <p>What is the solution?</p>
<p>This is a dead topic, but the solution is to install a client adapter along with Subclipse.</p> <p>Take a look at <a href="http://subclipse.tigris.org/wiki/PluginFAQ#head-da671f9d3dd97d874248445af428545727a8271a" rel="noreferrer">this</a>, and install SVN Client Adapter, SVNKit Adapter, and SVNKit Library.</p> <p>Then check under Window -> Preference -> Team -> SVN and make sure there is an entry for SVN Interface.</p> <p>And for future reference, if you can connect to the repository through the command line, then it must be a problem with the IDE.</p>
<p>I saw the same error and solved by switching off the proxy settings in TortoiseSVN that I normally need for commits to the company servers. I installed Subclipse to back up my own non-prime-time stuff to a local repository (using VisualSVN). I use Eclipse Galileo 3.3 and Subclipse 1.6.12.</p>
11,105
<p>I'm looking for tutorials or walkthroughs for converting DTS packages into the new SSIS 2005. Any one knows.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/cc768544.aspx" rel="noreferrer">Migrating DTS Packages to Integration Services</a></p> <p>SQL Server Integration Services provides a robust way to process millions of rows of data. The platform is highly extensible and performs much faster than the previous DTS platform. Migration of old DTS packages can be done two ways: through the built-in Package Migration Wizard, which handles simple package migrations; and through DTS xChange, which handles both simple and complex DTS migrations, while applying best practices to the migrated packages.</p>
<p>within solution explorer there is a menu option to import DTS packages. This should do all the conversion for you. Having said that i've only ever tried it on simple packages</p>
32,281
<p>I`m using Delphi 2009 and want to operate some XML data. I heard that nativeXML is one of the most convenient ways to do it. so how can I install this library?</p>
<p>NativeXML doesn't claim to support Delphi 2009 just yet. [Edit: Apparently there is a 2009 beta available to paying customers.] The trial version does not, so it cannot work with Delphi 2009 until that version of Delphi is officially supported.</p> <p>That said, using XML in Delphi for most purposes doesn't require third-party components. You have several options, depending upon what you're doing.</p> <ol> <li><p>The most straightforward is to use TXMLDocument. This lets you open an XML file or stream, and access nodes using a DOM.</p></li> <li><p>With the Enterprise version of Delphi, you get the XML data binding wizard. This generates strongly typed mapping classes for a certain XML schema. It's very convenient when you know exactly what the structure of the XML document you're parsing will be.</p></li> <li><p>A third option is the XML mapper, which allows you to read XML data to and from a TClientDataset.</p></li> </ol>
<p>Based on their <a href="http://www.simdesign.nl/xml.html" rel="nofollow noreferrer">web site</a>, it sounds like you just download the .dcu file, put it in a convenient directory, and add that directory to your type library path (tools->options->library path).</p> <p>After that, just add the unit to your uses clause and you should be good to go.</p>
39,773
<p>My servlet application includes a number of library .jars, some of which contain embedded log4j.xml or log4j.properties files. I'd like to ensure that log4j finds my log4j.xml first! I've tried searching for some specification of the priorities of the various classpath elements in a servlet (e.g. does WEB-INF/classes always precede WEB-INF/lib?), or some way to configure or tweak the servlet's classloader so that a given resource directory appears early in the classpath. So far, I've drawn a blank. Any suggestions on ensuring that a servlet .war file loads the correct log4j.xml via the classloader?</p>
<p>As far as I understand the resource selection from the classpath is non-deterministic (from the point of view of the app developer). Even if the same file is loaded consistently the behaviour could change: 1. When you upgrade the version of your current container. 2. If you switch containers.</p> <p>The simplest solution will be to <em>remove embedded log4j config files from library jars</em>. It is almost never a good idea to embed log4j config's as it leads to the problem you are seeing here...</p> <p>Are they third party jars or jars you developed?</p>
<p>You need to have log4j.properties in your CLASSPATH. The best place is under WEB-INF/classes.</p> <p>You also have to make sure that you use your version of log4j.jar. So, put it in WEB-INF/lib, just to make sure you are not using one from tomcat folders, since it may cause strange classloading issues.</p>
33,185
<p>Trying to debug an issue with a server and my only log file is a 20GB log file (with no timestamps even! Why do people use <code>System.out.println()</code> as logging? In production?!)</p> <p>Using grep, I've found an area of the file that I'd like to take a look at, line 347340107.</p> <p>Other than doing something like</p> <pre><code>head -&lt;$LINENUM + 10&gt; filename | tail -20 </code></pre> <p>... which would require <code>head</code> to read through the first 347 million lines of the log file, is there a quick and easy command that would dump lines 347340100 - 347340200 (for example) to the console?</p> <p><strong>update</strong> I totally forgot that grep can print the context around a match ... this works well. Thanks!</p>
<p>I found two other <a href="http://www.unix.com/unix-dummies-questions-answers/21027-how-do-you-specific-lines-file.html" rel="noreferrer">solutions</a> if you know the line number but nothing else (no grep possible):</p> <p>Assuming you need lines 20 to 40,</p> <pre><code>sed -n '20,40p;41q' file_name </code></pre> <p>or</p> <pre><code>awk 'FNR&gt;=20 &amp;&amp; FNR&lt;=40' file_name </code></pre> <p>When using <code>sed</code> it is more efficient to quit processing after having printed the last line than continue processing until the end of the file. This is especially important in the case of large files and printing lines at the beginning. In order to do so, the <code>sed</code> command above introduces the instruction <code>41q</code> in order to stop processing after line 41 because in the example we are interested in lines 20-40 only. You will need to change the 41 to whatever the last line you are interested in is, plus one.</p>
<p>You could try this command: </p> <pre><code>egrep -n "*" &lt;filename&gt; | egrep "&lt;line number&gt;" </code></pre>
23,238
<p>Hi were can I find training videos for MySQL ? </p>
<p>In youtube you find somethings like mysql install: <a href="http://www.youtube.com/watch?v=KQcFP3GcQ0s" rel="nofollow noreferrer">http://www.youtube.com/watch?v=KQcFP3GcQ0s</a></p> <p>mysql trainning: <a href="http://www.youtube.com/watch?v=BHq-bORKncA" rel="nofollow noreferrer">http://www.youtube.com/watch?v=BHq-bORKncA</a></p> <p>Google presentation about mysql tunning (hot) <a href="http://www.youtube.com/watch?v=u70mkgDnDdU" rel="nofollow noreferrer">http://www.youtube.com/watch?v=u70mkgDnDdU</a></p> <p>You have anothers google presentations about mysql, just search in youtube and googlevideos :-)</p>
<p>And don't forget: <a href="http://dev.mysql.com/" rel="nofollow noreferrer">http://dev.mysql.com/</a></p> <p>This is a good resource to back up anything you find in any videos. I can't recommend any videos as I have no experience with them, sorry. </p>
12,606
<p>I'm working with the PieChart and PieSeries components in Flex, and have ran into an issue. When the labelPosition property of a PieSeries is set to 'inside' and there is only one slice in the pie, the label doesn't get displayed.</p> <p>Looking at the docs, I'm guessing its some quirk related to when inside labels are removed. The doc reads as:</p> <blockquote> <p>Draw labels inside the chart, centered approximately seven tenths of the way along each wedge. Shrink labels to ensure that they do not interfere with each other. If labels are shrunk below the calloutPointSize property, remove them. When two labels overlap, Flex gives priority to labels for larger slices.</p> </blockquote> <p>One work around is to detect 1 slice and add another element to the dataProvider with a zero value, but the displayed label is still not where I'd like it, and there doesn't seem to be a way to move it.</p> <p>Another solution would be to wrap the PieChart with a canvas and just render text on top in the same format as I use for labels, but I would really prefer to not have to go this route (including rendering text on the chart's canvas, which might be slightly less of a hack, but still a hack).</p> <p>Here is some code demonstrating my issue:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" backgroundColor="white" &gt; &lt;mx:Script&gt; &lt;![CDATA[ import mx.collections.ArrayCollection; [Bindable] public var pieData:ArrayCollection = new ArrayCollection([ {value: 50, label: "This is a\nlong label"} ]); [Bindable] public var pieData2:ArrayCollection = new ArrayCollection([ {value: 50, label: "This is a\nlong label"}, {value: 0, label: ""} ]); ]]&gt; &lt;/mx:Script&gt; &lt;mx:HBox width="100%" height="100%" &gt; &lt;mx:PieChart width="100%" height="100%" &gt; &lt;mx:series&gt; &lt;mx:PieSeries dataProvider="{ pieData }" field="value" labelField="label" labelPosition="callout" /&gt; &lt;/mx:series&gt; &lt;/mx:PieChart&gt; &lt;mx:PieChart width="100%" height="100%" &gt; &lt;mx:series&gt; &lt;mx:PieSeries dataProvider="{ pieData }" field="value" labelField="label" labelPosition="insideWithCallout" /&gt; &lt;/mx:series&gt; &lt;/mx:PieChart&gt; &lt;mx:PieChart width="100%" height="100%" &gt; &lt;mx:series&gt; &lt;mx:PieSeries dataProvider="{ pieData }" field="value" labelField="label" labelPosition="inside" /&gt; &lt;/mx:series&gt; &lt;/mx:PieChart&gt; &lt;/mx:HBox&gt; &lt;mx:HBox width="100%" height="100%" &gt; &lt;mx:PieChart width="100%" height="100%" &gt; &lt;mx:series&gt; &lt;mx:PieSeries dataProvider="{ pieData2 }" field="value" labelField="label" labelPosition="callout" /&gt; &lt;/mx:series&gt; &lt;/mx:PieChart&gt; &lt;mx:PieChart width="100%" height="100%" &gt; &lt;mx:series&gt; &lt;mx:PieSeries dataProvider="{ pieData2 }" field="value" labelField="label" labelPosition="insideWithCallout" /&gt; &lt;/mx:series&gt; &lt;/mx:PieChart&gt; &lt;mx:PieChart width="100%" height="100%" &gt; &lt;mx:series&gt; &lt;mx:PieSeries dataProvider="{ pieData2 }" field="value" labelField="label" labelPosition="inside" /&gt; &lt;/mx:series&gt; &lt;/mx:PieChart&gt; &lt;/mx:HBox&gt; &lt;/mx:Application&gt; </code></pre> <p>Has anyone encountered this problem or know of a work-around/good solution?</p>
<p>All I can do is point out <a href="http://bugs.adobe.com/jira/browse/FLEXDMV-1569" rel="nofollow noreferrer">this bug report</a>, which looks to be what you've come across.</p> <p>I'm afraid I can't get the suggested patch to work though, maybe you'll have better luck.</p>
<p>The Flex charts are designed to be drawn on via the CartesianDataCanvas.</p> <p>See "Drawing on chart controls" in <em>Flex Data Visualization Developer's Guide / Flex Charting Components / Using Events and Effects in Charts</em></p> <p>Cheers</p>
47,152
<p>I'm trying to pick a good CMS that isn't a portal. All of my research as lead me to believe SilverStipe is the best option. I'd like some opinions/impressions.</p> <p>Thanks for any thoughts you have.</p> <p>edit: I've decided to try it out. I'll post my own answer after I've had some time with it. It seems like based on the lack of a response there isn't a large user base. (At least who intersect with the Stack Overflow community.)</p>
<p>I just stumbled upon Silverstripe / Sapphire a week ago or so (now is the 3rd November 2008) and I was amazed. This seems to be an underestimated piece of software. I'm not such a pro that I could say it for sure but I believe their code is very solid, clean and intelligent. They just got and award for the most promising open source CMS which might be a hint in the same direction. </p> <ul> <li>The CMS still lacks the vast amount of plugins and modules if you compare it with Joomla or Drupal but their <strong>code seems more advanced</strong>. </li> <li>The whole CMS uses the <strong>active record pattern</strong> approach and a <strong>clean MVC</strong> design. If you create a new pagetype you can add new db-fields in the page class, flush the db built via url and the cms inserts the new tables and fields.</li> <li><strong>Building templates is easier</strong> compared to Joomla for example, thanks to MVC and thanks to a two level approach using templates and subtemplates called layouts. E.g. if you have a page type called "BlogPage" the "BlogPage" Class first looks for a "BlogPage" template and if it doesn't find it it looks for a "BlogPage" layout and inserts it at the given place in the template.</li> </ul> <p>That's just my first impression after a few days of dabbling around with it.</p>
<p>There is also a book on Silverstripe out now - at least a German version, English version anounced for release end of August</p>
30,994
<p>Is there any simple way of creating tappered thread in OpenSCAD? I need something like 10 mm in diameter at the end, 9 at the top and the height of 10 mm.</p>
<p>I mostly use a tooth brush for that kind of problem</p>
<p>If you are able to remove the gear, as I suspect you can, a useful tool is the file card. It resembles a flat hair brush but the bristles are short wire, very stiff. In traditional use, it removes metal shavings from conventional metal files. It will easily remove plastic from between the gear teeth. If you are unable to remove the gear, but can access a portion of the exposed teeth, a suitably named dental pick can remove slowly the clogged material.</p> <p>Cooking the gear may not cause a fire, but could carbonize the plastic onto the teeth, perhaps creating a greater problem.</p>
323
<p>I've inherited a large VB6 app at my current workplace. I'm kinda learning VB6 on the job and there are a number of problems I'm having. The major issue at the moment is I can't figure out how to check if a key exists in a Collection object. Can anyone help?</p>
<p>@Mark Biek Your keyExists closely matches my standard Exists() function. To make the class more useful for COM-exposed collections and checking for numeric indexes, I'd recommend changing sKey and myCollection to not be typed. If the function is going to be used with a collection of objects, 'set' is required (on the line where val is set).</p> <p><strong>EDIT</strong>: It was bugging me that I've never noticed different requirements for an object-based and value-based Exists() function. I very rarely use collections for non-objects, but this seemed such a perfect bottleneck for a bug that would be so hard to track down when I needed to check for existence. Because error handling will fail if an error handler is already active, two functions are required to get a new error scope. Only the Exists() function need ever be called:</p> <pre><code>Public Function Exists(col, index) As Boolean On Error GoTo ExistsTryNonObject Dim o As Object Set o = col(index) Exists = True Exit Function ExistsTryNonObject: Exists = ExistsNonObject(col, index) End Function Private Function ExistsNonObject(col, index) As Boolean On Error GoTo ExistsNonObjectErrorHandler Dim v As Variant v = col(index) ExistsNonObject = True Exit Function ExistsNonObjectErrorHandler: ExistsNonObject = False End Function </code></pre> <p>And to verify the functionality:</p> <pre><code>Public Sub TestExists() Dim c As New Collection Dim b As New Class1 c.Add "a string", "a" c.Add b, "b" Debug.Print "a", Exists(c, "a") ' True ' Debug.Print "b", Exists(c, "b") ' True ' Debug.Print "c", Exists(c, "c") ' False ' Debug.Print 1, Exists(c, 1) ' True ' Debug.Print 2, Exists(c, 2) ' True ' Debug.Print 3, Exists(c, 3) ' False ' End Sub </code></pre>
<p>While looking for a function like this i designed it as following. This should work with objects and non-objects without assigning new variables.</p> <pre><code>Public Function Exists(ByRef Col As Collection, ByVal Key) As Boolean On Error GoTo KeyError If Not Col(Key) Is Nothing Then Exists = True Else Exists = False End If Exit Function KeyError: Err.Clear Exists = False End Function </code></pre>
6,188
<p>Does IPsec in Windows XP Sp3 support AES-256 encryption?</p> <p><strong>Update:</strong></p> <ol> <li>Windows IPsec FAQ says that it's not supported in Windows XP, but maybe they changed it in Service Pack 3?<br> http://www.microsoft.com/technet/network/ipsec/ipsecfaq.mspx<br> Question: <em>Is Advanced Encryption Standard (AES) encryption supported?</em><br><br> </li> <li>origamigumby, please specify where, because I cannot find it.</li> </ol>
<p>You may well be starving the stack. It is pretty easy to drain in a high open/close transactions per second environment e.g. webserver serving lots of unpooled requests. </p> <p>This is exhacerbated by the default TIME-WAIT delay - the amount of time that a socket has to be closed before being recycled defaults to 90s (if I remember right)</p> <p>There are a bunch of registry keys that can be tweaked - suggest at least the following keys are created/edited</p> <pre><code>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters TcpTimedWaitDelay = 30 MaxUserPort = 65534 MaxHashTableSize = 65536 MaxFreeTcbs = 16000 </code></pre> <p>Plenty of docs on MSDN &amp; Technet about the function of these keys.</p>
<p>I guess the port number comment from RichS is correct.</p> <p>Other than that, the TCP/IP stack is just a module in your operating system and, as such, can have bugs that might allow an application to kill it. It wouldn't be the first driver to be killed by a program.</p> <p>(A tip to the hat towards Andrew Tanenbaum for insisting that operating systems should be modular instead of monolithic.)</p>
16,156
<p>Here's the situation: I have a label's text set, immediately followed by a response.redirect() call as follows (this is just an example, but I believe it describes my situation accurately):</p> <p>aspx:</p> <pre><code>&lt;asp:Label runat="server" Text="default text" /&gt; </code></pre> <p>Code-behind (code called on an onclick event):</p> <pre><code>Label.Text = "foo"; Response.Redirect("Default.aspx"); </code></pre> <p>When the page renders, the label says "default text". What do I need to do differently? My understanding was that such changes would be done automatically behind the scenes, but apparently, not in this case. Thanks.</p> <p>For a little extra background, the code-behind snippet is called inside a method that's invoked upon an onclick event. There is more to it, but I only included that which is of interest to this issue.</p>
<p>A <code>Response.Redirect</code> call will ask the user's browser to load the page specified in the URL you give it. Because this is a new request for your page the page utilises the text which is contained in your markup (as I assume that the label text is being set inside a button handler or similar).</p> <p>If you remove the <code>Response.Redirect</code> call your page should work as advertised.</p>
<p>So, if I may answer my own question (according to the FAQ, that's encouraged), the short answer is, you don't persist view state through redirects. View state is for postbacks, not redirects.</p> <p>Bonus: <a href="http://msdn.microsoft.com/en-us/library/ms972976.aspx#viewstate_topic10" rel="nofollow noreferrer">Everything you ever wanted to know about View State in ASP.NET</a>, with pictures!</p>
12,941
<p>The following snippet of C# code:</p> <pre><code> int i = 1; string result = String.Format("{0},{1},{2}", i++, i++, i++); Console.WriteLine(result); </code></pre> <p>writes out: 1,2,3</p> <p>Before I tried this in the compiler I was expecting the assignments to take place and then the evaluations, so my expected output was: 1,1,1</p> <p>So my question is: Does this "pattern" (is it called a pattern?) of assign and then evaluate each parameter have a name?</p> <p>EDIT: I'm referring to the pattern of evaluating and assigning the parameters to the String.Format() function. Not the incrementing of i.</p> <p>(I may be incorrectly using the word evaluate in the question above because if the parameter was say (i + j) then we know that it would be evaluated before it was assigned. When using the word evaluate in that context I'm referring to the incrementing of i.)</p>
<p>The <strong>order of evaluation</strong> of arguments is strictly left-to-right in C#. When you evaluate the expression <code>i++</code>, what happens is the value of <code>i</code> is calculated and pushed, then the value of <code>i</code> is incremented.</p> <p>The ++ operator on System.Int32 is effectively a function with the special name <code>++</code> and the special syntax of calling it by writing a reference to a variable and then the characters ++.</p> <p>So in effect, what you wrote is</p> <pre><code>// assume this function is defined: int Inc(ref int i) { var old = i; i = i + 1; return old; } ... int i = 1; string result = String.Format("{0},{1},{2}", Inc(ref i), Inc(ref i), Inc(ref i)); Console.WriteLine(result); ... </code></pre> <p>Since arguments are evaluated left-to-right, <code>Inc(ref i)</code> is called 3 times, each time incrementing <code>i</code> after passing the current value of <code>i</code> to <code>String.Format(...)</code>. This is exactly what happens in your code, as well.</p>
<p>The arguments of a function are evaluated <a href="http://msdn.microsoft.com/en-us/library/aa691335.aspx" rel="nofollow noreferrer">left-to-right in C#</a>. This is not the case in C/C++, where the standard says the order of evaluation is undefined.</p>
19,926
<p>I'm writing an interpreter for an experimental language. Three of the main constructs of the language are definitions, statements, and expressions. Definitions can contain statements and expressions, statements can contain definitions and expressions, and one kind of expression can contain statements. I represent all of these using union types so I can easily use pattern matching on them. Ideally, I would like to put the code for these in different files, but OMake complains about circular dependency issues. As far as I know, circular type definitions across modules are not allowed.</p> <p>The only way I know of to solve this is to define all three types at once:</p> <pre><code>type defn = ... and stmt = ... and expr = ... </code></pre> <p>It seems like this requires all the code for types to be in the same file. Is there any way around this? How do you deal with circular definitions in your code?</p>
<p>Recursive definitions need to appear in the same file. If you want to separate definitions, statements, and expressions into separate modules, you can do so using <a href="http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#htoc100" rel="noreferrer">recursive modules</a>, but they will still need to appear in the same file. DAG-ifying inter-file dependencies is one of the annoyances of OCaml.</p>
<p>Another solution often used is to abstract the types in the interfaces. Since the types are abstract in the interfaces, these interfaces are not recursively dependent. In the implementations, you can specify the types, and since the implementations depend only on the interfaces, they are not recursive either.</p> <p>The only problem is that, with this solution, you cannot anymore pattern-matching on these types outside of their implementation.</p> <p>Personally, but it is probably a matter of taste, I like to have all the types of my program defined in one module (I think it helps in the readability of the program). So, this restriction of OCaml is not really a problem for me.</p>
5,691
<p>Our windows deliverable has different sets of config files and binary assets for different customers. Right now the configuring is done by hand before packaging and its error prone. What do you think of using branches for each customer, and having the package build/script automerge the customer's branch with trunk?</p> <p>I'm less concerned with scalability than I am of getting this automated ASAP.</p> <p>The entire packag contents is in SVN, but SVN branching and merging is so delicate that I don't trust it to work consistently when its automated. If you guys like the idea I might try to use git-svn for this, because it will hopefully make merging less delicate. We don't necessarily have to merge the assets, because they are organized so the installer can just skip inappropriate directory trees, but configuration is not so simple.</p>
<p>I suppose it depends on how many things have to change. For config files, I like to keep a single file under source control and use a build script to set the environment-specific (or in your case client-specific) items.</p> <p><a href="http://automaticchainsaw.blogspot.com/2008/02/automate-config-changes-for-different.html" rel="nofollow noreferrer">http://automaticchainsaw.blogspot.com/2008/02/automate-config-changes-for-different.html</a></p> <p>For binaries, it probably has more to do with how many of them you have and where they come from. If they are part of a code compile, then the compilation process ideally would create what you need. If they are other resources, such as graphics, perhaps you have a customer-specific set of folders under one directory. The build script would pull in the correct client folder based on a parameter passed to the script. This is basically the branch and merge idea you mentioned in your question.</p> <p>Regarding your later comment about multi-line config changes - assuming it is xml, you might look at the XmlMassUpdate class in the MSBuild Community Tasks. I've not used it myself, but it looks like it might be what you need.</p>
<p>You don't mention which language, but you might consider doing <a href="http://msdn.microsoft.com/en-us/library/x435tkbk(VS.80).aspx" rel="nofollow noreferrer">conditional compilation</a>:</p> <pre><code>#If FirstCustomer Then ' &lt;code specific to the FirstCustomer version&gt;. #ElseIf SecondCustomer Then ' &lt;code specific to the SecondCustomer version&gt;. #Else ' &lt;code specific to other versions&gt;. #End If </code></pre>
35,594
<p>This would be a question for anyone who has code in the App_Code folder and uses a hardware load balancer. Its true the hardware load balancer could be set to sticky sessions to solve the issue, but in a perfect world, I would like the feature turned off.</p> <p>When a file in the App_Code folder, and the site is not pre-compiled iis will generate random file names for these files.</p> <pre><code>server1 "/ajax/SomeControl, App_Code.tjazq3hb.ashx" server2 "/ajax/SomeControl, App_Code.wzp3akyu.ashx" </code></pre> <p>So when a user posts the page and gets transfered to the other server nothing works.</p> <p>Does anyone have a solution for this? I could change to a pre-compiled web-site, but we would lose the ability for our QA department to just promote the changed files.</p>
<p>Do you have the &lt;machinekey&gt; node on both servers set to the same value?</p> <p>You can override the machine.config file in web.config to set this. This needs to match otherwise you can get strange situations like this.</p>
<p>If it's a hardware load balancer, you shouldn't have an issue, because all that is known there is the request URL, in which the server would compile the requested page and serve it.</p> <p>the only issue i can think of that you might have is with session and view state.</p>
7,355
<p>We have a large (about 580,000 loc) application which in Delphi 2006 builds (on my machine) in around 20 seconds. When you have build times in seconds, you tend to use the compiler as a tool. i.e. write a little code, build, write some more code and build some more etc etc As we move some of our stuff over to C#, does anyone have a comparison of how long something that size would take to build? I only have small apps and components at the moment, so can't really compare. If things are going to take a lot longer to build, then I may need to change my style! Or is my style just lazy?</p> <p>For example, if I'm changing the interface of a method call, rather than do a full search on all the app to find out where I need to make changes to calls, I'll use the compiler to find them for me.</p>
<p>Visual Studio 2008 SP1 now has background compilation for C# (it's always had it for VB.NET). Back in my VB days, I often used this to find where something was referenced by changing the name and then seeing where the background compiler said there was an error.</p> <p>I never worked on anything quite this large. At my last job we had about 60,000 loc spread over about 15 projects and it took about 10 seconds to compile. Maybe someone else can post a slightly larger case study</p>
<p>Well, compiler doesn't have to be that fast to take advantage of it. Some IDEs support incremental compilation on every file save, or either on-the-fly. This works great.</p>
38,798
<p>I'm looking for articles, forum or blog posts dealing with SharePoint and thread safety? I'm quite sure there are some special aspects regarding thread safety that have to be considered when working with the SharePoint object model.</p> <p>Actually I didn't find many information about this, yet.</p> <p>So I'm looking forward to your answers. </p> <p>Bye, Flo</p>
<p>There are much worse pitfalls in the SharePoint OM than just plain old thread safety. Pay particular attention to working with objects retrieved from properties. You should <em>always</em> keep a pointer to an object while you work on it; example:</p> <pre><code>var list = web.List["MyList"] list.Items[0]["Field1"] = "foo" list.Items[0]["Field2"] = "bar" list.Items[0].Update() // nothing is updated! </code></pre> <p>You might expect Field1 and Field2 to be updated by the final Update() call, but nope. Each time you use the indexer, a NEW reference to the SPListItem is returned. </p> <p>Correct way:</p> <pre><code>SPListItem item = list.Items[0] item["Field1"] = "foo" item["Field2"] = "bar" item.Update() // updated! </code></pre> <p>Just a start. Also google for pitfalls around the IDisposabe/Dispose pattern.</p> <p>-Oisin</p>
<p>So after doing some more googling and searching on the web and testing, it seems as if you don't have to care about thread-safety that much when using the MOSS object model because you're always working with non-static and unique instances. </p> <p>Furthermore an exception is thrown when a object e.g. a SPWeb was altered and saved by calling the Update() method before you saved your changes (also calling the Update() method) even though you got your object first. </p> <p>In the following example the instruction <code>web11.Update()</code> will throw an exception telling you that the SPWeb represented through the object web12 was altered meanwhile. </p> <pre><code>SPSite siteCol1 = new SPSite("http://localhost"); SPWeb web11 = siteCol1.OpenWeb(); SPWeb web12 = siteCol1.OpenWeb(); web12.Title = "web12"; web12.Update(); web11.Title = "web11"; web11.Update(); </code></pre> <p>So the thready-safety seems to be handled by the object model itself. Of course you have to handle the exceptions that might be thrown due to race conditions. </p>
40,576
<p>I am reading over the K&amp;R book, and am a little stuck.</p> <p>What is wrong with the following?</p> <pre><code>void getInput(int* output) { int c, i; for(i=0; (c = getchar()) != '\n'; i++) output[i] = c; // printf("%c", c) prints the c value as expected output[++i] = '\0'; } </code></pre> <p>When I run the program it never gets out of the loop and I have to <kbd>Ctrl+C</kbd> to exit. However if I replace the fifth line with <code>printf("%c", c);</code>, it prints out all the input just fine after hitting enter and creating the new line.</p>
<blockquote> <p>What is wrong with the following?</p> </blockquote> <pre><code>1. void getInput(int* output) { </code></pre> <p>Why is the input argument an int* when what you want to store in an array of characters? Probably </p> <pre><code>void getInput(char* output) { </code></pre> <p>is better. </p> <p>Also, how do you know that the output pointer is pointing somewhere where you hold enough memory to write the user's input? Maybe you must have the maximum buffer length as an extra parameter to avoid buffer overflow errors as <a href="https://stackoverflow.com/questions/224562/basic-c-question#224581">PW pointed out</a>.</p> <pre><code>5. output[++i] = '\0'; </code></pre> <p>i has already been incremented an extra time inside the for loop, so you can just do:</p> <pre><code>output[i] = '\0'; </code></pre> <p>Other than these, the program runs fine and outputs what we input until return.</p> <p>FWIW, I tested it by calling it like so:</p> <pre><code> int main(void) { char o[100]; getInput(o); printf("%s", o); return 0; } </code></pre>
<p>a simple way to risk buffer overflow, because output's size is never passed/checked</p>
27,748
<p>I am developing Eclipse plugins, and I need to be able to automate the building and execution of the test suite for each plugin. (Using Junit)</p> <p>Test are working within Eclipse, and I can break the plugins into the actual plugin and a fragment plugin for unit testing as described <a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.test/testframework.html?view=co" rel="nofollow noreferrer">here</a>, <a href="http://rcpquickstart.com/2007/08/06/running-automated-tests-with-pde-build/" rel="nofollow noreferrer">here</a> and in a couple places <a href="http://eclipsenuggets.blogspot.com/2007/09/6-great-links-for-eclipse-build.html" rel="nofollow noreferrer">here</a>.</p> <p>However, each of the approaches above results in the same issue: The java ant task/commandline command that issues the build or should trigger the test, generates no observable side effects, and returns the value "13". I've tried everything I can find, and I've learned a fair bit about how Eclipse starts up (eg: since v3.3 you can no longer use startup.jar -- it doesn't exist -- but you should use <a href="http://blog.ciscavate.org/2008/11/treat-your-mailing-lists-like-reference-documents-please.html" rel="nofollow noreferrer">org.eclipse.equinox.launcher</a>). Unfortunately, while that is apparently necessary information, it is far from sufficient.</p> <p>I am working with Eclipse 3.4, Junit 4.3.1 (the org.junit4 bundle, but I would much rather use JUnit 4.4. See <a href="https://stackoverflow.com/questions/251791">here</a>.)</p> <p>So, my question is: How exactly do you automate the build and testing of Eclipse plugins? </p> <p><em>Edit:</em> To clarify, I <em>want</em> to use something like ant + cruise control, but I can't even get the unit tests to run <em>at all</em> outside of Eclipse. I say "something like" because there are other technologies that accomplish the same thing, and I am not so picky as to discard a solution that works just because it's using say, Maven or Buckminster, if those technologies make this substantially easier.</p> <p><em>Edit2:</em> The 'Java Result 13' mentioned above seems to be caused by the inability to find the coretestrunner. From the log:</p> <pre><code>java.lang.RuntimeException: Application "org.eclipse.test.coretestapplication" could not be found in the registry. The applications available are: org.eclipse.equinox.app.error, com.rcpquickstart.helloworld.application. at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:242) at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:29) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504) at org.eclipse.equinox.launcher.Main.run(Main.java:1236) at org.eclipse.equinox.launcher.Main.main(Main.java:1212) at org.eclipse.core.launcher.Main.main(Main.java:30) !ENTRY org.eclipse.osgi 2 0 2008-11-04 21:02:10.514 !MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists: !SUBENTRY 1 org.eclipse.osgi 2 0 2008-11-04 21:02:10.515 !MESSAGE Bundle update@plugins/org.eclipse.test_3.2.0/ [34] was not resolved. !SUBENTRY 2 org.eclipse.test 2 0 2008-11-04 21:02:10.516 !MESSAGE Missing required bundle org.apache.ant_0.0.0. !SUBENTRY 2 org.eclipse.test 2 0 2008-11-04 21:02:10.516 !MESSAGE Missing required bundle org.eclipse.ui.ide.application_0.0.0. !SUBENTRY 1 org.eclipse.osgi 2 0 2008-11-04 21:02:10.518 !MESSAGE Bundle update@plugins/org.eclipse.ant.optional.junit_3.2.100.jar [60] was not resolved. !SUBENTRY 2 org.eclipse.ant.optional.junit 2 0 2008-11-04 21:02:10.519 !MESSAGE Missing host org.apache.ant_[1.6.5,2.0.0). !SUBENTRY 2 org.eclipse.ant.optional.junit 2 0 2008-11-04 21:02:10.519 !MESSAGE Missing required bundle org.eclipse.core.runtime.compatibility_0.0.0. </code></pre>
<p>I have just got JUnit testing working as part of the headless build for our RCP application. </p> <p>I found this article - <a href="http://www.eclipse.org/articles/article.php?file=Article-PDEJUnitAntAutomation/index.html" rel="noreferrer">Automating Eclipse PDE Unit Tests using Ant</a> incredibly helpful. It provides code and approach to get you started. However, a number of things that I discovered:</p> <h2>About the article's code</h2> <ul> <li>there was only one bundle under tests (we have separated out our build process from the code, using <a href="http://wiki.eclipse.org/Buckminster_Project" rel="noreferrer">Buckminster</a>)</li> <li>there was only one test class. </li> <li>these were both effectively hardcoded into the build script</li> </ul> <h2>About Eclipse PDE</h2> <ul> <li>the <code>uitestapplication</code> requires another <code>testApplication</code>. Using <code>coretestapplication</code> does not. </li> <li>as these applications are both in bundles that have dependencies on SWT. This is a deal killer in most circumstances, though not if your build machine is a Windows box. I would love to see these split into non-UI bundles.</li> </ul> <p>I found that the code provided was a good starting point, but had a number of the above assumptions implicit in their implementation.</p> <p>Having discovered these assumptions, doing the work was relatively straight forward.</p> <h2>Our new and shiny setup</h2> <ul> <li>buckminster builds the bundles. </li> <li>target copies the bundles from the target platform, the org.eclipse.pde.runtime and org.eclipse.jdt.junit into a "tester-eclipse-install". This should take care of your <code>Java Result 13</code> problem.</li> <li>find the test fragments from looking at the workspace</li> <li>find the fragment host from looking at the manifest</li> <li>find the test classes from looking at the project in the workspace.</li> <li>register a <code>PDETestListener</code> modified to handle multiple test classes</li> <li>invoke the tester-eclipse-install with the multiple test classes.</li> </ul> <p>I also read <a href="http://www.eclipse.org/articles/Article-PDE-Automation/automation.html" rel="noreferrer">Build and Test Automation for plug-ins and features</a> but we are not using PDE-Build directly. </p>
<p>Here is a Tool which I can recommand if someone is interrested by TDD : <a href="http://www.junit.org/node/343" rel="nofollow noreferrer">Infinitest</a></p> <p>Short description extracted from the Infinitest site:</p> <blockquote> <p>What is Infinitest?</p> <p>Infinitest is a continuous test runner designed to facilitate Test Driven Development. Infinitest helps you learn TDD by providing feedback as you work, and helps you master TDD by reducing your feedback cycle from minutes to mere seconds.</p> <p>Whenever you change a class, Infinitest runs your tests for you. It's smart about what tests to run, and only runs the ones you need. If any errors occur, it reports them clearly and concisely. This gives you instant feedback about the semantic correctness of your code, just as modern IDE's give you instant feedback about syntax errors.</p> </blockquote>
31,860
<p>I have a client that is asking me to give them a listing of every file and folder in the source code (and then a brief explanation of the source tree). Is there an easy way to create some sort of decently formatted list like this from a subversion repository?</p>
<p>You'll want the list command. Assuming you're using the command line client</p> <pre><code>svn list -R http://example.com/path/to/repos </code></pre> <p>This will give you a full recursive list of everything that's in the repository. Redirect it to a text file</p> <pre><code>svn list -R http://example.com/path/to/repos &gt; file.txt </code></pre> <p>and then format to your heart's content.</p>
<p>Assuming it's available via HTTP - why not just give them a read-only login, and point them at the web address?</p>
12,497
<p>Is it possible to re-use ABS or PLA filament material from printed parts?</p> <p>If so, what is the techniques to reform it?</p>
<p>There are a few options.</p> <ol> <li>Machines are available which grind the used plastic into fine pieces, melt it down, and extrude it as filament to be reused. <a href="http://www.filabot.com/">Filabot</a> is perhaps the most well known.</li> <li>Depending on where you live the local recycling programs may accept PLA or ABS. They will then shred it and melt it down for reuse.</li> <li>PLA is bio-degradable so you can put it in the compost.</li> <li>I put scrap ABS in acetone which results in a slurry which can be used as a glue to attach ABS parts, fix cracks, and hold parts to the bed.</li> </ol>
<p>If you're more interested in the recycling and reuse aspect than the re-print aspect, you could melt all the scrap filament onto a cookie sheet or into a bar (like in a bread ban). You could then manually work the material, or use a CNC machine to carve out your next thing.</p> <p>This <a href="https://www.youtube.com/watch?v=kUR6_bQLU-E" rel="nofollow noreferrer">Youtube video</a> refers to HDPE, but the same concept will apply to other thermoplastics:</p> <p><div class="youtube-embed"><div> <iframe width="640px" height="395px" src="https://www.youtube.com/embed/kUR6_bQLU-E?start=0"></iframe> </div></div></p> <p>This <a href="https://www.youtube.com/watch?v=G-HWrDMr0ks" rel="nofollow noreferrer">Youtube video</a> uses a cookie sheet and failed prints:</p> <p><div class="youtube-embed"><div> <iframe width="640px" height="395px" src="https://www.youtube.com/embed/G-HWrDMr0ks?start=0"></iframe> </div></div></p>
101
<p>Is either:</p> <pre><code>&lt;a href="#"&gt;&lt;h1&gt;text here&lt;/h1&gt;&lt;/a&gt; </code></pre> <p>or</p> <pre><code>&lt;h1&gt;&lt;a href="#"&gt;text here&lt;/a&gt;&lt;/h1&gt; </code></pre> <p>"correct". Is there any benefit of using the first one, it seems more logical to me. Perhaps from an SEO point?</p>
<pre><code>&lt;h1&gt;&lt;a href="#"&gt;text here&lt;/a&gt;&lt;/h1&gt; </code></pre> <p>is correct, as HTML does not allow a block element (<code>&lt;h1&gt;</code>) within an inline element (<code>&lt;a&gt;</code>) (<a href="http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.3" rel="nofollow noreferrer">src</a>). your first example will fail <a href="http://validator.w3.org/#validate_by_input" rel="nofollow noreferrer">validation</a>.</p> <blockquote> <p>Generally, block-level elements may contain inline elements and other block-level elements. Generally, inline elements may contain only data and other inline elements. Inherent in this structural distinction is the idea that block elements create "larger" structures than inline elements.</p> </blockquote>
<p>There ain't really much difference in this particular case. There are some things to point out though:</p> <ul> <li><code>&lt;h*&gt;</code> are block elements, <code>&lt;a&gt;</code> is an inline element by default. As others pointed out, XHTML does not allow block elements in inline elements, so if you did not redefine their display style in CSS, <code>&lt;a&gt;&lt;h1&gt;&lt;/h1&gt;&lt;/a&gt;</code> is invalid.</li> <li><code>&lt;a href="#"&gt;&lt;h1&gt;text here&lt;/h1&gt;&lt;/a&gt;</code> is a link that can have multiple child nodes. In this case, it only has a <code>&lt;h1&gt;</code> child node, but nothing is stopping you from adding more.</li> <li>On the other hand, <code>&lt;h1&gt;&lt;a href="#"&gt;text here&lt;/a&gt;&lt;/h1&gt;</code> is a header that can cave multiple nodes. You can add all sorts of child nodes to it, like labels, etc.</li> </ul> <p>So this is basically a logical difference without any practical differences in this particular case.</p>
39,719
<p>I've written up a weekly-review GTD checklist for myself in TiddlyWiki, using <a href="http://www.tiddlytools.com/#CheckboxPlugin" rel="nofollow noreferrer">CheckboxPlugin</a>. After I'm finished with it each week, I'd like to click one link to uncheck (reset) all of the items on it, so it's ready for the next use.</p> <p>I'm storing the check information as tags on a separate tiddler page. I should be able to just erase all the tags on that page and refresh the checklist page, but I haven't been able to work out how to do that yet.</p> <p>I generally work in C, C++, and Lisp, I'm just learning about Javascript. Can anyone offer some useful pointers?</p> <p>(And before anyone suggests it, I've looked at the ChecklistScript on the same site. It doesn't use the CheckboxPlugin stuff, and isn't compatible with it.)</p>
<p>Try this (adapted from ChecklistScript's "resetall" code):</p> <pre><code>&lt;html&gt;&lt;form style="display:inline"&gt; &lt;input type="button" value="clear all" onclick=" var tid='SomeTiddler'; var list='tag1 [[tag 2]] tag3 tag4'; var tags=list.readBracketedList(); store.suspendNotifications(); for (var t=0; t&lt;tags.length; t++) store.setTiddlerTag(tid,false,tags[t]); store.resumeNotifications(); story.refreshTiddler(tid,null,true); "&gt;&lt;/form&gt;&lt;/html&gt; </code></pre>
<p>Try this (adapted from ChecklistScript's "resetall" code):</p> <pre><code>&lt;html&gt;&lt;form style="display:inline"&gt; &lt;input type="button" value="clear all" onclick=" var tid='SomeTiddler'; var list='tag1 [[tag 2]] tag3 tag4'; var tags=list.readBracketedList(); store.suspendNotifications(); for (var t=0; t&lt;tags.length; t++) store.setTiddlerTag(tid,false,tags[t]); store.resumeNotifications(); story.refreshTiddler(tid,null,true); "&gt;&lt;/form&gt;&lt;/html&gt; </code></pre>
20,761
<p>I've always been interested in developing a web search engine. What's a good place to start? I've heard of Lucene, but I'm not a big Java guy. Any other good resources or open source projects?</p> <p>I understand it's a huge under-taking, but that's part of the appeal. I'm not looking to create the next Google, just something I can use to search a sub-set of sites that I might be interested in.</p>
<p>There are several parts to a search engine. Broadly speaking, in a hopelessly general manner (folks, <strong>feel free to edit</strong> if you feel you can add better descriptions, links, etc):</p> <ol> <li><p><strong>The crawler</strong>. This is the part that goes through the web, grabs the pages, and stores information about them into some central data store. In addition to the text itself, you will want things like the time you accessed it, etc. The crawler needs to be smart enough to know how often to hit certain domains, to obey the robots.txt convention, etc. </p></li> <li><p><strong>The parser</strong>. This reads the data fetched by the crawler, parses it, saves whatever metadata it needs to, throws away junk, and possibly makes suggestions to the crawler on what to fetch next time around.</p></li> <li><p><strong>The indexer</strong>. Reads the stuff the parser parsed, and creates inverted indexes into the terms found on the webpages. It can be as smart as you want it to be -- apply NLP techniques to make indexes of concepts, cross-link things, throw in synonyms, etc.</p></li> <li><p><strong>The ranking engine</strong>. Given a few thousand URLs matching "apple", how do you decide which result is the best? Jut the index doesn't give you that information. You need to analyze the text, the linking structure, and whatever other pieces you want to look at, and create some scores. This may be done completely on the fly (that's really hard), or based on some pre-computed notions of "experts" (see PageRank, etc).</p></li> <li><p><strong>The front end</strong>. Something needs to receive user queries, hit the central engine, and respond; this something needs to be smart about caching results, possibly mixing in results from other sources, etc. It has its own set of problems.</p></li> </ol> <p>My advice -- choose which of these interests you the most, download Lucene or Xapian or any other open source project out there, pull out the bit that does one of the above tasks, and try to replace it. Hopefully, with something better :-). </p> <p>Some links that may prove useful: <a href="http://www.scribd.com/doc/100903/Agile-webcrawler-design-and-implementation" rel="noreferrer">"Agile web-crawler"</a>, a paper from Estonia (in English) <a href="http://sphinxsearch.com" rel="noreferrer" title="Sphinx search engine">Sphinx Search engine</a>, an indexing and search api. Designed for large DBs, but modular and open-ended. <a href="http://www-csli.stanford.edu/~hinrich/information-retrieval-book.html" rel="noreferrer">"Information Retrieval</a>, a textbook about IR from Manning et al. Good overview of how the indexes are built, various issues that come up, as well as some discussion of crawling, etc. Free online version (for now)!</p>
<p>There are ports of Lucene. Zend have one freely available. Have a look at this quick tutorial: <a href="http://devzone.zend.com/node/view/id/91" rel="nofollow noreferrer">http://devzone.zend.com/node/view/id/91</a></p>
13,740
<p>I'm just reading Code Complete by Steve McConell and I'm thinking of an Example he gives in a section about loose coupling. It's about the interface of a method that calculates the number of holidays for an employee, which is calculated from the entry date of the employee and her sales. The author suggests a to have entry date and sales as the parameters of the method instead of an instance of the employee:</p> <pre><code>int holidays(Date entryDate, Number sales) </code></pre> <p>instead of </p> <pre><code>int holidays(Employee emp) </code></pre> <p>The argument is that this decouples the client of the method because it does not need to know anything about the Employee class.</p> <p>Two things came to my mind:</p> <ol> <li><p>Providing all the parameters that are needed for the calculation breaks encapsulation. It shows the internals of the method on how it computes the result.</p></li> <li><p>It's harder to change, e.g. when someone decides that also the age of the employee should be included in the calculation. One would have to change the signature.</p></li> </ol> <p>What's your opinion?</p>
<p>The problems I see with your argument number 2 are</p> <ol> <li><p>you are assuming every needed value comes from an Employee instance. This is by no means always true. For example, say you have to consider the financial state of the company to calculate how much 'bonus holiday' give to any employee. Would you add financial state information to the employee class to avoid changing the signature? </p></li> <li><p>changing a signature is not necessarily "harder", especially so in these days of tools that will highlight every calling place at the click of a button.</p></li> </ol> <p>And the main problem with your argument number 1 is that it just doesn't break encapsulation as everyone else has said. You are showing the what, not the how, which is what encapsulation is about.</p>
<p>I would say that one of the major benefits of loose coupling is the ease of change. Loosely coupled types can change independently of each other so I don't understand your "vs" in the question.</p> <p>Additionally, I would not say that you break encapsulation by providing parameters for the method. You can implement a <code>Sum(int a, int b)</code> anyway you want - but you have to tell me (as the user) that you expect two numbers. </p>
47,266
<p>In WPF, there are two ways to set the focus to an element.<br> You can either call the .Focus() method of the input element, or call Keyboard.Focus() with the input element as parameter.</p> <pre><code>// first way: item.Focus(); // alternate way: Keyboard.Focus(item); </code></pre> <p>What is the difference between these two? Are there special reasons to use one of them instead of the other in some cases?<br> So far I noticed no difference - what ever method I used, the item always got logical focus as well as keyboard focus.</p>
<p>One of the first things that <code>item.Focus()</code> does is call <code>Keyboard.Focus( this )</code>. If that fails, then it makes calls to <code>FocusManager</code>, as decasteljau has answered.</p> <p>The following are copied from disassambler view in <a href="http://reflector.red-gate.com/" rel="noreferrer">Reflector</a>.</p> <p>This is from <code>UIElement</code> (<code>UIElement3D</code> is the same):</p> <pre><code>public bool Focus() { if (Keyboard.Focus(this) == this) { return true; } if (this.Focusable &amp;&amp; this.IsEnabled) { DependencyObject focusScope = FocusManager.GetFocusScope(this); if (FocusManager.GetFocusedElement(focusScope) == null) { FocusManager.SetFocusedElement(focusScope, this); } } return false; } </code></pre> <p>This is from <code>ContentElement</code>:</p> <pre><code>public bool Focus() { return (Keyboard.Focus(this) == this); } </code></pre>
<p>Also, you may want to know that item.Focus() is the equivalent of calling:</p> <pre><code>DependencyObject focusScope = FocusManager.GetFocusScope(item); if (FocusManager.GetFocusedElement(focusScope) == null) { FocusManager.SetFocusedElement(focusScope, item); } </code></pre>
23,960
<p>Can somebody tell me how to use the <em><code>printWhenExpression</code></em> of JasperReports?</p>
<p>Do you have an error relative to boolean ?</p> <p>Because you need to use Boolean instead of the primitive type.</p> <p>So: </p> <pre><code>$F{mesure} != "PH" ($F{userfd4}).equals("1") ? true : false </code></pre> <p>would give <code>cannot cast from boolean to Boolean</code>.</p> <pre><code>( $F{mesure}.startsWith("PH") ? Boolean.TRUE:Boolean.FALSE ) ($F{userfd4}).equals("1") ? Boolean.TRUE : Boolean.FALSE </code></pre> <p>would be correct.</p> <p>See also this <a href="http://jasperforge.org/plugins/espforum/view.php?group_id=83&amp;forumid=101&amp;topicid=47713" rel="nofollow noreferrer">example</a></p> <hr> <p>Update Nov 2015 (7 years later)</p> <p><a href="https://stackoverflow.com/users/5292302/petter-friberg">Petter Friberg</a> points out <a href="https://stackoverflow.com/questions/294989/how-to-use-printwhenexpression-in-jasperreports/294999?noredirect=1#comment55033358_294999">in the comments</a>:</p> <blockquote> <p>In <a href="https://en.wikipedia.org/wiki/JasperReports" rel="nofollow noreferrer">jasper report</a> 6.0 this is not need:<br> You can return either <code>boolean</code> or <code>Boolean</code> a simple expression like <code>$F{fieldName}.equals("hello")</code> will work.</p> </blockquote> <hr> <p>You can see a demo of that command in <a href="https://github.com/TIBCOSoftware/jasperreports/blob/89055a52f85c589ff08f0a72d0108ecf17a388e6/jasperreports/demo/samples/tableofcontents/reports/TocPart.jrxml#L61-L68" rel="nofollow noreferrer"><code>demo/samples/tableofcontents/reports/TocPart.jrxml</code></a></p> <pre><code>&lt;reportElement style="Sans_Bold" positionType="Float" x="50" y="0" width="100" height="15" isRemoveLineWhenBlank="true" uuid="db8b68c6-4430-4199-8967-3ab5c077cb56"&gt; &lt;property name="local_mesure_unitx" value="pixel"/&gt; &lt;property name="com.jaspersoft.studio.unit.x" value="px"/&gt; &lt;printWhenExpression&gt;&lt;![CDATA[$F{level} == 1]]&gt;&lt;/printWhenExpression&gt; &lt;/reportElement&gt; </code></pre>
<p>$P{mesure}.equals("200") should work without any additional details. It will print if the condition is true</p>
37,670
<p>I have findbugs plugin for eclipse which when run on my project will show results in Bugs explorer clubbed by the type of bug.</p> <p>I need to be able to do two things:</p> <ul> <li>Export all these to excel sheet</li> <li>Find out the bugs reported in a set of files (and be able to do it recursively w/o running for whole project and exporting and finding out the classes to be modified.</li> </ul> <p>Any suggestions?</p> <p>FYI, I am using MyEclipse v 6.0.1 and FindBugs 1.3.4</p>
<p>Findbugs dumps its results into an XML file in your workspace's .metadata folder. Look for the subfolder that's named something like findbugs.</p> <p>You can also download a standalone version of Findbugs that will save the results wherever you like.</p> <p>Once you have the results file, you might be able to import from XML to Excel and filter there. Alternatively, you can use XSLT to transform to several CSV files and open them in Excel.</p>
<p>I had the same problem with findbugs some versions ago.</p> <p>I updated the plugin today to version 1.3.8 and found out that you can now export and even import reports as XML directly. </p> <p>All you have to do is right-click on a project either in the package explorer or in the findbugs "Bug explorer" and select "Findbugs->Save XML" or "Findbugs->Load XML".</p> <p>Finely a proper export and import functionality for a fantastic tool.</p> <p>Btw, I use Eclipse 3.3.2.</p>
6,853
<p>We are beginning to go down the path of mobile browser support for an enterprise e-commerce webapp (Java/Servlet based). Of course there are many decisions to be made, but it seems to me the cornerstone is to be able to reliably detect mobile browsers, and make decisions on the content to be returned accordingly. Is there a standard way to make this determination (quickly) based on the http request, and ideally glean more information about the given browser and device making the request (screen size, html capabilities, etc?).</p> <p>I would also appreciate any supplemental information that would be of use from someone who has gone down this path of taking an existing large scale enterprise webapp and architect-ing out mobile browser support from the development side.</p> <p>[edit] I certainly understand the request header and the information about a database of standard user agents is a great help. For those talking about 'other' request header properties, if you could include similar standardized name / resource of values that would be a big help.</p> <p>[edit] Several users have proposed solutions that involve a call over the wire to some web service that will do the detection. While I'm sure this works, it is not a good solution for an enterprise e-commerce site for two reasons: 1) speed. A call over the wire for every page request to a third party would have huge performance implications. 2) dependency/legal. We'd tie our website response time and key functionality to their service, which is horrible for legal and risk reasons.</p>
<p>Wouldn't the standard way be to check the user agent? Here's a <a href="http://wurfl.sourceforge.net/" rel="noreferrer">database of user agents</a> you can use to detect mobile browsers.</p>
<p>You will have to check the user agent string with a previously defined list, <a href="http://www.zytrax.com/tech/web/mobile_ids.html" rel="nofollow noreferrer">like this one</a></p>
17,199
<p>Does anyone know a simple algorithm to check if a Sudoku-Configuration is valid? The simplest algorithm I came up with is (for a board of size n) in Pseudocode</p> <pre><code>for each row for each number k in 1..n if k is not in the row (using another for-loop) return not-a-solution ..do the same for each column </code></pre> <p>But I'm quite sure there must be a better (in the sense of more elegant) solution. Efficiency is quite unimportant.</p>
<p>You need to check for all the constraints of Sudoku :</p> <ul> <li>check the sum on each row</li> <li>check the sum on each column</li> <li>check for sum on each box</li> <li>check for duplicate numbers on each row</li> <li>check for duplicate numbers on each column</li> <li>check for duplicate numbers on each box</li> </ul> <p>that's 6 checks altogether.. using a brute force approach.</p> <p>Some sort of mathematical optimization can be used if you know the size of the board (ie 3x3 or 9x9)</p> <p><strong>Edit</strong>: explanation for the sum constraint: Checking for the sum first (and stoping if the sum is not 45) is much faster (and simpler) than checking for duplicates. It provides an easy way of discarding a wrong solution. </p>
<p>Let's say int sudoku[0..8,0..8] is the sudoku field.</p> <pre><code>bool CheckSudoku(int[,] sudoku) { int flag = 0; // Check rows for(int row = 0; row &lt; 9; row++) { flag = 0; for (int col = 0; col &lt; 9; col++) { // edited : check range step (see comments) if ((sudoku[row, col] &lt; 1)||(sudoku[row, col] &gt; 9)) { return false; } // if n-th bit is set.. but you can use a bool array for readability if ((flag &amp; (1 &lt;&lt; sudoku[row, col])) != 0) { return false; } // set the n-th bit flag |= (1 &lt;&lt; sudoku[row, col]); } } // Check columns for(int col= 0; col &lt; 9; col++) { flag = 0; for (int row = 0; row &lt; 9; row++) { if ((flag &amp; (1 &lt;&lt; sudoku[row, col])) != 0) { return false; } flag |= (1 &lt;&lt; sudoku[row, col]); } } // Check 3x3 boxes for(int box= 0; box &lt; 9; box++) { flag = 0; for (int ofs = 0; ofs &lt; 9; ofs++) { int col = (box % 3) * 3; int row = ((int)(box / 3)) * 3; if ((flag &amp; (1 &lt;&lt; sudoku[row, col])) != 0) { return false; } flag |= (1 &lt;&lt; sudoku[row, col]); } } return true; </code></pre> <p>}</p>
36,878
<p>I have been tasked with converting several php classes into java classes, which is quickly becoming a nightmare for me. I understand the basic language structure, it being similar to C. It is all of the function calls and class calls that seem to go nowhere and the fact that a var can be declared in the <strong>!middle of an expression!</strong> that is spinning my head, oh and the fact that there is zero "0" documentation.</p> <p>What is the best <strong>method</strong> (and/or) <strong>tool</strong> (and/or) <strong>reference material</strong> to convert the php into java code?</p> <p>edit: There is 3 reasons that I am having to convert the php to java. </p> <ol> <li>The usual reason, my boss told me too.</li> <li>The php is too slow, it is taking <strong>minutes</strong> sometimes to run a request to the server. </li> <li>php is a nightmare to scale and maintain.(at least for us strong typed language types)</li> </ol>
<p>You ask about best practices. I believe a good practice in your case is the approach pleasantly presented by theman: using an automated tool will probably give a bad result: garbage in, garbage out...</p> <p>You have the code: analyze it, in its broad lines if necessary. And re-create it in Java. It might be time-consuming, but not necessarily worse than by doing blind conversion. And you can document on the way, and perhaps use this analysis to find the problematic parts.</p>
<p>I can not imagine that a tool for this is existing. I did something similar with C++ und Java. It is a pain, but the best is to impement it by your self.</p> <p>Or write it in C and create a dll with a jni warpper to call it from Java. This should be the fastet way.</p>
47,492
<p>The MEF team keep saying it is about plug-in model. So, are we talking about UI plugins? How can we use this stuff in non-UI code? I downloaded the code and the examples are all about GUI. Am I guessing it wrong?</p>
<p>Ilya</p> <p>MEF is absolutely not only for UI. Nothing about MEF is UI-dependent, which is why it lives in the System.ComponentModel namespace. You can use MEF in desktop apps, web apps, or services. </p> <p>In terms of samples, thank you for the feedback. We do need better samples that illustrate that it is a non-UI based technology. I think the reason alot of the samples have gravitated around UI is that our chief partners like Visual Studio, are using MEF in desktop apps. I'll talk to the team about some non-UI based samples.</p> <p>Thanks Glenn</p>
<p>If you're talking about Microsoft <a href="http://code.msdn.microsoft.com/mef" rel="nofollow noreferrer">Managed Extensibility Framework</a> then no, it's definitely not just about UI. </p> <p>By doing something visual in the samples you just make it easier for people to understand the concept. You could not make it clearer that an Tetris game with plug-in blocks.</p>
16,918
<p>I'm trying to figure out why the control does not honor ZIndex.</p> <p>Example 1 - which works fine</p> <pre><code> &lt;Canvas&gt; &lt;Rectangle Canvas.ZIndex="1" Height="400" Width="600" Fill="Yellow"/&gt; &lt;Rectangle Canvas.ZIndex="2" Height="100" Width="100" Fill="Red"/&gt; &lt;/Canvas&gt; </code></pre> <p>Example 2 - which does not work</p> <pre><code> &lt;Canvas&gt; &lt;WebBrowser Canvas.ZIndex="1" Height="400" Width="600" Source="http://www.stackoverflow.com"/&gt; &lt;Rectangle Canvas.ZIndex="2" Height="100" Width="100" Fill="Red"/&gt; &lt;/Canvas&gt; </code></pre> <p>Thanks, -- Ed</p>
<p>Unfortunately this is because the WebBrowser control is a wrapper around the Internet Explorer COM control. This means that it gets its own HWND and does not allow WPF to draw anything over it. It has the same restrictions as hosting any other Win32 or WinForms control in WPF.</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms742522.aspx" rel="noreferrer">MSDN</a> has more information about WPF/Win32 interop.</p>
<p>I solved a similar issue where I was hosting a 3rd party WinForms control in my WPF application. I created a WPF control that renders the WinForms control in memory and then paints it to a bitmap. Then I use DrawImage in the OnRender method to draw the rendered content. Finally I routed mouse events from my control to the hosted control. In the case of a web browser you would also have to route keyboard events.</p> <p>My case was fairly easy - a chart with some simple mouse interaction. A web browser control may have other issues that I didn't take into consideration. Anyway I hope that helps.</p>
10,901
<p>I have a form that contains a GridView control which is databound to an ObjectDataSource Control. There are several TextBox controls that are already being used as ControlParameters for the ObjectDataSource. I also have a custom data object that the ObjectDataSource is associated with {TypeName="myDataClass"}. The values are passed from the ObjectDataSource to myDataClass.</p> <p>Now I need to also use a multi-select ListBox as a ControlParameter. When I use the SelectedValue parameter of the ListBox, the ObjectDataSource is only seeing the first selected item in the list. </p> <p>Here's the question: How can I get all the multi-select ListBox values passed into my custom object "myDataClass" instead of just the first one selected? Hence the ["multi-select"]</p> <p>Thanks for any help!</p>
<p>Multi-select list boxes are tricky. You need to loop through the items in code to build a list of selected values. So you will probably need to implement a custom parameter that does this for you.</p> <p>You might end up needing to bind to the grid from code-behind, instead of doing it declaratively.</p>
<p>This is typical problem. multi-select list box always return the first selected value and not all the selected value. We have to loop through the entire collection and check each individual value if selected or not.</p>
24,147
<p>I've been having this irritating issue lately. The site I'm currently working on has large aspx pages with tons of client side js code. While I'm typing the Error List window will keep opening and closing at the bottom of VS (where I have the window docked). I mean constantly. This is beyond aggravating as you can imagine. It's happening to a coworker as well. Does anybody else have this issue? Any solutions? (other than smaller pages)</p> <p>We've got 2008 Pro SP1. I've turned off every JS feature I can find since with pages this large it slows the VS to a crawl while it tries to parse it. I've tried closing the Error list completely but it just re-opens itself.</p> <p>Thanks in advance, Geoff</p>
<ol> <li>Try deleting the .user file in the project directory</li> <li>Use Add/Remove programs to do a repair on VS2008</li> <li>If neither of those work, copy the markup to a new project and attempt to reproduce. If you can reproduce this issue then update this question with details.</li> </ol>
<p>I finally found the options that were causing the issue.<br> 1. Options->Text Editor-> Miscellaneous, <br> &nbsp;&nbsp;&nbsp; un-check "Formal HTML on paste<br> 2. Options->Text Editor->JScript->Formatting<br> &nbsp;&nbsp;&nbsp;un-check The boxes under "Automatic Formatting"</p>
12,128
<p>I many times have to work with directories containing hundreds of thousands of files, doing text matching, replacing and so on. If I go the standard route of, say</p> <pre><code>grep foo * </code></pre> <p>I get the too many files error message, so I end up doing</p> <pre><code>for i in *; do grep foo $i; done </code></pre> <p>or</p> <pre><code>find ../path/ | xargs -I{} grep foo "{}" </code></pre> <p>But these are less than optimal (create a new grep process per each file).</p> <p>This looks like more of a limitation in the size of the arguments programs can receive, because the * in the for loop works alright. But, in any case, what's the proper way to handle this?</p> <p>PS: Don't tell me to do grep -r instead, I know about that, I'm thinking about tools that do not have a recursive option.</p>
<p>In newer versions of findutils, find can do the work of xargs (including the glomming behavior, such that only as many grep processes as needed are used):</p> <pre><code>find ../path -exec grep foo '{}' + </code></pre> <p>The use of <code>+</code> rather than <code>;</code> as the last argument triggers this behavior.</p>
<p>I can't see that</p> <pre><code>for i in *; do grep foo $i done </code></pre> <p>would work since I thought the "too many files" was a shell limitation, hence it would fail for the for loop as well.</p> <p>Having said that, I always let xargs do the grunt-work of splitting the argument list into manageable bits thus:</p> <pre><code>find ../path/ | xargs grep foo </code></pre> <p>It won't start a process per file but per group of files.</p>
22,517
<p>I have recently been doing a bit of investigation into the different types of Model View architectures, and need to decide which one to pursue for future in-house development. As I'm currently working in a Microsoft shop that has ASP.NET skills, it seems my options are between ASP.NET MVC and WCSF (Monorail is probably out of the as it wouldn't be supported by Microsoft).</p> <p>After reading <a href="http://blogs.msdn.com/simonince/archive/2007/11/22/the-asp-net-mvc-framework-using-the-wcsf-as-a-yardstick.aspx" rel="noreferrer">the ASP.NET MVC framework, using the WCSF as a yardstick</a>, I picked up the following points: </p> <ul> <li>ASP.NET MVC cannot use web controls that rely on postbacks, whereas WCSF can.</li> <li>You have more control over the urls in an ASP.NET MVC site as opposed to a WCSF site.</li> <li>An ASP.NET MVC site will probably be easier to test than an equivalent WCSF version.</li> <li>It seems that the WCSF still uses the code behind to control UI events under some circumstances, but ASP.NET MVC doesn't allow this. </li> </ul> <p>What are some of the other considerations?<br/> What have I misunderstood?<br/> Is there anybody out there who has used both frameworks and has advice either way?</p>
<blockquote> <p>ASP.NET MVC cannot use web controls that rely on postbacks, whereas WCSF can.</p> </blockquote> <p>You should think of WCSF as guidance about how to use the existing WebForms infrastructure, especially introducing Model-View-Presenter to help enforce separation of concerns. It also increases the testability of the resulting code.</p> <blockquote> <p>You have more control over the urls in an ASP.NET MVC site as opposed to a WCSF site.</p> </blockquote> <p>If you can target 3.5 SP1, you can use the new Routing system with a traditional WebForms site. Routing is not limited to MVC. For example, take a look at Dynamic Data (which also ships in 3.5 SP1).</p> <blockquote> <p>An ASP.NET MVC site will probably be easier to test than an equivalent WCSF version.</p> </blockquote> <p>This is true because it uses the new abstractions classes for HttpContext, HttpRequest, HttpResponse, etc. There's nothing inherently more testable about the MVC pattern than the MVP pattern. They're both instances of "Separated Presentation", and both increase testability.</p> <blockquote> <p>It seems that the WCSF still uses the code behind to control UI events under some circumstances, but ASP.NET doesn't allow this.</p> </blockquote> <p>In Model-View-Presenter, since the outside world interacts with views (i.e., the URL points to the view), the views will naturally be responding to these events. They should be as simple as possible, either by calling the presenter or by offering events that the presenter can subscribe to.</p> <p>Model-View-Controller overcomes this limitation by having the outside world interact with controllers. This means your views can be a lot "dumber" about non-presentation things.</p> <p>As for which you should use, I think the answer comes down to which one best suits your project goals. Sometimes WebForms and the rich third party control vendor availability will be preferable, and in some cases, raw simplicity and fine-grained HTML control will favor MVC.</p>
<p>Why not attach both to Northwind and see which fits best for you and your situation?</p>
7,694
<p>Is it possible to set a symbol for conditional compilation by setting up properties in an Xcode project?</p> <p>My aim is to to create a symbol that is available to all files, without having to use import/include, so that a set of common classes can have a special behavior in some projects. Like the following, but with my own symbols.</p> <pre><code>#if TARGET_IPHONE_SIMULATOR ... #endif </code></pre>
<p>Go to your Target or Project settings, click the Gear icon at the bottom left, and select "Add User-Defined Setting". The new setting name should be <code>GCC_PREPROCESSOR_DEFINITIONS</code>, and you can type your definitions in the right-hand field.</p> <p>Per Steph's comments, the full syntax is:</p> <pre><code>constant_1=VALUE constant_2=VALUE </code></pre> <p>Note that you don't <i>need</i> the '='s if you just want to #define a symbol, rather than giving it a value (for <code>#ifdef</code> statements)</p>
<p>You can duplicate the target which has the preprocessing section, rename it to any name you want, and then change your Preprocessor macro value.</p>
47,948
<p>Today I was working on a tab navigation for a webpage. I tried the <a href="http://www.alistapart.com/articles/slidingdoors2/" rel="noreferrer">Sliding Doors</a> approach which worked fine. Then I realized that I must include an option to delete a tab (usually a small X in the right corner of each tab). </p> <p>I wanted to use a nested anchor, which didn't work because it is <a href="http://www.w3.org/TR/html4/struct/links.html#h-12.2.2" rel="noreferrer">not</a> allowed. Then I saw the tab- navigation at <a href="http://www.pageflakes.com" rel="noreferrer">Pageflakes</a>, which was actually working (including nested hyperlinks). Why?</p>
<p>They must be doing some really crazy stuff with JavaScript to get it to work (notice how neither the parent nor the nested anchor tags have a name or href attribute - all functionality is done through the class name and JS).</p> <p>Here is what the html looks like:</p> <pre><code>&lt;a class="page_tab page_tab"&gt; &lt;div class="page_title" title="Click to rename this page."&gt;Click &amp; Type Page Name&lt;/div&gt; &lt;a class="delete_page" title="Click to delete this page" style="display: block;"&gt;X&lt;/a&gt; &lt;/a&gt; </code></pre>
<p>Actually, the code I had pasted previously was the generated DOM, after all JS manipulation. If you don't have the <a href="https://addons.mozilla.org/en-US/firefox/addon/1843" rel="nofollow noreferrer">Firebug</a> extension for Firefox, you should get it now.</p> <p>Edit: Deleted the old post, it was no longer useful. Firebug is, so this one is staying :)</p>
4,130
<p>This should be simple. I'm trying to import data from Access into SQL Server. I don't have direct access to the SQL Server database - it's on GoDaddy and they only allow web access. So I can't use the Management Studio tools, or other third-party Access upsizing programs that require remote access to the database.</p> <p>I wrote a query on the Access database and I'm trying to loop through and insert each record into the corresponding SQL Server table. But it keeps erroring out. I'm fairly certain it's because of the HTML and God knows what other weird characters are in one of the Access text fields. I tried using CFQUERYPARAM but that doesn't seem to help either.</p> <p>Any ideas would be helpful. Thanks.</p>
<p>Try using the <a href="http://blog.godaddyhosting.com/2007/07/20/presentingdrum-roll-please-the-ms-sql-backuprestore-feature.aspx" rel="nofollow noreferrer">GoDaddy SQL backup/restore tool</a> to get a local copy of the database. At that point, use the <a href="http://www.microsoft.com/technet/prodtechnol/sql/2000/deploy/dtssql2k.mspx" rel="nofollow noreferrer">SQL Server DTS tool</a> to import the data. It's an easy to use, drag-and-drop graphical interface.</p>
<p>It's never advisable to loop through records when a SQL Update can be used.</p> <p>It's not clear from your question what database interface layer you are using, but it is possible with the right interfaces to insert data from a source outside a database <em>if</em> the interface being used supports both types of databases. This can be done in the FROM clause of your SQL statement by specifying not just the table name, but the connect string for the database. Assuming that your web host has ODBC drivers for Jet data (you're not actually using Access, which is the app development part -- you're only using the Jet database engine), the connect string should be sufficient.</p> <p>EDIT: If you use the Jet database engine to do this, you should be able to specify the source table something like this (where tblSQLServer is a table in your Jet MDB that is linked via ODBC to your SQL Server):</p> <pre><code>INSERT INTO tblSQLServer (ID, OtherField ) SELECT ID, OtherField FROM [c:\MyDBs\Access.mdb].tblSQLServer </code></pre> <p>The key point is that you are leveraging the Jet db engine here to do all the heavy lifting for you.</p>
9,158
<p>I would like to change the "Row Source" values in an Access table through code. This way I can filter what a user can choose in a column's combo box.</p>
<p>I don't know whether or not this is an option for you, but I would recommend separating the table and filtering options, setting up a form to do the data entry and modification and using code to set the Row Source for the combo box on the form. As you've already seen, while Access does provide the opportunity to treat tables as more than just tables, that is primarily for GUI purposes. Behind the scenes, Access prefers that you work with forms for data entry.</p> <p>If you need to pursue the table method, you might try looking at the MS knowledge base articles referenced <a href="http://www.mdbmakers.com/forums/showthread.php?t=187" rel="nofollow noreferrer">here</a>. (The kb articles are <a href="http://support.microsoft.com/kb/151196" rel="nofollow noreferrer">here</a> and <a href="http://support.microsoft.com/kb/159367" rel="nofollow noreferrer">here</a>.) Keep in mind that these refer to Access 97 and may no longer be relevant. I wasn't able to find any more recent references to those properties in an Access tabledef.</p>
<p>Your question is quite confusing. "RowSource" is a property of a list box or combo box. A table does not have a RowSource, but, as Remou points out, Access allows you to define fields in your tables so that they display a combo box that looks up values from a related table. This combo box has a rowsource, so it's perhaps what you mean, but it's simply a terrible idea. </p> <p>That combo box that you define in the table design is a user interface object, and UI doesn't belong in your table definitions. Not only does it lead to all sorts of problems, but it means your tables themselves can be broken by changes to other tables that invalidate the definition of the lookup fields.</p> <p>User interface controls belong in user interface objects, which means that you should be putting them only in forms (or, at the lowest level, in saved queries).</p> <p>Filtering for a user is, again, a user interface issue, and not one that has anything to do with table design.</p>
29,678
<p>I am in need of a case insensitive string enumeration type in my XML schema (.xsd) file. I can get case insensitive by doing the following.</p> <pre><code>&lt;xs:simpleType name="setDigitalPointType"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:pattern value="[Oo][Nn]" /&gt; &lt;xs:pattern value="[Oo][Ff][Ff]" /&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; </code></pre> <p>The only problem is that I get no enumeration values. I will not get the nice intellesense when using Visual Studio to write my XML. The following will give me enumerations but it is case sensitive.</p> <pre><code>&lt;xs:simpleType name="setDigitalPointType"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:enumeration value="on" /&gt; &lt;xs:enumeration value="off" /&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; </code></pre> <p>This will give me my enumerations but if I ever receive a value of "On", "ON", or "oN" it will fail verification.</p> <p>I want enumeration of "on", "off" and allow entry of case insensitive versions.</p>
<p>IBM developerWorks has <a href="https://web.archive.org/web/20091206195708/http://www.ibm.com/developerworks/xml/library/x-case/" rel="nofollow noreferrer">an article</a> on how to use XSLT to perform the construction of the full set of enumeration alternatives in an automated fashion. It is presented as a workaround to the lack of case-insensitive enumerations.</p>
<p>Well, you could just list all the permutations as patterns :)</p>
46,875
<p>I need to change the functionality of an application based on the executable name. Nothing huge, just changing strings that are displayed and some internal identifiers. The application is written in a mixture of native and .Net C++-CLI code. </p> <p>Two ways that I have looked at are to parse the GetCommandLine() function in Win32 and stuffing around with the AppDomain and other things in .Net. However using GetCommandLine won't always work as when run from the debugger the command line is empty. And the .Net AppDomain stuff seems to require a lot of stuffing around.</p> <p>So what is the nicest/simplest/most efficient way of determining the executable name in C++/CLI? (I'm kind of hoping that I've just missed something simple that is available in .Net.)</p> <p>Edit: One thing that I should mention is that this is a Windows GUI application using C++/CLI, therefore there's no access to the traditional C style main function, it uses the Windows WinMain() function.</p>
<p>Call <a href="http://msdn.microsoft.com/en-us/library/ms683197(VS.85).aspx" rel="nofollow noreferrer">GetModuleFileName()</a> using 0 as a module handle.</p> <p><strong>Note:</strong> you <em>can</em> also use the <code>argv[0]</code> parameter to main or call <code>GetCommandLine()</code> if there is no main. However, keep in mind that these methods will not necessarily give you the complete path to the executable file. They will give back the same string of characters that was used to start the program. Calling <code>GetModuleFileName()</code>, instead, will always give you a complete path and file name.</p>
<p>I can confirm it works under win64/visual studio 2017/ MFC</p> <pre><code>TCHAR szFileName[MAX_PATH + 1]; GetModuleFileName(NULL, szFileName, MAX_PATH + 1); auto exe = CString(szFileName); </code></pre> <p>exe contains full path to exe.</p>
15,186
<p>There must be a generic way to transform some hierachical XML such as:</p> <pre><code>&lt;element1 A="AValue" B="BValue"&gt; &lt;element2 C="DValue" D="CValue"&gt; &lt;element3 E="EValue1" F="FValue1"/&gt; &lt;element3 E="EValue2" F="FValue2"/&gt; &lt;/element2&gt; ... &lt;/element1&gt; </code></pre> <p>into the flattened XML (html) picking up selected attributes along the way and providing different labels for the attributes that become column headers.</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;th&gt;A_Label&lt;/th&gt; &lt;th&gt;D_Label&lt;/th&gt; &lt;th&gt;E_Label&lt;/th&gt; &lt;th&gt;F_Label&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;AValue&lt;/td&gt; &lt;td&gt;DValue&lt;/td&gt; &lt;td&gt;EValue1&lt;/td&gt; &lt;td&gt;FValue1&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;AValue&lt;/td&gt; &lt;td&gt;DValue&lt;/td&gt; &lt;td&gt;EValue2&lt;/td&gt; &lt;td&gt;FValue2&lt;/td&gt; &lt;/tr&gt; &lt;table&gt; </code></pre> <p>OK, so there's not generic solution due to the attribute re-labelling but you get what I mean hopefully. I've just started on all the XSLT/XPATH stuff so I'll work it out in good time but any clues would be useful.</p>
<p>I'm not 100% sure of what you are trying to do but this solution may work if your element1, element2 and element3 are nested consistently.</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;table&gt; &lt;xsl:apply-templates select="//element3"&gt;&lt;/xsl:apply-templates&gt; &lt;/table&gt; &lt;/xsl:template&gt; &lt;xsl:template match="element3"&gt; &lt;tr&gt; &lt;td&gt;&lt;xsl:value-of select="../../@A"/&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="../../@B"/&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="../@C"/&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="../@D"/&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="@E"/&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="@F"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;xsl:apply-templates select="*"&gt;&lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
<p>We already have a Pro*C program reading from an Oracle database, it calls a perl script which in turn executes some Java to extract data in XML format from the aforementioned database for calling a batch file to execute some vbscript FTPing the file to some other server. I was really hoping for something in Fortran.</p>
11,442
<p>I'm new to the WCSF and can't seem to find anything related to "building a custom template" for creating the views/presenters/code-behinds/etc with your own flavor ...</p> <p>Can anyone point me in the right direction?</p>
<p>If you're using <strong>Visual C++</strong> do the following: You include intrin.h and call the following functions:</p> <p>For 16 bit numbers:</p> <pre><code>unsigned short _byteswap_ushort(unsigned short value); </code></pre> <p>For 32 bit numbers:</p> <pre><code>unsigned long _byteswap_ulong(unsigned long value); </code></pre> <p>For 64 bit numbers:</p> <pre><code>unsigned __int64 _byteswap_uint64(unsigned __int64 value); </code></pre> <p>8 bit numbers (chars) don't need to be converted.</p> <p>Also these are only defined for unsigned values they work for signed integers as well.</p> <p>For floats and doubles it's more difficult as with plain integers as these may or not may be in the host machines byte-order. You can get little-endian floats on big-endian machines and vice versa.</p> <p>Other compilers have similar intrinsics as well. </p> <p>In <strong>GCC</strong> for example you can directly call <a href="https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html" rel="noreferrer">some builtins as documented here</a>:</p> <pre><code>uint32_t __builtin_bswap32 (uint32_t x) uint64_t __builtin_bswap64 (uint64_t x) </code></pre> <p>(no need to include something). Afaik bits.h declares the same function in a non gcc-centric way as well.</p> <p>16 bit swap it's just a bit-rotate.</p> <p>Calling the intrinsics instead of rolling your own gives you the best performance and code density btw.. </p>
<p>Look up bit shifting, as this is basically all you need to do to swap from little -> big endian. Then depending on the bit size, you change how you do the bit shifting.</p>
13,080
<p>I'm trying to get a bare-bones example of logging going in my ASP.NET application. I would like to use the My.Log functionality to write out error log messages to a text log file. I have tried several things via Google but none of them seem to work. In general, when I use any of the properties of My.Log.DefaultFileWriter in the code it says "Object reference not set".</p> <p>My basic question is: What do I need in my web.config file (and/or anywhere else, if necessary) so that I can write messages with</p> <pre><code>My.Log.WriteEntry("blahblahblah") </code></pre> <p>in my code, to a text file, D:\log.txt?</p> <p>Thanks.</p> <hr> <p>Edit: specific code used:</p> <pre><code> &lt;system.diagnostics&gt; &lt;sources &gt; &lt;source name="DefaultSource" switchName="DefaultSwitch"&gt; &lt;listeners&gt; &lt;add name="FileLog"/&gt; &lt;/listeners&gt; &lt;/source&gt; &lt;/sources&gt; &lt;sharedListeners&gt; &lt;add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" initializeData="FileLogWriter" /&gt; &lt;/sharedListeners&gt; &lt;switches&gt; &lt;add name="DefaultSwitch" value="Verbose"/&gt; &lt;/switches&gt; &lt;trace autoflush="true"&gt;&lt;/trace&gt; &lt;/system.diagnostics&gt; </code></pre> <p>Then in the code:</p> <pre><code>My.Log.DefaultFileLogWriter.CustomLocation = "D:\" My.Log.DefaultFileLogWriter.BaseFileName = "log" My.Log.WriteEntry("blahblahblah") </code></pre> <p>(this would write to D:\log.log).</p>
<p><a href="https://learn.microsoft.com/en-us/dotnet/visual-basic/developing-apps/programming/log-info/walkthrough-changing-where-my-application-log-writes-information" rel="nofollow noreferrer">Walkthrough: Changing Where My.Application.Log Writes Information </a></p>
<p>log4net is the bst option for logging in asp.net</p>
30,349
<p>We have a lot of dll-libraries written in both delphi and c++ builder, and use sharemem and borlndmm.dll.</p> <p>An aligment-issue in a 3thparty library forces us over to the new memorymanager in delphi 2007.</p> <p>Can someone please explain 'shared memory manager' for me?<br> Is SimpleShareMem a dropin replacement for ShareMem ?<br> Can we then stop deploying borlndmm.dll?<br> Do we have to do something with the c++-libraries as well?<br> Can some libraries use ShareMem and some SimpleShareMem?</p> <p>Thanks, -Vegar</p>
<p>I think I found the answer to most of my questions in this thread: <a href="http://groups.google.com/group/borland.public.delphi.language.basm/browse_frm/thread/8b70a36f331f137e?ie=UTF-8&amp;oe=utf-8&amp;q=Re:+FastMM+questions" rel="nofollow noreferrer" title="borland.public.delphi.language.basm">borland.public.delphi.language.basm</a>:</p> <blockquote> <p>Either use<br> (a) SimpleShareMem.pas/FastMM4.pas, or use<br> (b) ShareMem.pas (i.e. borlndmm.dll)<br> You cannot mix the two different sharing methods. </p> </blockquote>
<p>Just have a look at <a href="https://forums.codegear.com/thread.jspa?threadID=6608" rel="nofollow noreferrer">https://forums.codegear.com/thread.jspa?threadID=6608</a> for an interesting discussion about this subject.</p>
39,237
<p>I've been arguing with my coworkers about Pascal casing (upper camel case) vs. lower <a href="http://en.wikipedia.org/wiki/CamelCase" rel="noreferrer">CamelCasing</a>. They are used to lower camel casing for everything from table names in SQL databases to property naming in C# code but I like Pascal casing better, lower camel casing for variables and Pascal casing for properties:</p> <pre><code>string firstName; public string FirstName { ... } </code></pre> <p>But they are used to this:</p> <pre><code>string _firstname; public string firstName { ... } </code></pre> <p>I try to keep up with their "standard" so the code looks the same but I just don't like it.</p> <p>I've seen that at least the .NET framework uses this convention and that is how I try to keep my code, e.g.:</p> <pre><code>System.Console.WriteLine("string") </code></pre> <p>What do you use/prefer and why? I'm sorry if somebody else asked this question but I searched and did not find anything.</p> <p><strong>Update:</strong> I've given a method example and not a property but it's the same. As I stated in the first paragraph my colleagues use the Pascal convention for everything (variables, methods, table names, etc.)</p>
<p>I use what the Framework uses, as it's the de-facto best practice. However, so long as the code in your company is <strong>consistently</strong> using their style, then you're much better off getting used to it. If every developer has their own standard, then there's no standard at all.</p>
<p>The day when i quit programming - its when Microsoft will make CamelCase in C# as standard. Because my grown logic has many reasons for PascalCase, unlike kid's logic, who cares only shorter names or easier to write.</p> <p>And BTW: CamelCasing comes primarily from C++ STD library style, the native old language inherited from C. So Java inherited from C++. But C# - is entirely new language - clean and beauty, with new rules. Oldfags must programm on Java or C++, new generation people must programm on C# - and they should never interact.</p> <p>Consider this example: 1) PascalCase: list.Capacity.ToString(); 2) CamelCase: list.capacity.toString();</p> <p>In (1) we have CAMEL CASE in long TERM!!! means listCapacityToString. In (2) we have bullshit: listcapacitytoString.</p> <p>Thats how i read. And why CamelCase is illogical for itselt. I could kill for PascalCase, never touch it, kids of any age.</p> <p>Microsoft - forever or until they use PascalCase.</p>
18,015
<p>We are in the early design stages of a major rewrite of our product. Right now our customers are mostly businesses. We manage accounts. User names for an account are each on their own namespace but it means that we can't move assets between servers.</p> <p>We want to move to a single namespace. But that brings the problem of unique user names.</p> <p>So what's the best idea?</p> <ul> <li>Email address (w/verification) ?</li> <li>Unique alpha-numeric string ("johnsmith9234")?</li> <li>Should we look at OpenID?</li> </ul>
<p><strong>EMAIL ADDRESS</strong></p> <p>Rational</p> <ol> <li>Users don't change emails very often</li> <li>Removes the step of asking for username and email address, which you'll need anyway</li> <li>Users don't often forget their email address (see number one)</li> <li>Email will be unique unless the user already registered for the site, in which case forward them to a forgot your password screen</li> <li>Almost everyone is using email as the primary login for access to a website, this means the rate of adoption shouldn't be affected by the fact that you're asking for an email address</li> </ol> <hr> <p><strong>Update</strong></p> <p>After registration, be sure to ask the user to create some kind of username, don't litter a public site with their email address! Also, another benefit of using an email address as a login: you won't need any other information (like password / password confirm), just send them a temp password through the mail, or forgo passwords altogether and send them a one-use URL to their email address every time they'd like to login (see: <a href="http://mugshot.org/main" rel="noreferrer">mugshot.org</a>)</p>
<p>OpenID seems to be a very good alternative to writing your own user management/authentication piece. I'm seeing more and more sites using OpenID these days, so the barrier to entry for your users should be relatively low.</p>
2,789
<p>We’re currently in the process of updating the email dispatch part of our application to replace the deprecated set of classes under System.Web.Mail with the System.Net.Mail classes. </p> <p>The changes have been fairly straightforward but we’ve hit an obstacle today in that we were trying to port the contents of the System.Web.Mail.MailMessage.Fields dictionary (which contains objects mapping to CDO fields) but we cannot see an equivalent on the System.Net.Mail.MailMessage class. </p> <p>Does anyone know of any documentation which maps the CDO fields to the new classes/properties in the System.Net.Mail classes? (Here is the fields in the <a href="http://msdn.microsoft.com/en-us/library/ms872853.aspx" rel="nofollow noreferrer"><strong>namespace</strong></a>).</p>
<p>Have a look at this site <a href="http://www.systemnetmail.com/" rel="nofollow noreferrer">http://www.systemnetmail.com/</a></p> <p>It should cover all the SMTP related fields that you need to map e.g. ssl, sendusing</p>
<p>which cdo fields are you trying to carry over?</p> <p>i know some CDO fields we used are now mapped to some properties in the SmtpClient object.</p>
46,006
<p>Should I prepare my code for possible/predicted future changes so that it's easier to make these changes even if I don't really know if these changes will be required anytime?</p>
<p>I am likely to get lynched for my opinion on this, but here I go.</p> <p>While I have had this hammered into me over years of reading idealistic articles and sitting through far too many seminars and lectures categorically stating the nirvana like benefits of this, I too had similar questions in my mind. This line of thought can lead to massive over-engineering of the code, adding many man hours or more to design, development and testing estimates, increasing cost and overheads, when in reality this is not often the case. How many times have you actually reused your code or a library. If it is going to be used in many places, through numerous projects, then yes you should.</p> <p>However, most of the time this is not the case. You will often find it more economical (in time and money) to only refactor your code for reuse and configurability when you actually know that you are going to use it again. The rest of the time the real benefits are lost.</p> <p>This is not, I repeat NOT, an excuse to write sloppy, poorly designed, poorly documented code. This should be a fundamental that is so wholly ingrained in you that you could not break it, but writing a class for reuse is a waste most of the time as it will never get reused.</p> <p>There are obvious exceptions to this. If you are writing third party libraries then obviously this is not the case and reuse and expansion should be key to your design. Certain other types of code should be obvious for reuse (Logging, Configuration etc.)</p> <p>I asked a similar question here <a href="https://stackoverflow.com/questions/325514/code-reusability-is-it-worth-it" title="Code Reusability: Is it worth it">Code Reusability: Is it worth it</a> It might help.</p>
<p>In two words: yes, always.</p>
47,312
<p>I was making the following call:</p> <pre><code>result = RegOpenKeyEx(key, s, 0, KEY_READ, &amp;key); </code></pre> <p>(C++, Visual Studio 5, Vista 64bit).</p> <p>It is failing with error code 2 ("File not found") even though "<code>regedit</code>" shows that the key exists. This code has always worked on 32bit XP. Why is it "file not found" when it clearly is there?</p>
<p>I discovered that I could solve my problem using the flag: <code>KEY_WOW64_64KEY</code> , as in:</p> <pre><code>result = RegOpenKeyEx(key, s, 0, KEY_READ|KEY_WOW64_64KEY, &amp;key); </code></pre> <p>For a full explanation: <a href="http://msdn.microsoft.com/en-us/library/ms724072(VS.85).aspx" rel="noreferrer">32-bit and 64-bit Application Data in the Registry</a></p>
<p>I had a similar problem. I was using:</p> <pre><code>dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPWSTR)"SOFTWARE\\0test", 0, WRITE_DAC , &amp;hKey); </code></pre> <p>That didn't work. I tried it like this and it worked:</p> <pre><code>dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\0test"), 0, WRITE_DAC , &amp;hKey); </code></pre>
31,440
<p>I'm very excited about the new "local F specs" coming in V6R1 - see:</p> <p><a href="http://www.mcpressonline.com/programming/rpg/v6r1-rpg-enhancements.html" rel="nofollow noreferrer">http://www.mcpressonline.com/programming/rpg/v6r1-rpg-enhancements.html</a></p> <p>Does anyone know a way to simulate this in V5R4 in a SRVPGM procedure?</p>
<p>Fortunately or not, but OpenSSH client seems to be very picky about passwords and where they come from.</p> <p>You may try using <a href="http://www.lag.net/paramiko/" rel="nofollow noreferrer">Paramiko</a> Python SSH2 library. Here's a simple <a href="http://www.lag.net/pipermail/paramiko/2006-January/000180.html" rel="nofollow noreferrer">example how to use it with password authentication</a>, then issue some shell commands (<code>echo "..." &gt;&gt; $HOME/.ssh/authorized_keys</code> being the simplest) to add your public key on remote host.</p>
<p>Reading <a href="http://pexpect.sourceforge.net/pexpect.html#spawn" rel="nofollow noreferrer">pexpect documentation for spawn</a>, I think it is waiting for the command to terminate.</p> <p>I would suggest a couple of different possibilities, depending on your needs:</p> <p>1) Kill the spawned process. However, this may lead to corruption in your operation, so I do not know if it is what you want.</p> <pre><code>child = pexpect.spawn('command') child.expect('password:') child.sendline('the password') child.close(True) </code></pre> <p>2) Wait for completion of the initial task before moving to the next one</p> <pre><code>child = pexpect.spawn('command') child.expect('password:') child.sendline('the password') child.wait() child = pexpect.spawn('command2') ... </code></pre> <p>3) Use a different instance for all children, then wait on all of them at the end - and this would be most probably the best solution</p> <pre><code>def exec_command(cmd): child = pexpect.spawn(cmd) child.expect('password:') child.sendline('the password') return child commands = ['command1', 'command2'] childrens = [exec_command(cmd) for cmd in commands] for child in childrens: child.wait() </code></pre> <p>Note: all of the code here is untested, and written under the assumption that your script is hanging because deleting a spawn object will hang until the command will terminate.</p>
46,531
<p>I have forms in my page a get and a post and i want add pager on my get form .. so i cant page through the results.. </p> <p>The problem that i am having is when i move to the second page it does not display anything..</p> <p>I am using this library for paging .. <a href="http://stephenwalther.com/Blog/archive/2008/09/18/asp-net-mvc-tip-44-create-a-pager-html-helper.aspx" rel="nofollow noreferrer">http://stephenwalther.com/Blog/archive/2008/09/18/asp-net-mvc-tip-44-create-a-pager-html-helper.aspx</a></p> <p>this my actions code.</p> <pre><code> [AcceptVerbs("GET")] public ActionResult SearchByAttraction() { return View(); } [AcceptVerbs("POST")] public ActionResult SearchByAttraction(int? id, FormCollection form) {.... } </code></pre> <p>and this is what i am using on my get form to page through</p> <p>&lt;%= Html.Pager(ViewData.Model)%> //but when i do this it goes to this method [AcceptVerbs("GET")] public ActionResult SearchByAttraction()</p> <p>instead of going to this this</p> <p>[AcceptVerbs("POST")] public ActionResult SearchByAttraction(int? id, FormCollection form)</p> <p>which sort of makes sence .. but i cant really think of any other way of doing this</p> <p>Any help would be very appreciated.. </p> <p>Thanx</p>
<p>I'd recommend against doing paging via HTTP POST. Page and search criteria are 2 perfect examples of what querystrings are meant for. Put those values in the query string &amp; have that load up your action args.</p> <p>Think about this. You can search google for "pies", navigate to page 14, copy the link and send it to your grandma. You can't do that when your paging/search only works with form posts.</p>
<p>Of course it will hit the GET version of SearchByAttraction because using this control you have a links as output.</p> <p>So what you need to do:</p> <pre><code>1. make form on the page: &lt;form id="myForm" action="your/url" method="post"&gt; &lt;input type="hidden" name="page" /&gt; &lt;input type="hidden" name="your_param1" /&gt; &lt;input type="hidden" name="your_param2" /&gt; &lt;input type="hidden" name="your_paramN" /&gt; &lt;/form&gt; 2. make changes to pager - it should produce something like that: &lt;ul id="pager"&gt; &lt;li&gt;&lt;a href="url/as/was/created/by/pager" onclick="return submitMyForm(1);"&gt;1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="url/as/was/created/by/pager" onclick="return submitMyForm(2);"&gt;2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="url/as/was/created/by/pager" onclick="return submitMyForm(3);"&gt;3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; 3. add simple javascript function on the page: &lt;script language="javascript" type="text/javascript"&gt; function submitMyForm(page) { var form = document.forms["myForm"]; form.elements["page"].value = page; form.submit(); return false; } &lt;/script&gt; </code></pre> <p>And you will be able to hit the POST version, because clicking the link will submit your form on the server using POST request.</p>
48,176
<p>When I try to bind port 80 to a socket in c, i always get the error, that I don't have permission to use this port. is there an easy way to get this permission?</p>
<p>Usually only the superuser (root) can bind to 'privileged' ports (i.e. those port numbers below 1024).</p> <p>This means that you either have to run your program as root or make your executable 'suid root'.</p> <p>Both of these have security consequences so you may want to consider using the suid approach and relinquishing superuser privileges once the bind call has been made.</p>
<p>Yes, you can easily bind to port 80. Use Apache. Write a web application. Apache binds to port 80 and runs your web application. </p> <p>Are you trying to write the next Apache? If so, you'll need to learn about the <a href="http://www.manpagez.com/man/2/setuid/" rel="nofollow noreferrer">setuid</a> API call in your operating system. </p> <p>If you're not writing a new version of Apache, most people use a non-privileged port. 8000 is popular, so is 8080.</p>
20,411
<p>One of the things that seems to be necessary with use of STL is a way to specify local functions. Many of the functions that I would normally provide cannot be created using STL function object creation tools ( eg bind ), I have to hand roll my function object.</p> <p>Since the C++ standard forbids local types to be used as arguments in template instantiations the best I was able to use was to create a small library, ( just showing relevant parts )</p> <pre><code>// library header class MyFunctionBase&lt;R,T&gt; { public: virtual ~MyFunctionBase(); virtual R operator()(const T &amp;) const=0; }; class MyFunction&lt;R,T&gt; { MyFunctionBase&lt;R,T&gt; *b; public: ~MyFunction() { delete b; } virtual R operator()(const T &amp;) const { return (*b)(T); } }; // source file .... class func: public MyFunctionBase ... std::stl_alg(.... MyFunction(new funct)); </code></pre> <p>This has always seemed unwieldly to me. I guess to the people on the ISO committee believe so too and added a lambda to C++.</p> <p>In the meantime how have compilers addressed this problem? ( Especially Windows compilers. )</p> <p>A correction which might clarify a bit. Changelog: Nov 2 replaced to clarify Since the C++ standard forbids local classes as function objects</p>
<p>The standard way is a "functor" - basically, a <code>struct</code> that supplies an <code>operator()</code></p> <p>For example:</p> <pre><code>struct MyMinFunctor { bool operator()(const int&amp; a, const int&amp; b) { return a &gt; b; } }; vector&lt;int&gt; v; sort(v.begin(), v.end(), MyMinFunctor()); </code></pre> <p>Because it is a struct/class, you can subclass any of the things like 'binary_operator' as well as maintain state for more advanced functors.</p>
<p>With C++0x you can use lambda's (as you mentioned):</p> <pre><code>for_each(container.begin(), container.end(), [](auto item) { // do something with item } ); </code></pre> <p>This is already available in MS Visual C++ 2010 (currently in Community Tech Preview) and GCC 4.3.x (with the -std=c++0x compiler flag). However, without lambda's, you just need to provide a type that:</p> <ol> <li>Is default constructible</li> <li>Is copy constructible</li> <li>Defines a function operator overload</li> </ol> <p>There are some algorithms that require binary function objects while there are some that require unary function objects. Refer your vendor's STL documentation to find out exactly which algorithms require binary function objects and which ones require unary function objects.</p> <p>One thing you might also want to look into are the newer implementations of <code>bind</code> and <code>function</code> in TR1 (based on Boost.Bind and Boost.Function).</p>
32,016