input
stringlengths
51
42.3k
output
stringlengths
18
55k
Converting a PDF to PNG <p>I'm trying to convert a PDF (at least the cover of one, I'm successfully extracting the first page of the PDF with pdftk) to a PNG. I'm using imagemagick to do the converstion:</p> <pre><code>convert cover.pdf cover.png </code></pre> <p>This works, but unfortunately the cover.png comes through incorrectly rendered (some of the alpha object in the PDF aren't rendered properly). I know ImageMagick uses GhostScript to do the conversion and if I do it directly with gs I can get the desired results, but I'd rather use the convert library as it has other tools I'd like to leverage.</p> <p>This command in GhostScript accomplishes the desired image:</p> <pre><code>gs -sDEVICE=pngalpha -sOutputFile=cover.png -r144 cover.pdf </code></pre> <p>I'm wondering is there any way to pass arguments through convert to GhostScript or am I stuck with calling GhostScript directly?</p>
<p>You can use one commandline with two commands (<code>gs</code>, <code>convert</code>) connected through a pipe, if the first command can write its output to stdout, and if the second one can read its input from stdin.</p> <ol> <li>Luckily, gs can write to stdout (<code>... -o %stdout ...</code>). </li> <li>Luckily, convert can read from stdin (<code>convert -background transparent - output.png</code>).</li> </ol> <p>Problem solved: </p> <ul> <li>GS used for alpha channel handling a special image, </li> <li>convert used for creating transparent background,</li> <li>pipe used to avoid writing out a temp file on disk.</li> </ul> <p><strong><em>Complete solution:</em></strong> </p> <pre><code>gs -sDEVICE=pngalpha \ -o %stdout \ -r144 cover.pdf \ | \ convert \ -background transparent \ - \ cover.png </code></pre> <hr> <h2>Update</h2> <p>If you want to have a separate PNG per PDF page, you can use the <code>%d</code> syntax:</p> <pre><code>gs -sDEVICE=pngalpha -o file-%03d.png -sDEVICE=pngalpha -r144 cover.pdf </code></pre> <p>This will create PNG files named <code>page-000.png</code>, <code>page-001.png</code>, ... (Note that the <code>%d</code>-counting is zero-based -- <code>file-000.png</code> corresponds to page 1 of the PDF, <code>001</code> to page 2...</p> <p>Or, if you want to keep your transparent background, for a 100-page PDF, do</p> <pre><code>for i in {1..100}; do \ \ gs -sDEVICE=pngalpha \ -dFirstPage="${i}" \ -dLastPage="${i}" \ -o %stdout \ -r144 input.pdf \ | \ convert \ -background transparent \ - \ page-${i}.png ; \ \ done </code></pre>
how to get a particular value from NameValueCollection's comma-delimited string? <p>i have a POST request</p> <pre><code>firstname=1&amp;lastname=10&amp;firstname=2&amp;lastname=20&amp;firstname=3&amp;lastname=30. </code></pre> <p>then i get comma-delimited lists of names and values</p> <pre><code>Request.Form["firstname"] // 1,2,3 Request.Form["lastname"] //10,20,30 </code></pre> <p>it seems that NameValueCollection does not contain a method to access specified firstname value directly?</p> <p>the task looks standard, like Request.Form index property in ASP.</p> <p>of course i can implement a custom helper enumerator or simply parse strings someway, but i'm not sure there are no any standard solution.</p> <p>to be honest, i would prefer to have direct access to each firstname-lastname pair, but i cannot ask impossible:).</p>
<p><code>GetValues()</code> will return a <code>string[]</code></p>
How to delete the cache of SPNavigationNodes in Sharepoint 2007? <p>I have a website in Sharepoint.</p> <p>As you know,in settings users can order the sites and pages as they want in exploration, and then you can get these items with this order with:</p> <pre><code>SPWeb web = CurrentSite.OpenWeb(currentSite); SPNavigation nav = web.Navigation; SPNavigationNodeCollection nodeColl = nav.QuickLaunch; </code></pre> <p>The problem I am having is that there is a cache for this, and everytime the user adds a webpage, the list i get with web.Navigation.QuickLaunch is the same as before.</p> <p>The only way to delete the cache is to enter the exploration and change the order of the items and then restablish it and accept the form. </p> <p>Can somebody tell me if i can do it in another way?</p>
<p>i'm not 100% sure, but trying retrieving a new copy of the SPWeb object instead of using one from the current context:</p> <pre><code>using ( SPSite l_site = new SPSite(SPContext.Current.Site.Url); ) { using ( SPWeb l_web = l_site.OpenWeb() ) { .. } } </code></pre>
WPF: Is ListBox or Panel responsible for mouse wheel navigation? <p>I have a custom ListBox which uses a custom Panel as ItemsHost. I want to have control over mouse wheel input, so that turning the wheel changes the single selected item.</p> <p>I believe that the best method to do so is to handle the OnPreviewMouseWheel event (although this is only have what I want since it doesn't provide horizontal wheel data).</p> <p>Now the big question: Is there a best practice where to handle OnPreviewMouseWheel? In ListBox (which by default doesn't have a clue about the arrangement of the Panel's child elements) or in Panel (which by default doesn't have a clue about the "IsSelected" property of it's child elements)?</p>
<p>I think you should do this from the <code>ListBox</code>. <code>ListBox</code> inherits from <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.aspx" rel="nofollow">Selector</a> which handles everything to do with selection.</p> <p>The mousewheel selection behavior could apply with any kind of <code>Panel</code> (it might even be a good idea to implement it using a standard <code>ListBox</code> first), and you might want to use the <code>Panel</code> somewhere outside of a <code>ListBox</code> where the selection logic would make no sense.</p>
convert xml to sorted dictionary <p>i have an xml file similar to this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;data&gt; &lt;resource key="123"&gt;foo&lt;/resource&gt; &lt;resource key="456"&gt;bar&lt;/resource&gt; &lt;resource key="789"&gt;bar&lt;/resource&gt; &lt;/data&gt; </code></pre> <p>i want to put this into a Dictionary (sorted) as key value pairs. i.e: 123:foo, 456:bar...etc</p> <p>the keys are unknown.</p> <p>how can i do this?</p>
<p>This looks like a job for Linq to Xml</p> <pre><code> static void Main(string[] args) { XDocument yourDoc = XDocument.Load("the.xml"); var q = from c in yourDoc.Descendants("resource") orderby (int) c.Attribute("key") select c.Attribute("key").Value + ":" + c.Value; foreach (string s in q) Console.WriteLine(s); Console.ReadLine(); } </code></pre>
Why does the count() function require a parameter? <p>The <code>count()</code> function counts rows, and is very often used as <code>count(*)</code>. If I had a table with phoneNo and firstName, <code>count(phoneNumber)</code> returns the same number as <code>count(*)</code>. All columns are always present, if not populated, in each row.</p>
<p>There is a subtle difference. </p> <p>If you specify a field , count(fieldname) will count records which have <em>non null</em> values for the field. count(*) will give you total rows. </p>
How to do with pointing the target html when doing xml transformation? <p>I want to generate a treeview from xml by xsl. In the output html, there are 2 frames: treeframe for the treeview and contentframe for displaying the content of the nodes when I click on the tree. </p> <p>I wrote a tree.xsl to generate the tree from the xml, a result.html who constructs the frameset and has js function, populateFrames() to automatically do the transformation and output it in the treeframe.</p> <p>I also wrote a content.xsl file to extract the content of each specified node, and a content.js file who has the function, displayContent to do the transformation of xml by content.xsl. </p> <p>Then in the tree.xsl, in the onclick event, I call the displayContent function. </p> <p>My problem is here. I don't know how to set the target, to the contentframe. Can I do this in the tree.xsl or it'll be better to do it in the content.js or there are other solutions. </p> <p>Thank you for your help.</p> <p>Allen </p>
<p>Put displayContent function in the containing page code rather than in HTML for the Tree frame. Have the nodes call top.displayContent. Now the displayContent can instruct the content frame with the URL it needs to display.</p> <p>Alternatively use anchors in the XSL and specify the target attribute to point at the content frame.</p>
Highlight a list of words using a regular expression in c# <p>I have some site content that contains abbreviations. I have a list of recognised abbreviations for the site, along with their explanations. I want to create a regular expression which will allow me to replace all of the recognised abbreviations found in the content with some markup.</p> <p>For example:</p> <p>content: <pre>This is just a little test of the memb to see if it gets picked up. Deb of course should also be caught here.</pre></p> <p>abbreviations: <pre>memb = Member; deb = Debut; </pre></p> <p>result: <pre>This is just a little test of the [a title="Member"]memb[/a] to see if it gets picked up. [a title="Debut"]Deb[/a] of course should also be caught here.</pre></p> <p>(This is just example markup for simplicity).</p> <p>Thanks.</p> <p>EDIT:</p> <p>CraigD's answer is nearly there, but there are issues. I only want to match whole words. I also want to keep the correct capitalisation of each word replaced, so that deb is still deb, and Deb is still Deb as per the original text. For example, this input:</p> <pre> This is just a little test of the memb. And another memb, but not amemba. Deb of course should also be caught here.deb! </pre>
<p>First you would need to <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.escape.aspx"><code>Regex.Escape()</code></a> all the input strings.</p> <p>Then you can look for them in the string, and iteratively replace them by the markup you have in mind:</p> <pre><code>string abbr = "memb"; string word = "Member"; string pattern = String.Format("\b{0}\b", Regex.Escape(abbr)); string substitue = String.Format("[a title=\"{0}\"]{1}[/a]", word, abbr); string output = Regex.Replace(input, pattern, substitue); </code></pre> <p>EDIT: I asked if a simple <a href="http://msdn.microsoft.com/en-us/library/system.string.replace.aspx"><code>String.Replace()</code></a> wouldn't be enough - but I can see why regex is desirable: you can use it to enforce "whole word" replacements only by making a pattern that uses word boundary anchors.</p> <p>You can go as far as building a single pattern from all your escaped input strings, like this:</p> <pre><code>\b(?:{abbr_1}|{abbr_2}|{abbr_3}|{abbr_n})\b </code></pre> <p>and then using a <a href="http://msdn.microsoft.com/en-us/library/cft8645c.aspx">match evaluator</a> to find the right replacement. This way you can avoid iterating the input string more than once.</p>
GC.Collect in a loop? <p>I found this piece of code inside System.Web.ISAPIRuntime using Reflector</p> <pre><code>public void DoGCCollect() { for (int i = 10; i &gt; 0; i--) { GC.Collect(); } } </code></pre> <p>Can anyone comment on this? Is there a reason to do GC.Collect() in a loop? Why 10 times and not 3, 5 or 20? Analysis indicated that it's not used inside .net framework but it's public so I suppose that IIS could call it...</p> <p><strong>edit :</strong></p> <p>Just for clarification purposes : I have never called GC.Collect and I have no intentions of using it. I know it's a bad idea in most (if not all) cases. The question is why .net framework does it. Thanks for all your answers.</p>
<p>Yes, that's horrible. Firstly, you shouldn't need to do it at all. However, if you really want to force garbage collection as hard as you can, and wait for it to finish, you should probably use:</p> <pre><code>GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); // Collect anything that's just been finalized GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); </code></pre> <p>Really not a nice idea though.</p>
How to configure symfony project in local server? <p>I am beginner for symfony. I have to configure the already developed project that is built using symfony. I changed the database information but when browse localhost/myproject/web there is nothing displayed. What can i do to configure the project in local server. I have created the database as well. Hope to get help. Thanks ..........</p>
<p>you need to point apache to the web folder in your symfony project. or if your project reside inside apache web root you could use:</p> <p><strong><a href="http://localhost/myproject/web/index.php" rel="nofollow">http://localhost/myproject/web/index.php</a></strong> but that won't show any errors. insted of that you could use:</p> <p><a href="http://localhost/myproject/web/" rel="nofollow">http://localhost/myproject/web/</a><strong>frontend</strong>_dev.php where <strong>frontend</strong> is the name of front controler ( this file is in web/ folder).</p> <p>and if then you don't get any output look into your apache server error log to find why project isn't working.</p> <p>few resolves:</p> <p>when in symfony project root execute this in command prompt:</p> <pre><code>php symfony cache:clear php symfony fix-perms </code></pre> <p>and then try url above.</p> <p>more info <a href="http://www.symfony-project.org/tutorial/1%5F2/my-first-project" rel="nofollow">here</a></p>
SQL/MySQL SELECT and average over certain values <p>I have to work with an analysis tool that measures the Web Service calls to a server per hour. These measurments are inserted in a database. The following is a snippet of such a measurement: </p> <pre><code>mysql&gt; SELECT * FROM sample s LIMIT 4; +---------+------+-------+ | service | hour | calls | +---------+------+-------+ | WS04 | 04 | 24 | | WS12 | 11 | 89 | | WSI64 | 03 | 35 | | WSX52 | 01 | 25 | +---------+------+-------+ 4 rows in set (0.00 sec) </code></pre> <p>As the end result I would like to know the sum of all web services completions per hour of day. Obviously, this can be easily done with SUM() and GROUP BY: </p> <pre><code>mysql&gt; SELECT hour, SUM(calls) FROM sample s GROUP BY hour; +------+------------+ | hour | SUM(calls) | +------+------------+ | 00 | 634 | | 01 | 642 | | 02 | 633 | | 03 | 624 | | 04 | 420 | | 05 | 479 | | 06 | 428 | | 07 | 424 | | 08 | 473 | | 09 | 434 | | 10 | 485 | | 11 | 567 | | 12 | 526 | | 13 | 513 | | 14 | 555 | | 15 | 679 | | 16 | 624 | | 17 | 796 | | 18 | 752 | | 19 | 843 | | 20 | 827 | | 21 | 774 | | 22 | 647 | | 23 | 533 | +------+------------+ 12 rows in set (0.00 sec) </code></pre> <p>My problem is that in old sets, the web service calls in the hours from [00-11] were already summed up. The simple statement as listed above would therefore lead to </p> <pre><code>mysql&gt; SELECT hour, SUM(calls) FROM sample s GROUP BY hour; +------+------------+ | hour | SUM(calls) | +------+------------+ | 00 | 6243 | &lt;------ sum of hours 00-11! | 12 | 526 | | 13 | 513 | | 14 | 555 | | 15 | 679 | | 16 | 624 | | 17 | 796 | | 18 | 752 | | 19 | 843 | | 20 | 827 | | 21 | 774 | | 22 | 647 | | 23 | 533 | +------+------------+ 13 rows in set (0.00 sec) </code></pre> <p>This is an undesirable result. To make the old sets [00,12,...,23] comparable to the new sets [00,01,...,23] I would like to have one statement that averages the value of [00] and distributes it over the missing hours, e.g.: </p> <pre><code>+------+------------+ | hour | SUM(calls) | +------+------------+ | 00 | 6243/11 | | 01 | 6243/11 | [...] | 12 | 526 | [...] | 23 | 533 | +------+------------+ </code></pre> <p>I can easily do this using temporary tables or views, but i don't know how to accomplish this without them.</p> <p>Any ideas? Cause this is driving me crazy :P</p>
<p>You're probably best doing this with temp tables / views (I'd recommend a view over a temp table) or you will end up with a nasty case specific statement that will be a nightmare to manage over time.</p>
Can i display a portion of an image in iphone application using cocos2d? <p>I want to display portion of image not to display the total image.At first display the full image but after a delay time display the a portion of this image. I can not understand how can i do this. Like we can display portion of text by fixing the dimension of Label.But in case of image how can i do that using sprite or other.</p>
<pre><code>[someImage drawInRect:CGRectMake(0, 0, 30, 30)]; </code></pre>
C++ Optimization Techniques <p>Is there a site that provides a great list of common C++ optimization practices?</p> <p>What I mean by optimization is that you have to modify the source code to be able to run a program faster, not changing the compiler settings.</p>
<p>I will echo what others have said: a better algorithm is going to win in terms of performance gains.</p> <p>That said, I work in image processing, which as a problem domain can be stickier. For example, many years ago I had a chunk of code that looked like this:</p> <pre><code>void FlipBuffer(unsigned char *start, unsigned char *end) { unsigned char temp; while (start &lt;= end) { temp = _bitRev[*start]; *start++ = _bitRev[*end]; *end-- = temp; } } </code></pre> <p>which rotates a 1-bit frame buffer 180 degrees. _bitRev is a 256 byte table of reversed bits. This code is about as tight as you can get it. It ran on an 8MHz 68K laser printer controller and took roughly 2.5 seconds for a legal sized piece of paper. To spare you the details, the customer couldn't bear 2.5 seconds. The solution was an identical algorithm to this. The difference was that</p> <ol> <li>I used a 128K table and operated on words instead of bytes (the 68K is much happier on words)</li> <li>I used Duff's device to unroll the loop as much as would fit within a short branch </li> <li>I put in an optimization to skip blank words</li> <li>I finally rewrote it in assembly to take advantage of the sobgtr instruction (subtract one and branch on greater) and have "free" post increment and pre-decrements in the right places.</li> </ol> <p>So 5x: no algorithm change.</p> <p>The point is that you also need to understand your problem domain and what bottlenecks means. In image processing, algorithm is still king, but if your loops are doing extra work, multiply that work by several million and that's the price you pay.</p>
What is the most efficient way to convert an int to a String? <p>Say I have:</p> <pre><code>int someValue = 42; </code></pre> <p>Now I want to convert that int value to a String. Which way is more efficient?</p> <pre><code>// One String stringValue = Integer.toString(someValue); // Two String stringValue = String.valueOf(someValue); // Three String stringValue = someValue + ""; </code></pre> <p>I am just curious if there is any real difference or one is better than the other?</p>
<p>tested it for 10m assignments of the number 10</p> <pre><code>One: real 0m5.610s user 0m5.098s sys 0m0.220s Two: real 0m6.216s user 0m5.700s sys 0m0.213s Three: real 0m12.986s user 0m11.767s sys 0m0.489s </code></pre> <p>One seems to win</p> <p>Edit: JVM is standard '/usr/bin/java' under Mac OS X 10.5</p> <pre> java version "1.5.0_16" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284) Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing) </pre> <p>More edit:</p> <p>Code as requested</p> <pre><code>public class One { public static void main(String[] args) { int someValue = 10; for (int i = 0; i &lt; 10000000; i++) { String stringValue = Integer.toString(someValue); } } } </code></pre> <p>case 2 and 3 similarly<br /> run using</p> <pre><code>javac *.java; time java One; time java Two; time java Three </code></pre>
Variable variables in PHP and URL functions <p>Here's a piece of code:</p> <pre><code>$obj = new myClass(); $obj-&gt;{$_GET["func"]}($_GET["param"]) </code></pre> <p>It works based on variable variables, but I don't really understand how. As far as I know, variable variables are used for stuff like this:</p> <pre><code>require "dbsettings.php" $member_id = $_GET['id']; $db = new DBconnector(); $vars = array('username','passw','email','info','datejoined','dateofbirth'); foreach ($vars as $var) { $$var = $db-&gt;getUserInfo($member_id,$var); } echo $username; echo $passw; echo $email; echo $info; echo $datejoined; echo $dateofbirth; </code></pre> <p>So, in the first piece of code, what's happening? Also, what function do the braces serve? What do they tell the compiler to think?</p>
<pre><code>$obj-&gt;{$_GET["func"]}($_GET["param"]) </code></pre> <p>Simply calls the method whose name is stored in $_GET["func"], and pass as a parameter $_GET["param"]. </p> <p>The parentheses serve to disambiguate the method name (you also use parentheses in strings for similar purposes, e.g. <code>echo "calling {$_GET['func']}";</code></p> <p>See the <a href="http://uk.php.net/manual/en/language.variables.variable.php" rel="nofollow">PHP manual page on variable variables</a> for more, e.g.</p> <blockquote> <p>In order to use variable variables with arrays, you have to resolve an ambiguity problem. That is, if you write <code>$$a[1]</code> then the parser needs to know if you meant to use <code>$a[1]</code> as a variable, or if you wanted <code>$$a</code> as the variable and then the <code>[1]</code> index from that variable. The syntax for resolving this ambiguity is: <code>${$a[1]}</code> for the first case and <code>${$a}[1]</code> for the second.</p> </blockquote> <p><strong>A note on security</strong></p> <p>As this is the accepted answer, I'm going to add that you shouldn't use user input so blindly, there may be methods on $obj which you wouldn't want be called.</p> <p>You could, for example, check the method name against an array of allowed methods, e.g.</p> <pre><code>$method=$_GET["func"]; $ok=in_array($method, array('foo', 'bar', 'frobozz')); </code></pre> <p>Alternatively, you could only allow method names which follow a particular pattern, e.g. prefixed with 'ajax':</p> <pre><code>$method=$_GET["func"]; $ok=preg_match('/^ajax[A-Za-z]/', $method); </code></pre> <p>Or a variation on that idea, where the prefix is added to the passed method name so that only methods with that prefix can be called</p> <pre><code>$method='ajax'.preg_replace('/[^A-Za-z]/', '', $_GET["func"]); </code></pre> <p>There are other ways, but hopefully that illustrates a basic tenet: <em>assume your worst enemy constructed the <code>$_GET</code> array!</em></p>
Is using .h as a header for a c++ file wrong? <p>Is using .h as a header for a c++ file wrong?</p> <p>I see it all over the place, especially with code written in the "C style". I noticed that Emacs always selects C highlighting style for a .h header, but c++ for hpp or hh. </p> <p>Is it actually "wrong" to label your headers .h or is it just something which annoys me?</p> <p>EDIT:</p> <p>There is a good (ish) reason why this annoys me, if I have project files labelled, 'hpp &amp; cpp' I can get away with 'grep something *pp' etc. otherwise I have to type '.h cpp'</p>
<p>nothing wrong with that. This is the default with Microsoft Visual C++.</p> <p>Just follow the standard you like, and stick with it.</p>
I have to integrate an existing asp.net web app into another page by using jquery's load() method <p>I'm a bit stumped...</p> <p>I have to integrate an existing, simple asp.net web forms app including postbacks etc. into another external site with a jquery load() call., an app that was intended to be integrated through an iframe. I doubt that's possible without a rewrite of the app.</p> <p>The app is a basic questionnaire that leads the user to a product suggestion at the end.</p> <p>Does anyone have any pointers to how I could solve this? I guess I will probably have to rewrite the app with web services and dynamic calls to RenderUserControls, I will also need access to the page that calls the load() and write additional jQuery methods to handle the user input... I will probably have to remove all of asp.net's postback calls and rewrite the handling of the user input?</p> <p>Any pointers or helping ideas? I wish I could already shell out a bounty for this because it is rather urgent.</p>
<p>First of all you should note that the <code>load()</code> function, like all ajax, can only work on the same domain. So if the 'external site' is on another domain ajax is the wrong choice. </p> <p>It does sounds like a lot of hard work, depending on the complexity of the page. Postbacks can occur in many places - image clicks, combo selects, etc. Also, there are hidden fields to worry about, like the View State and Event handler - those have the same names on both pages. You'll have an easier time if the external site has no state and postbacks.</p> <p>If the pages are relatively simple this can probably be done. It's been my experience that forms don't work well in other forms, so you'll have to remove one of them (probably the loaded page's form), or place them one after the other. As you've mentioned, you'll have to rewrite postbacks, you'll want to <a href="http://docs.jquery.com/Ajax/serialize" rel="nofollow">serialize</a> the data. You may be able to change this string to fit the names on the original page (if you've changed the name of the viewstate, etc, it's easier to change it back on the serialized string than to mess with IDs), post it to the original page, and load again.</p> <p>Personally, as much as I like jQuery, and as much as this project sounds interesting (and it is), I'd probably go for a server-side solution. It sounds much easier to create a user control (that may use ajax itself), or to the expose the page's functionality using web services or better, generic handlers.</p>
cleanup php session files <p>On my website I use PHP sessions. Session information is stored in files in my ./session path. After a few months I discovered that these session files are never deleted, by now there are 145.000 of them in this directory. </p> <p>How should these be cleaned up? Do I have to do it programmatically, or is ther a setting I can use somewhere that would have this cleanup happen automatically?</p> <p><strong>EDIT</strong> forgot to mention: This site runs at a provider, so I don't have access to a command line. I do have ftp-access, but the session files belong to another user (the one the webserver proces runs I guess) From the first answers I got I think it's not just a setting on the server or PHP, so I guess I'll have to implement something for it in PHP, and call that periodically from a browser (maybe from a cron job running on my own machine at home)</p>
<p>To handle session properly, take a look at <a href="http://ar.php.net/manual/en/session.configuration.php">http://ar.php.net/manual/en/session.configuration.php</a>.</p> <p>There you'll find these variables:</p> <ul> <li>session.gc_probability</li> <li>session.gc_divisor</li> <li>session.gc_maxlifetime</li> </ul> <p>These control the garbage collector (GC) probability of running with each page request.</p> <p>You could set those with <a href="http://ar.php.net/manual/en/function.ini-set.php">ini_set()</a> at the beginning of your script or .htaccess file so you get certainty to some extent they will get deleted sometime.</p>
Can I have an 'offscreen' control? <p>I'm trying to create a <code>DataGridView</code> cell class which hosts a control (all the time, not just while editing). So far, my approach has been to add the control to the grid and try to synchronise its position with that of the cell.</p> <p>Would it be possible instead to keep the cell offscreen, route mouse and keyboard events to it, and paint it onto the cell?</p> <p>UPDATE: By 'offscreen', I don't mean that it should be added to another control such that it isn't displayed; I mean that it should never be added to another control at all.</p>
<p>You can create a control without adding it to the form, then using it as the Cell editor whenever you need to. Usually with grids, when you click on a cell to edit it, it's going to either create a new control and put it in the right place, or it's going to use an existing control. You can make this process a lot easier by creating your own custom cell / column types. See this MSDN page: <a href="http://msdn.microsoft.com/en-us/library/7fb61s43.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/7fb61s43.aspx</a>.</p> <p>Most grids (including DataGridView and 3rd Party Grids) have a facility for adding custom cells.</p>
Modify value of a Django form field during clean() <p>I am adding custom validation to my forms and custom fields in my Django app. I would like to be able to modify the value of a field when triggering an error. For example, if there is an error, the form should be redisplayed with the field value corrected by clean() and an error message "Data has been corrected below. Click save again to confirm if these changes are OK"</p> <p>I've tried returning the modified data in cleaned_data[] like this but it doesn't work. It displays the error correctly, but the field value is not updated with the corrected HTML when the form is redisplayed.</p> <pre><code>class T34AtividadeForm(ModelForm): def clean(self): # Return cleaned html error,html = fix_imgs(cleaned_data.get("a34_descricao")) if error: msg = u'Data has been corrected below. Click save again to confirm if these changes are OK'; self._errors['a34_descricao'] = ErrorList([msg]) # This doesn't work cleaned_data["a34_descricao"] = html # This doesn't work either self.a34_descricao = html return cleaned_data </code></pre> <p>I'd also like to do the same thing with a field, but since the errors are triggered by exception, I don't get a chance to return the corrected value. Like the form clean() method, the error is displayed correctly, but the value is not updated.</p> <pre><code>class HTMLField(CharField): widget = HTMLTextarea def clean(self, value): value = super(HTMLField,self).clean(value) error,html = fix_imgs(value) if error: # This doesn't work self.value = html raise forms.ValidationError(u'Data has been corrected below. Click save again to confirm if these changes are OK.') return html </code></pre>
<p>change self data in the clean method to change the value which gets displayed</p>
ServiceTracker in OSGi r4.1 <p>Im using a <code>org.osgi.util.tracker.ServiceTracker</code> (PrintableServiceTracker implements ServiceTrackerCustomizer and simply prints when a new service is added).</p> <pre><code>Filter filter = bc.createFilter("(objectClass=se.enea.print.Printable)"); tracker = new ServiceTracker(bc, filter, new PrintableServiceTracker(bc)); </code></pre> <p>I've read about "pseudo registration" in the new ebook "<a href="http://manning.com/hall/" rel="nofollow">OSGi in action</a>" and I wonder if I have to do pseudo registration explicitly or if the framwork handles this automatically?</p> <p>(Will already installed Printable services be caught by the ServiceTracker. will ServiceTracker.addingService(ServiceReference) be called for each of the pre installed Printable services)</p>
<p>Not sure what pseudo registration means, but the method addingService in PrintableServiceTracker will be called not only for new services but also for existing services. </p>
c# wcf - exception thrown when calling open() on proxy class <p>I have the following problem, basically i have a WCF service which operates fine in small tests. However when i attempt a batch/load test i get an <code>InvalidOperationException</code> with the message when the open() method is called on the proxy class:</p> <blockquote> <p><em>"The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be modified while it is in the Opened state."</em></p> </blockquote> <p>I have searched google, but cannot find anyone else really quoting this exception message.</p> <p>I guess some further info on the service may be necessary for a diagnosis - when the service receives data through one of it's exposed methods, it basically performs some processing and routes the data to a service associated with the data (different data will result in different routing). To ensure that the service runs as quickly as possible, each cycle of receiving, processing and routing of the data is handled by a seperate thread in the threadpool. could this be a problem arising from one thread calling <code>proxyClass.Open()</code> whilst another is already using it? would a <code>lock</code> block eliminate this problem, if indeed this is the problem?</p> <p>thanks guys, - ive been workikng on this project for <strong>too</strong> long, and finally want to see the back of it - but this appears to be the last stumbling block, so any help much appreciated :-)</p> <p>========================================================================= <br /><br /> thanks for highlighting that i shouldn't be using the <code>using</code> construct for WCF proxy classes. However the MSDN article isn't the most clearly written piece of literature ever, so one quick question: should i be using a proxy as such:</p> <pre><code>try { client = new proxy.DataConnectorServiceClient(); client.Open(); //do work client.Close(); } .................. //catch more specific exceptions catch(Exception e) { client.Abort(); } </code></pre>
<p>How are you using proxy? Creating new proxy object for each call. Add some code regarding how you use proxy. </p> <p>Desired way of using proxy is for each call you create new proxy and dispose it once completed. You are calling proxy.open() for opened proxy that is wrong. It should be just called once.</p> <p>Try using something like below in finally, as wcf does not dispose failed proxy and it piles up. Not sure it would help but give it a shot.</p> <pre><code>if (proxy.State == CommunicationState.Faulted) { proxy.Abort(); } else { try { proxy.Close(); } catch { proxy.Abort(); } } </code></pre> <p>Why to do this? <a href="http://msdn.microsoft.com/en-us/library/aa355056.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa355056.aspx</a></p> <p>Code you posted above would work but you will alway be eating exception. So handle wcf related exception in seperate catch and your generic catch with Excelion would abort then throw exception.</p> <pre><code>try { ... client.Close(); } catch (CommunicationException e) { ... client.Abort(); } catch (TimeoutException e) { ... client.Abort(); } catch (Exception e) { ... client.Abort(); throw; } </code></pre> <p>Also if you still want to use convenience of using statement then you can override dispose method in your proxy and dispose with abort method in case of wcf error.</p> <p>And do not need to call .Open() as it will open when required with first call.</p>
browserCaps in an External Config File <p>The BrowserCaps setting is rather quite long. Is there a way to factor it into an external config file.</p> <p>does anyone know the markup?</p>
<ol> <li><p>Create a new web.config file in your project and call it browserCaps.config</p></li> <li><p>Paste the XML of the latest browserCaps (<a href="http://owenbrady.net/browsercaps/CodeProject.xml" rel="nofollow">http://owenbrady.net/browsercaps/CodeProject.xml</a>) into this new file.</p></li> <li><p>In the existing web.config file of your project, add the following key within the <code>&lt;system.web&gt;&lt;/system.web&gt;</code> section:</p> <p><code>&lt;browserCaps configSource="browserCaps.config"/&gt;</code></p></li> </ol> <p>Also see this link: <a href="http://weblogs.asp.net/fmarguerie/archive/2007/04/26/using-configsource-to-split-configuration-files.aspx" rel="nofollow">http://weblogs.asp.net/fmarguerie/archive/2007/04/26/using-configsource-to-split-configuration-files.aspx</a></p>
ColSpan for Silverlight Datagrid <p>I have a need to customize a Datagrid, for a TimeManagement system, using rowspawns. My desired look is something like:</p> <pre><code>Customers| Projects | Tasks | Moanday | Tuesday | Wednesday | Thursday | Friday | | | Task 1 | 0 | 0 | 0 | 0 | 0 | Customer1| Project 1 | Task 2 | 0 | 0 | 0 | 0 | 0 | | | Task 3 | 0 | 0 | 0 | 0 | 0 | </code></pre> <p>Preferebly, i would like to be able to just give the DataGrid.ItemSource a List of Customers and it should work based on that. My current Model is</p> <pre><code> public class Customer { public string Name{get; set;} public List&lt;Project&gt; Projects{ get; set;} } public class Project { public string Name {get; set;} public List&lt;Task&gt; Tasks{ get; set; } } public class Task { public string Name { get; set;} public Week Week { get; set; } } public class Week { public double Monday { get; set; } ... } </code></pre> <ul> <li>I would like the Customer Cell to have a rowspan over all of its project rows.</li> <li>I would like the Project cell to have a rowspan over all of its task rows. </li> <li>And, most importantly, i need the user to be able to navigate around using the arrowkeys on the keyboard.</li> </ul> <p>My first attempt was to create new datagrids inside cells of another datagrid. It seems a user is not able to navigate from one datagrid to another using the arrowkeys.</p> <p>Any help is much appreciated.</p>
<p>Take a look at the "RowDetailsTemplate" in the DataGrid. It's a section that can be expanded beneath a row. Inside the RowDetailsTemplate you can add whatever you need, such as a grid or even a datagrid. Set the RowDetailsVisibilityMode attribute to Visible, and it will always be shown.</p> <p>Good luck.</p> <p>--Matt</p>
Programmatically detecting Release/Debug mode (.NET) <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/629674">How to find out if a .NET assembly was compiled with the TRACE or DEBUG flag</a> </p> </blockquote> <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/798971/how-to-idenfiy-if-the-dll-is-debug-or-release-build-in-net">How to idenfiy if the DLL is Debug or Release build (in .NET)</a> </p> </blockquote> <p>What's the easiest way to programmatically check if the current assembly was compiled in Debug or Release mode?</p>
<pre><code>Boolean isDebugMode = false; #if DEBUG isDebugMode = true; #endif </code></pre> <p>If you want to program different behavior between debug and release builds you should do it like this:</p> <pre><code>#if DEBUG int[] data = new int[] {1, 2, 3, 4}; #else int[] data = GetInputData(); #endif int sum = data[0]; for (int i= 1; i &lt; data.Length; i++) { sum += data[i]; } </code></pre> <p>Or if you want to do certain checks on debug versions of functions you could do it like this:</p> <pre><code>public int Sum(int[] data) { Debug.Assert(data.Length &gt; 0); int sum = data[0]; for (int i= 1; i &lt; data.Length; i++) { sum += data[i]; } return sum; } </code></pre> <p>The <code>Debug.Assert</code> will not be included in the release build.</p>
excel macro to change unformatted text data to correctly-typed data <p>I'm populating an excel sheet from DTS, but the resulting output is formatted as text since DTS sees the cells as varchar(255). I'm planning on adding a macro that will format the values correctly as numeric or datetime. What VBA would I use for this?</p> <p>eg the value in a cell shows as "2009-01-01 00:00:00". If I press F2 to edit the cell, then press ENTER, Excel realises it's a date and then formats it according to the cell formatting. I'd like to have some VBA to do the same thing.</p> <p>The problem isn't that the cell-formatting is incorrect, the problem is that Excel is thinking of the data as text instead of datetime or numeric. </p>
<p>Seems you can just assign the value of a cell or range to itself and that lets Excel determine the datatype. You can do this a row at a time, eg: </p> <pre><code>Worksheets("MySheet").Range("A:A").Value = Worksheets("MySheet").Range("A:A").Value </code></pre>
Is there a Java Collection (or similar) that behaves like an auto-id SQL table? <p>Note that I'm not actually doing anything with a database here, so ORM tools are probably not what I'm looking for.</p> <p>I want to have some containers that each hold a number of objects, with all objects in one container being of the same class. The container should show some of the behaviour of a database table, namely:</p> <ul> <li>allow one of the object's fields to be used as a unique key, i. e. other objects that have the same value in that field are not added to the container.</li> <li>upon accepting a new object, the container should issue a numeric id that is returned to the caller of the insertion method.</li> </ul> <p>Instead of throwing an error when a "duplicate entry" is being requested, the container should just skip insertion and return the key of the already existing object.</p> <p>Now, I would write a generic container class that accepts objects which implement an interface to get the value of the key field and use a HashMap keyed with those values as the actual storage class. Is there a better approach using existing built-in classes? I was looking through HashSet and the like, but they didn't seem to fit.</p>
<p>None of the Collections classes will do what you need. You'll have to write your own!</p> <p>P.S. You'll also need to decide whether your class will be thread-safe or not.</p> <p>P.P.S. <a href="http://download.oracle.com/javase/1,5.0/docs/api/java/util/concurrent/ConcurrentHashMap.html" rel="nofollow">ConcurrentHashMap</a> is close, but not exactly the same. If you can subclass or wrap it or wrap the objects that enter your map such that you're relying only on that class for thread-safety, you'll have an efficient and thread-safe implementation.</p>
multiquoted string in .rc2 file, VC++ <p>I was building a VC++ project and i happened to have data some thing like inside Resources.rc2 file</p> <p>"My data contains "multiple quoted string" and also symbols like "&lt;" ">" "\""</p> <p>It seems Quotes and &lt;, >, and \ are needed to be escaped.</p> <p>I'm getting error RC2104 upon compiling with RC.exe in VS08. It terminates the string on first occurance of a quote. What can i do?</p>
<p>Without knowing more about your RC file, try: </p> <p><a href="http://msdn.microsoft.com/en-us/library/k2z28y0f%28VS.71%29.aspx" rel="nofollow">Resource Compiler Error RC2104</a></p>
Is there any preferable way to get user/group information from an Active Directory domain in Python? <p>For a Django application that I'm working on, I wanted to allow group membership to be determined by Active Directory group. After a while of digging through the pywin32 documentation, I came up with this:</p> <pre><code>&gt;&gt;&gt; import win32net &gt;&gt;&gt; win32net.NetUserGetGroups('domain_name.com', 'username') [(u'Domain Users', 7), ...] </code></pre> <p>I spent a while googling before I figured this out though, and the examples I found almost exclusively used LDAP for this kind of thing. Is there any reason why that's to be preferred over this method? Bear a couple things in mind:</p> <ol> <li>I'm not using Active Directory to actually perform authentication, only permissions. Authentication is performed by another server.</li> <li>While it would be nice to have some cross-platform capabilities, this will probably run almost exclusively on Windows.</li> </ol>
<p>AD's LDAP interface has quite a few 'quirks' that make it more difficult to use than it might appear on the surface, and it tends to lag significantly behind on features. When I worked with it, I mostly dealt with authentication, but it's probably the same no matter what you're doing. There's a lot of weirdness in terms of having to be bound as a certain user just to do simple searches that a normal LDAP server would let you do as anonymous.</p> <p>Also, at least as of a year ago, when I worked on this, python-ldap was the only Python LDAP implementation to support anywhere close to the full feature set, since it's built on top of OpenLDAP, However, OpenLDAP is rather difficult to build on Windows (and in general), so most builds will be missing one or more features. Although you're not doing authentication, a lack of SASL/Kerberos support (which was missing at the time I used it) might make things complicated for you.</p> <p>If you have something that works, and only need to run it on Windows, I would really recommend sticking to it; using AD via LDAP can turn into a big project.</p>
How can I prevent page-break in CFDocument from occuring in middle of content? <p>I am generating a PDF file dynamically from html/css using the cfdocument tag. There are blocks of content that I don't want to span multiple pages.</p> <p>After some searching I found that the style "page-break-inside" is supported according to the docs. However in my testing the declaration "page-break-inside: avoid" does no good.</p> <p>Any suggestions on getting this style declaration to work, or have alternative suggestions?</p> <p>Here is an example. I would expect the content in the div tag not to span a page break but it does. The style "page-break-inside: avoid" is not being honored.</p> <pre><code>&lt;cfdocument format="flashpaper"&gt; &lt;cfloop from="1" to="10" index="i"&gt; &lt;div style="page-break-inside: avoid"&gt; &lt;h1&gt;Table Label&lt;/h1&gt; &lt;table&gt; &lt;tr&gt;&lt;td&gt;label&lt;/td&gt;&lt;td&gt;data&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;label&lt;/td&gt;&lt;td&gt;data&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;label&lt;/td&gt;&lt;td&gt;data&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;label&lt;/td&gt;&lt;td&gt;data&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;label&lt;/td&gt;&lt;td&gt;data&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;label&lt;/td&gt;&lt;td&gt;data&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;label&lt;/td&gt;&lt;td&gt;data&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;label&lt;/td&gt;&lt;td&gt;data&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;label&lt;/td&gt;&lt;td&gt;data&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;/cfloop&gt; &lt;/cfdocument&gt; </code></pre>
<p>Not an ideal solution, but I've forced page breaks before blocks that need to be kept together. Use page-break-before to trigger a page break before the block.</p> <p>I don't think there is a way to specifically forbid breaking within (that is honored by the PDF engine).</p>
Help Creating a Style for a ListBoxItem <p>I am new to styles and need help to create a style for a ListBoxItem that will give the item a transparent background then have the Font turn Gold when hovered over. It should not change the color when clicked and return to normal when the mouse moves off. It must still pass the selected object to the PreviewMouseRightButtonDown event for the ListBox</p> <p>I currently use a default dictionary from REUXABLES THEMES, but it is way to much coloring for this portion of the display on the application. </p> <p>Thanks,</p> <pre><code> &lt;DataTemplate x:Key="ItemsTemplate"&gt; &lt;StackPanel Orientation="Vertical" Margin="0,5,0,5" Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollContentPresenter}}}" MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ViewportWidth}" &gt; &lt;TextBlock VerticalAlignment="Top" TextWrapping="Wrap" FontSize="14" Text="{Binding Path=CID}" /&gt; &lt;StackPanel Orientation="Horizontal" Margin="0,5,0,0" &gt; &lt;TextBlock&gt; &lt;Label Foreground="{DynamicResource DisabledForegroundBrush}" &gt;Posted by&lt;/Label&gt; &lt;Label Foreground="{DynamicResource DisabledForegroundBrush}" VerticalContentAlignment="Top" Content="{Binding Path=ACID}" /&gt; &lt;/TextBlock&gt; &lt;TextBlock&gt; &lt;Label Foreground="{DynamicResource DisabledForegroundBrush}" Margin="3,0,0,0"&gt;at&lt;/Label&gt; &lt;Label Foreground="{DynamicResource DisabledForegroundBrush}" Margin="3,0,3,0" VerticalContentAlignment="Top" Content="{Binding Path=Type}" /&gt; &lt;/TextBlock&gt; &lt;TextBlock&gt; &lt;Label Foreground="{DynamicResource DisabledForegroundBrush}"&gt;(&lt;/Label&gt; &lt;Label Foreground="{DynamicResource DisabledForegroundBrush}" VerticalContentAlignment="Top" Content="{Binding Path=Route}" /&gt; &lt;Label Foreground="{DynamicResource DisabledForegroundBrush}"&gt;)&lt;/Label&gt; &lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;Style x:Key="ItemsListBox" TargetType="{x:Type ListBoxItem}"&gt; &lt;Setter Property="SnapsToDevicePixels" Value="true"/&gt; &lt;Setter Property="Background" Value="{DynamicResource Transparent}"/&gt; &lt;Setter Property="BorderBrush" Value="{DynamicResource Transparent}"/&gt; &lt;Setter Property="BorderBrush" Value="{DynamicResource Transparent}"/&gt; &lt;Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/&gt; &lt;/Style&gt; &lt;ListBox x:Name="ListViewFlightPlans" Grid.Column="0" ItemTemplate="{DynamicResource ItemsTemplate}" MaxWidth="800" ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderBrush="Black" BorderThickness="2,0,0,1"&gt; &lt;/ListBox&gt; </code></pre> <p>Dave</p>
<p>Unfortunately changing <code>BorderBrush</code> for the <code>ListBoxItem</code> won't have your desired effect, since the <code>Border</code> with the selection highlight is internal to the <code>ControlTemplate</code> of the <code>ListBoxItem</code>.</p> <p>Instead, you can add a new <code>Brush</code> resource with the key of <a href="http://msdn.microsoft.com/en-us/library/system.windows.systemcolors.highlightbrushkey.aspx" rel="nofollow">SystemColors.HighlightBrushKey</a>, this is the key that the <code>ListBoxItem</code> uses for setting the selection highlight color.</p> <p>The inactive selection brush uses the key of <a href="http://msdn.microsoft.com/en-us/library/system.windows.systemcolors.controlbrushkey.aspx" rel="nofollow">SystemColors.ControlBrushKey</a>, so if you override both of these with a transparent <code>Brush</code> you're guaranteed not to have any selection color. You can read more about it in <a href="http://blogs.msdn.com/wpfsdk/archive/2007/08/31/specifying-the-selection-color-content-alignment-and-background-color-for-items-in-a-listbox.aspx" rel="nofollow">this article</a>.</p> <p>Here's an example with everything but your <code>DataTemplate</code>:</p> <pre><code>&lt;Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Grid.Resources&gt; &lt;x:Array x:Key="data" Type="{x:Type sys:String}"&gt; &lt;sys:String&gt;a &lt;/sys:String&gt; &lt;sys:String&gt;bb&lt;/sys:String&gt; &lt;sys:String&gt;ccc&lt;/sys:String&gt; &lt;sys:String&gt;dddd&lt;/sys:String&gt; &lt;/x:Array&gt; &lt;/Grid.Resources&gt; &lt;ListBox ItemsSource="{StaticResource data}"&gt; &lt;ListBox.Resources&gt; &lt;Style TargetType="{x:Type ListBoxItem}"&gt; &lt;Style.Resources&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/&gt; &lt;/Style.Resources&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Setter Property="Foreground" Value="Black"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Setter Property="Foreground" Value="Gold"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/ListBox.Resources&gt; &lt;/ListBox&gt; &lt;/Grid&gt; </code></pre>
Running SSIS packages in separate memory allocations or increasing the default buffer size? <p>I have a SSIS package that has a child package that is failing. The error message isn't very helpful.</p> <blockquote> <p>The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020</p> </blockquote> <p>The problem seems to be I am running out of Virtual Memory to complete the job.</p> <p>I found a forum thread that may help solve the problem. <a href="http://social.msdn.microsoft.com/forums/en-US/sqlintegrationservices/thread/d6d52157-0270-4200-a8c2-585fa9a0eed5/">http://social.msdn.microsoft.com/forums/en-US/sqlintegrationservices/thread/d6d52157-0270-4200-a8c2-585fa9a0eed5/</a></p> <p>From the solutions offered I am unsure though how to:</p> <ol> <li>increase default buffer size</li> <li>Allocate a child pacakage into it's own memory allocation.</li> </ol> <p>I am running the package daily in SQL Server 2005. I was running fine daily up until the 12th. I am assuming the dat file that we are using to import data into the database grew to a size that was to large for the database to handle. It's only a 8.90MB csv file though. The import is a straight column to column import.</p> <p>The problem child package is step 1 and fails and continues and successfully completes the next 8 steps.</p>
<p>How much memory is allocated to SQL Server? How much memory is allocated outside of the SQL Server process space? </p> <p>The reason I ask is becuase SSIS memory is allocated from the memToLeave area of memory that sits outside of the SQL Server process space.</p> <p>See <a href="http://www.johnsansom.com/index.php/2009/03/sql-server-memory-configuration-determining-memtoleave-settings/" rel="nofollow">here</a> for details on configuring the amount of memory available to the memToLeave portion of memory.</p> <p>For generic performance tuning of SSIS consult the following article.</p> <p><a href="http://technet.microsoft.com/en-gb/library/cc966529.aspx" rel="nofollow">http://technet.microsoft.com/en-gb/library/cc966529.aspx</a></p> <p>I hope this makes sense but feel free to drop me a line once you have digested the material.</p> <p>Cheers,</p>
GIS Draw a parabola flight path in kml for google earth <p>I have to display flight paths on google earth and (still I got the exact flight plan path) want to show in a parabola way (markting side). From the taking off to the landing points. Basically I'm looking for the math formula to calculate latlng point with altitudes to display the parabola path.</p> <p>I see how to do the parabolic view with the altitude parameter. But there is less easy, how to get points on a path from two cordinates (start; end).</p> <p>Thank you !</p>
<p>Maybe I'm wrong about this, but if I remember my physics right, and if the distance between the two points is relatively small compared to the earth's radius, aside from altitude, the path will just follow a <a href="http://en.wikipedia.org/wiki/Great%5Fcircle" rel="nofollow">great circle</a>.</p> <p>If you write the coordinates as parametric equations as a function of time, you'd get:</p> <pre><code>gamma = v_horz/R * t altitude = g * t * (T0 - t) / 2 (where T0 = 2*v_vert/g = flight time, R = earth radius, g = earth's gravity) (vertical velocity = derivative of altitude = g/2*T0 - gt = v_vert - gt </code></pre> <p>where gamma = the angle along the great circle arc followed by the projectile. You know the beginning and endpoints, so you can use <a href="http://www.jqjacobs.net/astro/arc%5Fform.html#formula" rel="nofollow">spherical trigonometry</a> to figure out the arc distace G0 between start and endpoints. G0 = gamma at time T0 (when projectile lands). This tells you what omega_horz must be (= G0*R / T0).</p> <p>You can then use spherical trigonometry again to figure out the lat/longitude at any point along the great circle. (use similar triangles -- it's too late in the day for my brain to work through the math properly, sorry) </p> <p>assumptions:</p> <p>A. </p> <ul> <li>distance between start/end points is small compared to earth's radius</li> <li>the flight in question is a ballistic trajectory (some mass M going up and down under the force of gravity alone, no thrust or lift)</li> <li>we're talking about the planet Earth so you can make certain assumptions for the radius and the force of gravity g</li> <li>ignore air resistance (good luck in real life)</li> </ul> <p>OR</p> <p>B.</p> <ul> <li>this is for marketing types so you just want something that looks parabolic, so just use the assumptions in A anyway</li> </ul> <p><hr /></p> <p><strong>EDIT:</strong> See also these wikipedia articles on <a href="http://en.wikipedia.org/wiki/Trajectory%5Fof%5Fa%5Fprojectile" rel="nofollow">projectile trajectories</a> and <a href="http://en.wikipedia.org/wiki/Great-circle%5Fdistance" rel="nofollow">great circle distance</a>.</p>
How to update and order by using ms sql <p>Ideally I want to do this:</p> <pre><code>UPDATE TOP (10) messages SET status=10 WHERE status=0 ORDER BY priority DESC; </code></pre> <p>In English: I want to get the top 10 available (status=0) messages from the DB and lock them (status=10). A message with a higher priority should be gotten first.</p> <p>unfortunately MS SQL doesn't allow an order by clause in the update.</p> <p>Anyway how to circumvent this?</p>
<pre><code>WITH q AS ( SELECT TOP 10 * FROM messages WHERE status = 0 ORDER BY priority DESC ) UPDATE q SET status = 10 </code></pre>
Sending Rich Text Format email using Outlook 2003 <p>I am trying to send a Rich Text Format email message using Outlook 2003. The following code results the RTF HTML source code to be dumped into the mail message body.</p> <p>What should I do in order to fix that, and make Outlook display the formatted data and not the source HTML ?</p> <pre><code>import win32com.client RTFTEMPLATE = """&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"&gt; &lt;HTML&gt; &lt;HEAD&gt; &lt;META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; = charset=3Dus-ascii"&gt; &lt;META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version = 08.00.0681.000"&gt; &lt;TITLE&gt;%s&lt;/TITLE&gt; &lt;/HEAD&gt; &lt;BODY&gt; &lt;!-- Converted from text/rtf format --&gt; &lt;P DIR=3DLTR&gt;&lt;SPAN LANG=3D"en-us"&gt;&lt;FONT = FACE=3D"Calibri"&gt;%s&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN = LANG=3D"en-us"&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;/BODY&gt; &lt;/HTML&gt;""" Format = { 'UNSPECIFIED' : 0, 'PLAIN' : 1, 'HTML' : 2, 'RTF' : 3} profile = "Outlook" subject="Subject" body = "Test Message" session = win32com.client.Dispatch("Mapi.Session") outlook = win32com.client.Dispatch("Outlook.Application") session.Logon(profile) mainMsg = outlook.CreateItem(0) mainMsg.To = "test@test.test" mainMsg.Subject = subject mainMsg.BodyFormat = Format['RTF'] mainMsg.Body = RTFTEMPLATE % (subject,body) mainMsg.Send() </code></pre> <p>EDIT: When using HTMLBody instead of Body, Outlook detects the message as HTML and not as RTF.</p>
<p>If you must use RTF, you will need to convert your HTML to RTF format. Check out the <a href="http://pypi.python.org/pypi/zopyx.convert/1.1.9" rel="nofollow">zopyx package</a>.</p> <p>To use HTML, change the line:</p> <pre><code>mainMsg.Body = RTFTEMPLATE % (subject,body) </code></pre> <p>to:</p> <pre><code>mainMsg.HTMLBody = RTFTEMPLATE % (subject,body) </code></pre>
WCF Service invoking - without any reference added <p>I want to invoke a wcf service for testing on the http layer. I do not want to add a service reference and create a proxy and invoke. I want to create a new web test(VSTS) which sends a http request to the service and posts(Http post) the request in http body as an xml.</p> <p>I have service metadata, with which I can see the datacontracts, but the wsdl:operation has only the operation name, wsdl:input is just blank.</p> <p>On the Contary, an asmx service will have the soap request in the metadata which can be copied as the http request body, with the parameters replaced.</p> <p>How to build a wcf service xml body from scratch just by looking at the service metadata (no access to the service logs as well), have got just the end point.</p> <p>It is something like</p> <pre><code>&lt;root&gt; &lt;element1&gt;element1&lt;/element1&gt; &lt;element2&gt;element2&lt;/element2&gt; &lt;/root&gt; </code></pre> <p>But, how to find out this, root has to be some thing like </p> <pre><code>&lt;FunctionRequest xmlns=""http://schemas...."" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""&gt; </code></pre> <p>(tested for a local service and worked)</p> <p>Now, without having access to service logs(svctraceviewer logs), not able to add a service reference, not able to use svcutil.exe(certificate based service), just only with metadata - wsdl, is there a way to find out the request that is to be sent to service?</p>
<p>Well, you will have to create proxy - either statically by adding a service reference or running svcutil on your service metadata, or you can construct it dynamically totally in code, if you wish.</p> <p>In that case, you'd have to have your service contract (ISomethingService) at hand, and check out the <a href="http://msdn.microsoft.com/en-us/library/ms734681.aspx" rel="nofollow">ChannelFactory &lt; ISomethingService > ()</a> concept - that should get you started.</p> <p>Marc</p>
RFCs for content-type header? <p>I've looked @ <a href="http://www.faqs.org/rfcs/rfc2231.html" rel="nofollow">rfc 2231</a> and <a href="http://www.faqs.org/rfcs/rfc2183.html" rel="nofollow">2183</a>. Dealing with a multipart/related mime payload.</p> <p>I'm trying to decypher if the following is syntactically correct, specifically the "start" attribute for the first Content-Type, but I haven't been able to find the correct RFC.</p> <pre><code>Content-Type: multipart/related; boundary="=_34e1b39f5c290f66360ff510d4c38da4"; type="application/smil"; start="&lt;cid:eaec2c30d892902b14044d57dbb6ff85&gt;" --=_34e1b39f5c290f66360ff510d4c38da4 Content-ID: &lt;eaec2c30d892902b14044d57dbb6ff85&gt; Content-Type: application/vnd.oma.drm.message; boundary=ihvdxymhvdhobklkqbcn; name="IrishJi2.dm"; Content-Disposition: attachment; filename="IrishJi2.dm"; --ihvdxymhvdhobklkqbcn Content-Type: audio/mpeg Content-Transfer-Encoding: binary </code></pre> <p>Some background information for the curious. application/vnd.oma.drm.* file types is just a wrapper around a payload item (mp3,jpg, etc) that tells cellular devices the wrapped file is to be considered protected payload and not to allow it to be forwarded or transfered off the phone in anyway. If not for contractual obligations I'd just rip the wrapper off, send the payload on, and be happy, but that is too easy and probably illegal.</p>
<p>From <a href="http://www.ietf.org/rfc/rfc2387.txt" rel="nofollow"><strong>RFC 2387</strong> (The MIME Multipart/Related Content-type)</a>:</p> <blockquote> <p><strong>3.2. The Start Parameter</strong></p> <p>The <code>start</code> parameter, if given, is the <code>content-ID</code> of the compound object's "root". If not present the "root" is the first body part in the Multipart/Related entity. The "root" is the element the applications processes first.</p> </blockquote>
silverlight button does not stretch? <p>I have the below xaml markup, the button does not seen to stretch across the screen instead its left aligned. It is contained in a stack panel. What am I doing wrong here?</p> <pre><code> &lt;Grid&gt; &lt;ListBox Name="SideNavBar"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Vertical" HorizontalAlignment="Stretch"&gt; &lt;Button Content="{Binding}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;/Grid&gt; </code></pre>
<p>It illogical for a StackPanel to stretch because it's job is to place each child control in a row or a column, side by side.</p> <p>I think the same thinking applies to ListBox, but I'm unable to confirm at the moment.</p>
dynamic load data from xml to drop down box with jquery <p>I took over a small web application. I am learning JQuery so I like to rewrite the current java script with JQuery. Here is what I have 1. the xml file as following</p> <pre><code>&lt;courses&gt; &lt;course title="math"&gt; &lt;time&gt;1:00pm&lt;/time&gt; &lt;time&gt;3:00pm&lt;/time&gt; &lt;/course&gt; &lt;course title="physic"&gt; &lt;time&gt;1:00pm&lt;/time&gt; &lt;time&gt;3:00pm&lt;/time&gt; &lt;/course&gt; &lt;/courses&gt; </code></pre> <ol> <li>I like to load to drop down box1 with the title.</li> <li>when select the title from the box1, the drop down box2 will fill in the time that response to the title.</li> </ol> <p>Thanks for any tips and helps.</p>
<p>This should get you started:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { var course_data; // variable to hold data in once it is loaded $.get('courses.xml', function(data) { // get the courses.xml file course_data = data; // save the data for future use // so we don't have to call the file again var that = $('#courses'); // that = the courses select $('course', course_data).each(function() { // find courses in data // dynamically create a new option element // make its text the value of the "title" attribute in the XML // and append it to the courses select $('&lt;option&gt;').text($(this).attr('title')).appendTo(that); }); }, 'xml'); // specify what format the request will return - XML $('#courses').change(function() { // bind a trigger to when the // courses select changes var val = $(this).val(); // hold the select's new value var that = $('#times').empty(); // empty the select of times // and hold a reference in 'that' $('course', course_data).filter(function() { // get all courses... return val == $(this).attr('title'); // find the one chosen }).find('time').each(function() { // find all the times... // create a new option, set its text to the time, append to // the times select $('&lt;option&gt;').text($(this).text()).appendTo(that); }); }); }); &lt;/script&gt; Courses: &lt;select id='courses'&gt; &lt;option value='0'&gt;----------&lt;/option&gt; &lt;/select&gt; &lt;br&gt; Times: &lt;select id='times'&gt; &lt;option value='0'&gt;----------&lt;/option&gt; &lt;/select&gt; </code></pre> <h2>What it is doing:</h2> <p>I am using <code>$(document).ready();</code> to wait until the page is ready. Once it is, I am loading all the data from the file <code>courses.xml</code> (which you would change to whatever returns your XML file). Once I get this data, I populate the courses <code>&lt;select&gt;</code> with the value of all the courses in the XML. I then bind a trigger to fire everytime the courses <code>&lt;select&gt;</code> is changed. When this happens, I find the course which was selected and loop through all its times appending them to the times <code>&lt;select&gt;</code>. </p> <p>Tested and works.</p>
How do I copy files to another directory using MSBuild? <p>I'm trying to copy several files in the $(TargetDir) to another folder (e.g. C:\BinCache), but for whatever reason I cannot get MSBuild to stop complaining.</p> <pre><code> &lt;Target Name="AfterBuild"&gt; &lt;Copy SourceFiles="$(TargetDir)\*.*" DestinationFolder="C:\BinCache" /&gt; &lt;/Target&gt; </code></pre> <p>What am I doing wrong here?</p> <p>EDIT: The solution is to use a CreateItem task. Presumably, Visual Studio 2008 removes this restriction. Thanks Scott!</p> <pre><code>&lt;Target Name="AfterBuild"&gt; &lt;CreateItem Include="$(TargetDir)\*.*"&gt; &lt;Output TaskParameter="Include" ItemName="SourceFiles" /&gt; &lt;/CreateItem&gt; &lt;Copy SourceFiles="@(SourceFiles)" DestinationFolder="C:\BinCache" /&gt; &lt;/Target&gt; </code></pre>
<p>SourceFiles needs to be an Item list</p> <p>you'll need something like</p> <pre><code>&lt;Target Name="AfterBuild"&gt; &lt;ItemGroup&gt; &lt;SourceFiles Include="$(TargetDir)\*.*" /&gt; &lt;/ItemGroup&gt; &lt;Copy SourceFiles="@(SourceFiles)" DestinationFolder="C:\BinCache" /&gt; &lt;/Target&gt; </code></pre> <p>Just noticed you're on 2005, in that case you'll need to use the CreateItem task</p>
How do I force Visual Studio 2008 to use an Open instance when double clicking a file? <p>Certain non-project files that I use Visual studio for (.build, .xml, free-roaming html and css files) are already associated with visual studio and open in it when i double click them. </p> <p>How can I get them to open in an existing instance of visual studio? Right now If i double-click the same file twice, it will open two instances of visual studio, I'd like it just to basically ignore the second open attempt if there is already an instance of VS open.</p>
<p>Ok Richard helped point me in the right direction a bit, but I think I found exactly what I want.</p> <ol> <li>from an explorer window, go to Tools->Folder Options->File Types tab</li> <li>find the extension you wish to change.</li> <li>If there is a restore button click it.</li> <li>Click Advanced</li> <li>Click New... to create a new action.</li> <li>I set the following:</li> </ol> <p>Action: Open in VS 2008<br> "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" /dde<br> check use dde<br> DDE Message: Open("%1")<br> Application: VisualStudio.9.0<br> DDE Application Not Running: (left blank)<br> Topic: System </p> <ol> <li>Hit Ok</li> <li>Set the new action as the default.</li> <li>Hit Ok, Hit Ok</li> </ol> <p>Now that extension will behave exactly as described in the question. The file will open in an existing VS if visual studio is already open. </p> <p>I also used this to fix a few extensions that got broken when I reinstalled VS 2005 after 2008.</p> <p>Win 7/ VS 2012<br> You can right click a file, go to properties. Then there is an "Opens With" line and a change button. But I don't see a way to force other command line options. VS2012 seems to use the open instance by default.</p>
JQuery/WCF without ASP.NET AJAX: <p>I am proper struggling getting that "magic" moment when WCF is configured nicely and jQuery is structuring its requests/understanding responses nicely.</p> <p>I have a service:</p> <pre><code>&lt;%@ ServiceHost Language="C#" Debug="true" Service="xxx.yyy.WCF.Data.ClientBroker" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %&gt; </code></pre> <p>This was recommended by the man <a href="http://www.west-wind.com/WebLog/posts/310747.aspx" rel="nofollow">Rick Strahl</a> to avoid having to define the behaviours within Web.config.</p> <p>My interface for the WCF service sits in another assembly:</p> <pre><code>namespace xxx.yyy.WCF.Data { [ServiceContract(Namespace = "yyyWCF")] public interface IClientBroker { [OperationContract] [WebInvoke(Method="POST",BodyStyle=WebMessageBodyStyle.Wrapped,ResponseFormat=WebMessageFormat.Json)] IClient GetClientJson(int clientId); } } </code></pre> <p>The concrete service class is:</p> <pre><code>namespace xxx.yyy.WCF.Data { [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] class ClientBroker : IClientBroker { public IClient GetClientJson(int clientId) { IClient client=new Client(); // gets and returns an IClient return client; } } } </code></pre> <p>My IClient is an Entity Framework class so is decorated with DataContract/DataMember attributes appropriately.</p> <p>I am trying to call my WCF service using the methods outlined on Rick Strahl's blog at <a href="http://www.west-wind.com/weblog/posts/324917.aspx" rel="nofollow">http://www.west-wind.com/weblog/posts/324917.aspx</a> (the "full fat" version). The debugger jumps into the WCF service fine (so my jQuery/JSON is being understood) and gets the IClient and returns it. However, when I return the response, I get various useless errors. The errors I am getting back don't mean much. </p> <p>I am using POST.</p> <p>Am I right to be using an Interface instead of a concrete object? As it does get into the WCF service, it does seem to be the encoding of the result that is failing.</p> <p>Does anyone have any ideas?</p>
<p>At first glance there are three problems with your code:</p> <p>1: you should use the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute.aspx" rel="nofollow">ServiceKnownTypeAttribute</a> to specify known types when exposing only base types in your operation contracts:</p> <pre><code>[ServiceContract(Namespace = "yyyWCF")] public interface IClientBroker { [OperationContract] [ServiceKnownType(typeof(Client))] [WebInvoke( Method="GET", BodyStyle=WebMessageBodyStyle.WrappedRequest, ResponseFormat=WebMessageFormat.Json)] IClient GetClientJson(int clientId); } </code></pre> <p>2: You should use <code>WebMessageBodyStyle.WrappedRequest</code> instead of <code>WebMessageBodyStyle.Wrapped</code> because the latter is not compatible with <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.webscriptservicehostfactory.aspx" rel="nofollow">WebScriptServiceHostFactory</a>.</p> <p>3: IMHO using Method="GET" would be more RESTful for a method called GetClientJson than Method="POST"</p> <p>Another advice I could give you when working with WCF services is to use <a href="http://msdn.microsoft.com/en-us/library/ms732023.aspx" rel="nofollow">SvcTraceViewer.exe</a> bundled with Visual Studio. It is a great tool for debugging purposes. All you need is to add the following section to your app/web.config:</p> <pre><code> &lt;system.diagnostics&gt; &lt;sources&gt; &lt;source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"&gt; &lt;listeners&gt; &lt;add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "WcfDetailTrace.e2e" /&gt; &lt;/listeners&gt; &lt;/source&gt; &lt;/sources&gt; &lt;/system.diagnostics&gt; </code></pre> <p>Then invoke the web method and WcfDetailTrace.e2e file will be generated in your web site root directory. Next open this file with SvcTraceViewer.exe and you will see lots of useful information. For example it could say:</p> <blockquote> <p>Cannot serialize parameter of type 'MyNamespace.Client' (for operation 'GetClientJson', contract 'IClientBroker') because it is not the exact type 'MyNamespace.IClient' in the method signature and is not in the known types collection. In order to serialize the parameter, add the type to the known types collection for the operation using ServiceKnownTypeAttribute.</p> </blockquote> <p>Of course you should not forget commenting this section before going into production or you might end up with some pretty big files.</p>
WPF WinForms Interop issue with Enable / Disable <p>I have a WinForms usercontrol hosting a WPF custom Listbox in it. After the WinForms user control gets disabled and then re-enabled the WPF control in the WinForms usercontrol is unresponsive. Has anyone else experienced this?</p> <p>We had to hack a soultion into remove and re-add the element host each time the control gets disable / enabled to fix the issue.</p> <h2>WinForms</h2> <pre><code>wpfControl.Enabled = false; ... wpfControl.Enabled = true; </code></pre> <p>Hack for fixing it in the WinForms EnabledChanged method for the usercontrol</p> <pre><code>if ( Enabled ) { ElementHost oldEh = ctlElementHost; ElementHost eh = new ElementHost(); eh.Name = oldEh.Name; oldEh.Child = null; eh.Child = wpfControl; this.Controls.Remove( ctlElementHost ); this.Controls.Add( eh ); eh.Dock = DockStyle.Fill; oldEh.Dispose(); ctlElementHost = eh; } </code></pre> <p>There seems to be a memory leak where the disposed element hosts are still sticking around until the parent form that was hosting the WinForms usercontrol gets closed.</p>
<p>A co-worker (thanks KwB) of mine managed to find a fix for this issue: <a href="http://support.microsoft.com/kb/955753">http://support.microsoft.com/kb/955753</a> </p> <p>It involves inheriting from ElementHost and manually telling the window region to enable:</p> <pre><code>public class MyElementHost : ElementHost { protected override void OnEnabledChanged(EventArgs e) { SynchChildEnableState(); base.OnEnabledChanged(e); } private void SynchChildEnableState() { IntPtr childHandle = GetWindow(Handle, GW_CHILD); if (childHandle != IntPtr.Zero) { EnableWindow(childHandle, Enabled); } } private const uint GW_CHILD = 5; [DllImport("user32.dll")] private extern static IntPtr GetWindow(IntPtr hWnd, uint uCmd); [DllImport("user32.dll")] private extern static bool EnableWindow(IntPtr hWnd, bool bEnable); } </code></pre>
Database history for client usage <p>I'm trying to figure out what would be the best way to have a history on a database, to track any Insert/Delete/Update that is done. The history data will need to be coded into the front-end since it will be used by the users. Creating "history tables" (a copy of each table used to store history) is not a good way to do this, since the data is spread across multiple tables. </p> <p>At this point in time, my best idea is to create a few History tables, which the tables would reflect the output I want to show to the users. Whenever a change is made to specific tables, I would update this history table with the data as well.</p> <p>I'm trying to figure out what the best way to go about would be. Any suggestions will be appreciated.</p> <p>I am using Oracle + VB.NET</p>
<p>I have used very successfully a model where every table has an audit copy - the same table with a few additional fields (time stamp, user id, operation type), and 3 triggers on the first table for insert/update/delete.<br /> I think this is a very good way of handling this, because tables and triggers can be generated from a model and there is little overhead from a management perspective. The application can use the tables to show an audit history to the user (read-only).</p>
Passing a smart pointer as argument inside a class: scoped_ptr or shared_ptr? <p>I have a class that creates an object inside one public method. The object is private and not visible to the users of the class. This method then calls other <strong>private</strong> methods inside the same class and pass the created object as a parameter:</p> <pre><code>class Foo { ... }; class A { private: typedef scoped_ptr&lt;Foo&gt; FooPtr; void privateMethod1(FooPtr fooObj); public: void showSomethingOnTheScreen() { FooPtr fooObj(new Foo); privateMethod1(fooObj); }; }; </code></pre> <p>I believe the correct smart pointer in this case would be a scoped_ptr, however, I can't do this because scoped_ptr makes the class non copyable if used that way, so should I make the methods like this:</p> <pre><code>void privateMethod1(FooPtr&amp; fooObj); </code></pre> <p>privateMethod1 doesn't store the object, neither keeps references of it. Just retrieves data from the class <em>Foo</em>.</p> <p>The correct way would probably be not using a smart pointer at all and allocating the object in the stack, but that's not possible because it uses a library that doesn't allow objects on the stack, they must be on the Heap.</p> <p>After all, I'm still confused about the real usage of scoped_ptr.</p>
<p>One further possibility is to create the object as a static_ptr for ease of memory management, but just pass the raw pointer to the other private methods:</p> <pre><code>void privateMethod1(Foo *fooObj); void showSomethingOnTheScreen() { scoped_ptr&lt;Foo&gt; fooObj(new Foo); privateMethod1(fooObj.get()); }; </code></pre>
NHibernate fetch="join" mapping attribute does not appear to work <p>Mapping a dictionary with NH. Declaration is as follows:</p> <pre><code>&lt;hibernate-mapping ... &lt;map name="CostsByRole" table="JobAccountingSnapshotCosts" lazy="false" fetch="join" access="nosetter.camelcase-underscore"&gt; &lt;key column="SnapshotId" /&gt; &lt;index column="RoleCode" type="String" /&gt; &lt;element column="Amount" type="Decimal" /&gt; &lt;/map&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>I am expecting a single SQL query to be generated but instead I get two: a select for the actual object, followed by a select for the contents of the dictionary.</p> <p>Any ideas?</p>
<p>HQL queries do not consider the values set for fetch in the mapping. You need to specify them exclusively in each HQL query. Its supposedly by design. The fetch attributes value is used only by Criteria queries and by Load/Get. </p>
How to configure IPython to use gvim on Windows? <p>This really looks like something I should be able to find on Google, but for some reason I can't make heads or tails of it. There's the EDITOR environment variable, the ipy_user_conf.py file, the ipythonrc file, some weird thing about running gvim in server mode and a bunch of other stuff I can't wrap my head around (probably because of lack of sleep).</p> <p>Is there a guide somewhere I can follow, or maybe someone can just outline the steps I need to take?</p>
<p>Setting the EDITOR environment variable to 'gvim -f' seems to work.</p> <pre><code>set EDITOR=gvim -f </code></pre>
Need help displaying xml as html <p>I'm trying to use the Macromedia XSLTransform class to convert XML returned from Amazon Web Services to HTML. Here's the PHP page that calls the transform:</p> <pre><code>&lt;?php require_once('includes/MM_XSLTransform/MM_XSLTransform.class.php'); $restquery = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&amp;AWSAccessKeyId=[myid]&amp;Operation=ItemLookup&amp;ResponseGroup=Large&amp;ItemId=" . htmlspecialchars($_GET["asin"]); $mm_xsl = new MM_XSLTransform(); $mm_xsl-&gt;setXML($restquery); $mm_xsl-&gt;setXSL("aws1.xsl"); echo $mm_xsl-&gt;Transform(); ?&gt; </code></pre> <p>And here's a snippet of the aws1.xsl page</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2006-06-07"&gt; &lt;xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes"/&gt; &lt;xsl:template match="aws:Item"&gt; &lt;html&gt; &lt;body&gt; &lt;table&gt; &lt;tr&gt; &lt;td style="border-bottom:#C0C0C0 dotted 1px;padding:10px"&gt; &lt;table cellpadding="0" cellspacing="0" style="width: 90%;padding:5px"&gt; &lt;tr&gt; &lt;xsl:if test="aws:SmallImage/aws:URL"&gt; &lt;td valign="top" width="50"&gt; &lt;img&gt; &lt;xsl:attribute name="src"&gt; &lt;xsl:value-of select="aws:SmallImage/aws:URL" disable-output-escaping="yes" /&gt; &lt;/xsl:attribute&gt; &lt;xsl:attribute name="border"&gt;0&lt;/xsl:attribute&gt; &lt;/img&gt; &lt;/td&gt; &lt;/xsl:if&gt; &lt;!-- bunch of other stuff --&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>The basic code is working - I get data on the expected ASIN item back. And I know the XSL basically works because if I intentionally put an invalid attribute in I get a parser error. But what I get back is a big unformatted bunch of text instead of HTML. I've tried various <code>&lt;xsl:output method&gt;</code> options, but none seems to work. I thinks it's some kind of encoding or charset problem.</p>
<p>You need to create a rule to match "/" or XSL will implicitly generate one for you based on a to-text conversion of the document tree.</p> <p>I would rewrite the XSL to this:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2006-06-07"&gt; &lt;xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;head&gt;...&lt;/head&gt; &lt;body&gt; &lt;table&gt; &lt;thead&gt;...&lt;/thead&gt; &lt;tbody&gt; &lt;xsl:apply-templates select="//aws:Item"/&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;xsl:template match="aws:Item"&gt; &lt;tr&gt; &lt;td&gt;...&lt;/td&gt; &lt;/tr&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>OR add this template to your existing xsl</p> <pre><code>&lt;xsl:template match="*|@*"&gt; &lt;xsl:apply-templates select="*|@*"/&gt; &lt;/xsl:template&gt; </code></pre> <p>Both templates would match document root ("/") which is the ONLY implicit match that XSL does. This first would make "/" map to the html tag which would create a table in which each table row maps to aws:item. The second would match all nodes (and attributes), output nothing, and then attempt to match all children. The first is better if you only want to process aws:Item, the second is better if you want to process all nodes. The second may (depending on the optimization features of you xslt processor and your particular xslt document) take much longer to process.</p>
How can I execute a PHP script from Java? <p>I have a php script which is executed over a URL. (e.g. www.something.com/myscript?param=xy)</p> <p>When this script is executed in a browser it gives a coded result, a negative or positive number.</p> <p>I want to execute this script from Java code(J2EE) and store that result in some object.</p> <p>I'm trying to use <code>httpURLConnection</code> for that. I establish a connection but can not fetch the result. I'm not sure if I execute the script at all.</p>
<p>If your J2EE app is deployed on the same server the PHP script is on, you can also execute it directly through as an independent process like this:</p> <pre><code> public String execPHP(String scriptName, String param) { try { String line; StringBuilder output = new StringBuilder(); Process p = Runtime.getRuntime().exec("php " + scriptName + " " + param); BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { output.append(line); } input.close(); } catch (Exception err) { err.printStackTrace(); } return output.toString(); } </code></pre> <p>You will pay the overhead of creating and executing a process, but you won't be creating a network connection every time you need to execute the script. I think that depending on the size of your output, one will perform better than the other.</p>
How to program a RPG game in C++ with SDL? <p>I want to know how to program a 2D RPG game in C++ with SDL. </p> <p>I have searched, but was unable to find anything good. Many of the articles were too basic and didn't delve into anything practical. Can anyone help give me some articles, free books or other resources so I can learn how to program a RPG using C++ and SDL?</p> <p>EDIT:</p> <p>I don't need documentation of SDL. I'm programming a RPG Game with SDL, and I need some examples that help me in this task.</p>
<p>Do you have examples of articles that are too simple?</p> <p>Are these too simple: <a href="http://www.devshed.com/c/a/Multimedia/Game-Programming-using-SDL-Getting-Started/">devshed</a> or <a href="http://gpwiki.org/index.php/C:SDL%5Ftutorials">gpwiki</a> ?</p> <p>You might consider studying the topics separately. For example Bruce Eckels has, IMO, the best C++ books, "Thinking in C++ I &amp; II" that will take you from novice to expert (including SQA techniques like unit testing) and they are available for <a href="http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html">free.</a></p> <p>I've found that C++ is a harsh mistress and if you aren't prepared for the language, no tutorial specific to 'SDL and Games' will help much - this is true for any other advanced libraries, toolkits, etc.</p>
In Sql Server, how to convert binary strings to binary? <p>I have some data in string format that represents binary data (e.g. '0x0002'). Is there some function or trick where I can convert these from literal strings to binary? That is, I want '0x0002' to become 0x0002, and SELECT CAST('0x0002' AS BINARY(20)) obviously won't do that. I did come up with some painfully slow process that involves building up SQL Statements and assigning them to a variable and executing that (e.g. "EXEC (@Query)"), but I'm looking for something where I don't have to do that.</p> <p>If it helps, here is a sample table that you can test this on:</p> <pre><code>CREATE TABLE #T (BinaryString VARCHAR(100)) INSERT INTO #T VALUES('0x0000000000000000000000000000000000000002') -- Binary = the integer 2 INSERT INTO #T VALUES('0x000000000000000000000000000000000000007B') -- Binary = the integer 123 </code></pre>
<p><a href="http://support.microsoft.com/kb/104829" rel="nofollow">Older code, SQL 7, sp_hexadecimal</a></p> <p><a href="http://decipherinfosys.wordpress.com/2008/06/11/converting-a-hex-string-to-a-varbinary-or-vice-versa/" rel="nofollow">SQL 2005 (+ 2000 maybe), master.dbo.fn_varbintohexstr</a></p> <p><a href="http://decipherinfosys.wordpress.com/2008/07/31/sql-server-2008-converting-binary-and-character-values/" rel="nofollow">SQL 2008, native</a></p>
Is OpenID necessarily a good choice for eCommerce? <p>As a Single Sign-On implementation, I think OpenID is great. Even so, is it necessarily a good choice for eCommerce? I know it can be used, but should it? Are you risking too much in putting all of one's access details in a single basket? </p> <p>What's the general opinion out there?</p>
<p>When I worked for a large eCommerce company, the company looked at OpenID. Don't get upset by this, but the company rejected OpenID because they didn't like some of the clunkyness of the implementation, and they found that it actually reduced signup rates, when run through sample user community testing (the user community hated it, but they hated alot of things).</p> <p>Bottom line: you absolutely can use it for a eCommerce site, but I would have the database built to allow for a switch if necessary, and have a way to determine if it is gaining or costing customers.</p>
Share a .NET Membership Database with SharePoint? <p>We have an FBA SharePoint implementation using a .NET Membership database. We would like to use this same database and collection of users for a new application. Has anyone tried this? I know in theory that it should work, but SharePoint can be finicky.</p>
<p>I would normally worry a bit too, but it is similar to worrying if Sharepoint shares Active Directory well with another .NET application.</p>
Looking for a creational design pattern <p>I'm trying to find a design pattern I can use to simplify the construction of some objects.</p> <p>Based on an incoming parameter, an custom class, I'm going to create various inheritors from the System.Windows.Forms.Control class.</p> <p>For instance, if the custom class has one of its members set to 'ChkBox', I want my class to return a System.Windows.Forms.CheckBox, or if the member is 'List' I want my class to return a ComboBox.</p> <pre><code>public CustomClass() { FieldType type; } </code></pre> <p>and</p> <pre><code>GetControl(CustomClass type); </code></pre> <p>The common thing is that all the classes I want to create all have Control as it's base class. Having this in mind I imagine there is a way to set the members on the base class in only one place.</p> <p>Do you know of any design pattern I can use to solve this?</p>
<p>The <a href="http://en.wikipedia.org/wiki/Factory%5Fmethod%5Fpattern" rel="nofollow">factory pattern</a></p>
ProgressBar not updating on change to Maximum through binding <pre><code>&lt;ProgressBar Foreground="Red" Background="Transparent" Value="{Binding NumFailed, Mode=OneWay}" Minimum="0" Maximum="{Binding NumTubes, Mode=OneWay, Converter={x:Static wpftools:DebuggingConverter.Instance}, ConverterParameter=Failedprogressbar}" FlowDirection="RightToLeft" Style="{DynamicResource {x:Static wpftools:CustomResources.StyleProgressBarVistaKey}}" /&gt; </code></pre> <p>This is what my progressbar looks like at the moment. The style came from <a href="http://mattserbinski.com/blog/look-and-feel-progressbar" rel="nofollow">http://mattserbinski.com/blog/look-and-feel-progressbar</a> and the DebuggingConverter is a no-op converter that prints the value, type and parameter to the Console. I have verified that the converter for the Maximum is being called when my NumTubes property is changed.</p> <p>Basically, the ProgressBar won't redraw until the Value changes. So, if I have 2 tubes and 1 is failed, even if I add 20 more tubes, the bar is still half filled until the NumFailed changes, then the proportion is updated. I've tried adding spurious notifications of the NumFailed property, but that apparently doesn't work since the value didn't change.</p> <p>Ideas?</p>
<p>It looks like the bar size is calculated in the private method <code>ProgressBar.SetProgressBarIndicatorLength</code>. It's only called from <code>OnValueChanged</code>, <code>OnTrackSizeChanged</code>, and <code>OnIsIndeterminateChanged</code>.</p> <p>You could call <code>SetProgressBarIndicatorLength</code> through reflection, or cycle one of the properties that causes it to be called. This is lame, but it doesn't look like the <code>ProgressBar</code> was designed so that the <code>Maximum</code> and <code>Minimum</code> would be changed in mid-progress.</p> <p>Regardless of which method you choose, you can figure out when the <code>Maximum</code> property changes by using <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dependencypropertydescriptor.addvaluechanged.aspx" rel="nofollow"><code>DependencyPropertyDescriptor.AddValueChanged</code></a>:</p> <pre><code>DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(ProgressBar.MaximumProperty, typeof(ProgressBar))); if (dpd != null) { dpd.AddValueChanged(myProgressBar, delegate { // handle Maximum changes here }); } </code></pre>
How could I get the bits from a string in c#? <p>If I had the following string "Blue Box", how could I get the bits that make up the string in c# and what datatype would I store it in.</p> <p>If I do just the letter "o", I get 111 as the bytes and 111 as the bits. Is it chopping off the 0's and if I do "oo", I get 111 for each o in the byte array, but for the bits, I get the value 28527. Why?</p>
<p>You could do the following:</p> <pre><code>byte[] bytes = System.Text.UTF8Encoding.Default.GetBytes("Blue Box"); BitArray bits = new System.Collections.BitArray(bytes); </code></pre>
How to create a "Processing" page? <p>Can someone tell me how to create to a "Please Wait" page. When the pageload is complete, the default.aspx page shows up. Is there a way to do that? I do not want processing images or anything like that. The actual page would be what I would want.</p>
<p>I wrote a detailed blog post about this a while back. The good news is it is detailed. The bad news is it is very old. It is before AJAX, though it uses JavaScript and touches on some of the things that have made AJAX big.</p> <p>Also, it is for preventing users from clicking "Order" twice and thus causing a double-submit. That is close to what you want, but not exactly the same as what you asked for. However, I think the implementations would be similar. </p> <p><a href="http://www.charlieflowers.com/blog/archives/2006/09/solving%5Fthe%5Fdou.html" rel="nofollow">So, in case it helps, here it is. If it's too old, feel free to ignore it :) </a></p> <p><a href="http://www.charlieflowers.com/blog/archives/aspnet/index.html" rel="nofollow">Oh, and I forgot to mention there's a part 2, equally OLD, but telling how to make a base class for ASP.NET Page classes that all need this feature. Hope it helps in spite of its age.</a></p>
Where can I find a .NET datagrid that performs updates and inserts out of the box? <p>Is there a built-in grid that I could do the following simply:</p> <pre><code>SELECT * FROM MYTABLE </code></pre> <p>It would list all the rows, with paging support.</p> <p>Allow me to update/delete/insert a row by double clicking on it and making it editable etc.</p> <p>Does this exist? Does it require me to write any code to perform the CRUD operations?</p> <p>(any version of ASP.NET is fine)</p>
<p>Take a look at the <a href="http://quickstarts.asp.net/QuickStartv20/aspnet/" rel="nofollow">ASP.NET QuickStart Tutorials</a>. There's a tutorial on how to use the <code>GridView</code> for the purposes of adding data:</p> <blockquote> <p><a href="http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/gridview.aspx" rel="nofollow">ASP.NET Quickstart Tutorials - GridView</a></p> </blockquote> <p>The last example on that page demonstrates how to implement an updatable <code>GridView</code> with no code at all (with the exception of SQL statements). </p> <p>To implement a simple 'insert data' feature, you should take a look at the following tutorial on the same site (scroll down to the last example):</p> <blockquote> <p><a href="http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/detailsview.aspx" rel="nofollow">ASP.NET Quickstart Tutorials: DetailsView</a></p> </blockquote> <p>These should get you started.</p>
Why does T-SQL OpenXML bust with certain characters? <p>I have the following XML that I'm running in SQL Server, and it breaks, why?</p> <pre><code> declare @xml varchar(max) declare @hDoc int set @xml = '&lt;transaction&gt; &lt;item itemId="1" value="Hello World" /&gt; &lt;item itemId="2" value="Hello &amp;World" /&gt; &lt;item itemId="3" value="Hello &lt;World" /&gt; &lt;item itemId="4" value="Hello &gt;World" /&gt; &lt;item itemId="5" value="Hello ’World" /&gt; &lt;/transaction&gt;' exec sp_xml_preparedocument @hDoc OUTPUT, @xml select itemId , value from openxml(@hDoc, '/transaction/item') with ( itemId int, value varchar(max) ) item </code></pre>
<p>The values in the XML contain invalid characters. For XML in general you must escape the less than sign and the ampersand like so: &amp;lt; and &amp;amp;</p> <pre><code> declare @xml varchar(max) declare @hDoc int set @xml = '&lt;transaction&gt; &lt;item itemId="1" value="Hello World" /&gt; &lt;item itemId="2" value="Hello &amp;amp;World" /&gt; &lt;item itemId="3" value="Hello &amp;lt;World" /&gt; &lt;item itemId="4" value="Hello &gt;World" /&gt; &lt;/transaction&gt;' exec sp_xml_preparedocument @hDoc OUTPUT, @xml select itemId , value from openxml(@hDoc, '/transaction/item') with ( itemId int, value varchar(max) ) item </code></pre> <p>However when using openxml certain values won't work in general, specifically that curly apostrophe. I'm not sure what values are invalid, but I know that is one of them. So the solution is to use the native XML type in SQL Server 2005.</p> <pre><code> declare @xml xml set @xml = '&lt;transaction&gt; &lt;item itemId="1" value="Hello World" /&gt; &lt;item itemId="2" value="Hello &amp;amp;World" /&gt; &lt;item itemId="3" value="Hello &amp;lt;World" /&gt; &lt;item itemId="4" value="Hello &gt;World" /&gt; &lt;item itemId="5" value="Hello ’World" /&gt; &lt;/transaction&gt;' select item.value('@itemId', 'int') , item.value('@value', 'varchar(max)') from @xml.nodes('/transaction/item') [transaction](item) </code></pre>
What is the best CASE tool for database development and why? <p>I know there are a large number of CASE tools out there, some better than others, but what are the ones used by those in the field, and why do you use those specific tools?</p> <p>In this case, I am just interested in CASE tools for database design, and more specifically, ones that will let me "draw" the schema diagram, and then will create that schema in the database, as well as take an existing schema and create a diagram</p> <p>Some things to consider might be:</p> <ul> <li>Cost of the tool</li> <li>Can it deal with multiple vendors (eg. MS SQL Server, MySQL, Oracle, PostgreSQL)</li> <li>Ease of use</li> </ul> <p>So, what do you use and why?</p>
<p>Hands down the best data modeling tool is <a href="http://www.ca.com/us/data-modeling.aspx" rel="nofollow">ERWin from CA</a>.</p> <p>It's capable of quite a bit - logical and physical diagrams, multi-dimensional models, full forward and reverse engineering (i.e. generating a database from a diagram, and generating a diagram from a database). It can do more advanced things too, like data placement, volumetrics, etc.</p> <p>For diagramming it supports things like subject areas and different notations (crow's feet and IDEFX1, for example).</p> <p>It supports all major vendor RDBMS.</p> <p>It's pretty expensive for all that - last time I went to check it was $4000.</p> <p>It definitely has its quirks and idiosyncrasies, and a learning curve, but that's to be expected with any tool with many features. </p> <p>Major competitor would be Embarcadero ERStudio. I imagine they are pretty similar.</p> <p>If you want a similar question, <a href="http://stackoverflow.com/questions/30474/database-schema-diagram-design-tool">check here</a>.</p>
Can I get rows from SQLAlchemy that are plain arrays, rather than dictionaries? <p>I'm trying to optimize some Python code. The profiler tells me that SQLAlchemy's _get_col() is what's killing performance. The code looks something like this:</p> <pre><code>lots_of_rows = get_lots_of_rows() for row in lots_of_rows: if row.x == row.y: print row.z </code></pre> <p>I was about to go through the code and make it more like this...</p> <pre><code>lots_of_rows = get_lots_of_rows() for row in lots_of_rows: if row[0] == row[1]: print row[2] </code></pre> <p>...but I've found some documentation that seems to indicate that when accessing row objects like arrays, you're actually still pulling dictionary keys. In other words, the row object looks like this:</p> <pre><code>'x': (x object) '0': (x object) 'y': (y object) '1': (y object) 'z': (z object) '2': (z object) </code></pre> <p>If that's the case, I doubt I'll see any performance improvement from accessing columns by number rather than name. Is there any way to get SA to return results as a list of tuples, or a list of lists, rather than a list of dictionaries? Alternately, can anyone suggest any other optimizations?</p>
<p>Forgive the obvious answer, but why isn't row.x == row.y in your query? For example:</p> <pre><code>mytable.select().where(mytable.c.x==mytable.c.y) </code></pre> <p>Should give you a huge performance boost. <a href="http://www.sqlalchemy.org/docs/05/sqlexpression.html#selecting" rel="nofollow">Read the rest of the documentation.</a></p>
VMware Server 2 on Windows 2008 Server Core <p>I have an older server (retired database box in fact) that doesn't fit the requirements for VMware ESX/ESXi or Microsoft's Hyper-V but runs VMware Server 2 just fine. The host OS is currently Windows 2003 Standard. While it does the job just fine, I could hope for something a bit more "svelte" out of the box. Thus Windows 2008 Server Core caught my eye.</p> <p>Granted, I've never actually built a server core box, but it sounds like it might make a great host for VMware Server. I've yet to find an instance of anyone who's done it though. So, before I pervert a workstation for testing I figured I'd ask here: </p> <p>Anyone tried VMware Server on 2008 server core? Anything to be aware of or gotchas?</p> <p><em>(yes, I could also go with Linux for a thinner host, but this seems like a great excuse to bring up a 2008 server core box!)</em></p> <p>Edit: I guess I should mention this server hosts our development environments.</p>
<p>It won't work. This is answered on <a href="http://www.vmware.com/products/server/faqs.html" rel="nofollow">VMware's FAQ for VMware Server 2:</a></p> <blockquote> <p>Can I install VMware Server 2 on a Core installation of Windows Server 2008 host operating system? </p> <p><strong>No</strong>, VMware Server 2 can only be installed on a Full installation of Windows Server 2008 host operating system. However, both Core and Full installations of Windows Server 2008 are supported as guest operating systems.</p> </blockquote>
How does JIT compiling works for caching? <p>When you write an application in C#, and then run it, will it not be compiled again next time it's run, or everything that's used is gonna be recompiled every time the application starts up?</p> <p>How does JIT compiling works for caching?</p>
<p>For any DLL that is not in the ngen'd, every time you run the application, it will re-JIT the code that is used. There is no caching of the JIT code in between runs of the same non-ngen'd DLL. </p> <p><strong>EDIT</strong> Cleared up a mistake with GAC and NGEN</p>
Create SQL Database from ADO.NET Typed Dataset <p>I have a DataSet defined and designed in visual studio.</p> <p>Who knows of a tool to generate tables in SQL Server to match the dataset.</p>
<p>Here's an article I found very very helpful in building a class to do just that.</p> <p><a href="http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/4929a0a8-0137-45f6-86e8-d11e220048c3/" rel="nofollow">http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/4929a0a8-0137-45f6-86e8-d11e220048c3/</a></p>
Loading a lookup table from a database into a C# program - data structure? <p>I have a table full of id's,categories and weights that I need to reference in my program as I read in records that contain those categories. What is the most efficient method to read those from a database and put into a structure that I can reference?</p> <p>The ID's (and possibly the names) would be unique</p> <p>Data might look like:</p> <pre class="lang-none prettyprint-override"><code>ID,Category,Weight 1,Assignment,5 2,Test,10 3,Quiz,5 4,Review,3 </code></pre>
<p>Your best bet is to read in your table using a DataReader, and put each row into an object containing Category and Weight, then each object into a Dictionary.</p>
GAC vs JIT <p>Is everything under the GAC precompiled (ngened)? If so, then all of .NET is precompiled, so it's not possible for the CLR to optimize them at runtime?</p> <p>Like if you use List in your application then CLR will not be able to optimize the List itself, but only how it's used in your app? Doesn't this defeat the purpose of JIT, to get lots of optimizations at runtime? So effectively losing all the potential optimizations for the BCL?</p>
<p>No, the GAC is not automatically pre-JITted; however, GAC is a pre-requisite to pre-JIT. Actually, only a small minority of things are pre-JITted. Besides which - if the BCL was pre-JITted, then those optimisations <em>would have <strong>already</strong> been done</em> by NGEN, so the " losing all the potential optimizations" is a non-issue.</p>
Implementation: How to retrieve and send emails for different Gmail accounts? <p>I need advice and how to got about setting up a simple service for my users. I would like to add a new feature where users can send and receive emails from their gmail account. I have seen this done several times and I know its possible.</p> <p>There use to be a project for "Libgmailer" at sourceforge but I think it was abandoned. Is anyone aware of anything similar?</p> <p>I have found that Gmail has a Python API but my site is making use of PHP.</p> <p>I really need ideas on how to best go about this!</p> <p>Thanks all for any input</p>
<p>any library/source that works with imap or pop will work.</p>
What do you want an iPhone library to do for you? <p>I'm an undergraduate university student who also writes iPhone applications. Next year I'm expected to do a final project, something that lasts the full year and involves a fair bit of software engineering.</p> <p>My original plan was to write an object-relational wrapper around SQLite for the iPhone (or rather, to massively clean up and extend one I already have) and ultimately release it as open source. Unfortunately, with Core Data being added to iPhone OS 3.0, that's no longer really necessary. (At least, that's how it seems to me; any opinions on this?)</p> <p>However, I'd still like to do a useful, technically interesting iPhone-related project next year. So here's my question: what do developers need? What sort of problems do you encounter in your apps which seem like they could be handled by some sort of library or framework? My focus is generally more on utility, productivity, and communication apps than games. And since I'm proposing this to a university, something that's either theoretically interesting or attractive to potential students would be preferred. And of course, it'll need to be something that they <em>haven't</em> added to the new version of iPhone OS.</p>
<p>It's in the early stages, but a bunch of scientifically-minded Cocoa developers (headed by Drew McCormack) have joined together to start a BSD-licensed data charting / plotting / visualization framework called <a href="http://code.google.com/p/core-plot/" rel="nofollow">Core Plot</a> (mailing list <a href="http://groups.google.com/group/coreplot-discuss?hl=en&amp;pli=1" rel="nofollow">here</a>). This framework is cross-platform between Mac and iPhone, relying on Core Animation for rendering.</p> <p>While you wouldn't be starting your own project fresh, contributing to this open source framework would be technically challenging and I believe that the framework will have far-reaching applications. I'm sure that the university would be impressed by the potential scientific and educational uses of such a framework.</p>
Print designers moving to web ... what do they need to know? <p>I'm trying to compile a guide for students used to publishing in print who are learning web design.</p> <p>Some obvious things which web developers know but they don't:</p> <ul> <li>You can't rotate graphics in HTML</li> <li>All objects have to be rectangular, you can't have a circular DIV</li> <li>Many typographical effects in their repertoire can't be achieved</li> </ul> <p>Some things which are tricky are:</p> <ul> <li>Can they have variable opacity? Well, yes and no.</li> <li>Can they have rounded corners? Maybe.</li> </ul> <p>Some things which aren't technical difficulties, but which are problems:</p> <ul> <li>Image file sizes: I have a student who wants to have a different large graphic header on every page of their site; that's not <em>technically</em> a problem, but it will mean a visitor has to wait for a new graphic to load every time they navigate</li> <li>Accessibility: "why not just make everything a graphic, to overcome the limitations of HTML?"</li> </ul> <p>Please help me fill out my list and add any hints or tips for people making this transition.</p>
<h3>web is not print</h3> <ul> <li>Layouts can be fluid.</li> <li>elements don't have to be absolutely positioned</li> <li>web pages need to be checked in several browsers for compatibility</li> <li>avoid divitis; from experience people coming from print into this field do everything by brute force instead of trying to think of elegant solutions for optimization and semantics purposes</li> <li>print is consumed visually - the web is consumed by people with visual impairments as well. Don't forget lynx users no matter how small the market share is :)</li> <li>semantics is important, learn about them</li> </ul> <p>thats all i can think of right now...</p>
How can I correctly close the application opened with using of Process? <p>I open the application using the Process class:</p> <pre><code>System.Diagnostics.Process vsProc = new System.Diagnostics.Process(); vsProc.StartInfo.FileName = "program.exe"; vsProc.Start(); </code></pre> <p>If I just kill it <code>vsProc.Kill()</code> the application ends uncorrectly. How can I close it correctly?</p>
<p>How to close a program 'correctly' depends 100% on the program you're dealing with. If you're the one writing the child program, you get to implement proper &amp; sane behavior. If not, your best <b>general</b> bet is finding the application's main window and send it a close request... rather than terminating the process.</p>
Disable context menu in Internet Explorer control <p>How do I disable the context menu in the IE <code>WebBrowser</code> control and instead perform custom handling of the right-click event in C#?</p>
<p>Actually:</p> <pre><code>WebBrowser browser; browser.IsWebBrowserContextMenuEnabled = false; </code></pre> <p>This pretty much tells the WebBrowser that the right-click context menu is not welcome.</p>
How can I change source folders en masse in Wise Installation Studio? <p>I've got an existing Wise .wsi script that I would like to convert to using relative paths, but the problem is that it includes about 330 files and the only way I've found to fix the paths are to go into each file's Details and adjust the path manually (from Installation Expert: Files screen, right click and select Details). Am I going to have to do this manual process 330 times or is there a way to change the .wsi script without using this crappy GUI?</p>
<p>The solution is to go to the Tools menu and select "Convert Source Paths". A dialog pops up that will allow you to convert paths to relative and specify that newly added files always use relative paths. The "Change All Paths to Relative" didn't work for me, but changing just folder paths at least took less time than editing every file's details.</p>
Is there any way to get readable gcc error and warning output at the command line? <p>For some long errors, the gcc output is dense and has lots of line-wrapping etc. Especially when errors are subtle, it can take me 10-30 seconds of squinting to parse it with my eyes.</p> <p>I've taken to pasting this in an open code-editor window to get some basic syntax highlighting and enable reformatting with regex's.</p> <p>Has anyone invented a more automated method?</p>
<p>I've found <a href="http://schlueters.de/colorgcc.html">colorgcc</a> to be invaluable. By introducing coloring, it becomes much easier to mentally parse the text of gcc error messages, especially when templates are involved.</p>
Windows Workflow Delay Activity serialization errors <p>I have a state machine workflow hosted in SharePoint with a delay activity in one state. When the timer fires the delay activity, I get a serialization error: "Engine RunWorkflow: System.Runtime.Serialization.SerializationException: Cannot get the member 'SendEmail_MethodInvoking'".</p> <p>The method this error references is not in the same state, and works fine when the workflow calls it normally. </p> <p>Any ideas?</p>
<p>Restart the “windows SharePoint timer service”. Root cause was, whenever you have workflow that has got a delay activity, the event is fired by the service(SPTimerV3), before it fires, it has to load the assembly from its bin or from the GAC, only one file(module loads) based on the assembly information specified in workflow.xml file loads.</p> <p>Deploying the new binary after changing the workflow activities, the SPTimerV3 is not aware of the newly added binary; it won’t reload it unless you do a time reset. Unless you do a reset, the persistence (serialization or de-serialization) or loading of assembly would fail due to mismatch of types.</p>
Why does "?b" mean 'b' in Ruby? <pre><code>"foo"[0] = ?b # "boo" </code></pre> <p>I was looking at the above example and trying to figure out:</p> <ol> <li>How "?b" implies the character 'b'?</li> <li><p>Why is it necessary? - Couldn't I just write this:</p> <p>"foo"[0] = 'b' # "boo"</p></li> </ol>
<blockquote> <p>Ed Swangren: ? returns the character code of a character.</p> </blockquote> <p>Not in Ruby 1.9. As of 1.9, <code>?a</code> returns 'a'. See here: <a href="http://dablog.rubypal.com/2009/1/16/son-of-10-things-to-be-aware-of-in-ruby-1-9" rel="nofollow">Son of 10 things to be aware of in Ruby 1.9!</a></p> <pre><code>telemachus ~ $ ~/bin/ruby -v ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux] telemachus ~ $ ~/bin/ruby -e 'char = ?a; puts char' a telemachus ~ $ /usr/bin/ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux] telemachus ~ $ /usr/bin/ruby -e 'char = ?a; puts char' 97 </code></pre> <p>Edit: A <em>very</em> full description of <a href="http://eigenclass.org/hiki/Changes%2Bin%2BRuby%2B1.9" rel="nofollow">changes in Ruby 1.9</a>.</p> <p>Another edit: note that you can now use <code>'a'.ord</code> if you want the string to number conversion you get in 1.8 via <code>?a</code>.</p>
Do Poor Code Samples Turn You Away From Libraries? <p>I've been evaluating a framework that on paper looks great. The problem is that the sample code is incomplete and of poor quality. The supplied reference implementations are for the most part not meant to be used (so they can be considered as sample code as well) and have only succeeded at confusing me.</p> <p>I know that it's common for things to look better on paper, but my experience with the sample code is turning me away from further investigation.</p> <p>Do you let poor code samples change your judgment of frameworks/libraries? So far my experience has been similar to the "resume effect": if someone doesn't put the effort into spell checking their resume, they probably won't get the job...</p>
<p>For me, it does. I tend to want to avoid libraries where the code samples are incomplete. If the library is open source, I will overlook it, since I can directly look at the code and see if the library's internals are reasonable, and I know that, if there is a problem someday, I could (if I had to) fix it.</p> <p>If the library is commercial, and their samples and/or documentation is poor, I look elsewhere. I just see it as risk management - poor samples make me fear the quality of the library in general.</p> <p>No matter how good something is on paper or in theory, it can still be crap when programmed.</p>
Controller/Routing Errors with js, img files using a CommonServiceLocator ControllerFactory <p>I've set up an ASP.NET MVC RC2 application to use a custom controller factory backed by a CommonServiceLocator (using StructureMap). Routing to and instantiating controllers works fine, but for some reason I'm getting exceptions when trying to access .js, .jpg, or any other static file.</p> <p>Here's the ControllerFactory code:</p> <pre><code>public class CommonServiceLocatorControllerFactory : DefaultControllerFactory { protected override IController GetControllerInstance(Type controllerType) { return (controllerType == null) ? base.GetControllerInstance(controllerType) : ServiceLocator.Current.GetInstance(controllerType) as IController; } } </code></pre> <p>And the exception is:</p> <p>The controller for path '/someimage.jpg' could not be found or it does not implement IController.</p> <p>How can I get the factory or routing engine to bypass the controller factory? </p> <p>Note: I'll be using IIS7/Integrated Mode, but the error occurs with the built in web server for VS2K8. </p>
<p>The problem was actually due to 404 errors- the path I was requesting for the static content didn't exist, and the base controller factory couldn't handle the request because there was nothing to deliver.</p>
Bind ASP.net object fails on test server, but not dev <p>I am getting the following error for an item in a GridView: **A call to Bind was not well formatted. Please refer to documentation for the correct parameters to Bind. ** </p> <pre><code>&lt;ItemTemplate&gt; &lt;asp:LinkButton ID="lnkColumn" runat="server" CausesValidation="False" CommandName="Select" Text='&lt;%# Bind("TableName.Column") %&gt;' /&gt; &lt;/ItemTemplate&gt; </code></pre> <p>I can't work out why it works fine on my dev server, but not on the test machine. It also works on the production box? We are running ASP.NET 3.5 for the website.</p>
<p>At the risk of being rude: Is it worth double checking your database schema, looking for a missing field? Is anything different between your environments? Try using winmerge to compare your environments (its great!)</p> <p>Another idea: comment out the 'bind' row, and replace it with these, to get a better idea what's going on:</p> <pre><code>&lt;%= Table.Field %&gt; &lt;%= Table.Field.GetType().ToString() %&gt; &lt;%= Table.GetType().ToString() %&gt; </code></pre>
crystal report 9 <p>new page break is not working when exporting from Crystal report 9 using visual studio studio.net. I have set the below options in crystal report 9 design </p> <p>paper size is a3 and orientation is landscape. I have created 2 report groups (date and org unit) I want a page break after every new date and after every new org unit. I have already set the new page after in group footer1 and group footer 2.</p> <p>when i export to excel it doesn't break the page after each group is changed. Can anybody help me to resolve this issue.</p> <p>thanks bby</p>
<p>I said this in another <a href="http://stackoverflow.com/questions/570434/reportviewer-export-to-excel-adds-decimal-to-percentage-values-how-can-i-overrid/570507#570507">question</a> regarding exporting to Excel:</p> <blockquote> <p>If this was made with CR, I've found that if a report is going to consistently be exported to Excel, it's best to remove ALL formatting that CR has/does. Otherwise you'll get weird anomalies like what you're experiencing and will save you a lot of grief down the road.</p> <p>What I've done for some of my users is create one report with no formatting, specifically for exporting, and one report with all the bells and whistles of CR.</p> </blockquote>
Capturing all the data that has changed during a Linux install <p>I am trying to figure out which files were changed when I run an app install via make install. I can look at the script, but that calls other scripts and may or may not touch other files, etc. How can I do this programmatically?</p>
<p>Implementation: <a href="http://asic-linux.com.mx/~izto/checkinstall/" rel="nofollow">http://asic-linux.com.mx/~izto/checkinstall/</a></p> <p>Several ways come to mind. First, use some sort of LD_PRELOAD to track all files opened. Second approach, compare filesystem before and after.</p>
How to install VeriSign's Intermediate CA Certificates? <p>I'm running tomcat on Solaris server and I would like to know how can install VeriSign's Intermediate CA certificates?</p> <p>I have been struggling for days and keep having <em>keytool error: java.io.EOFException</em> How do I solve it?</p>
<p>You could try <a href="http://portecle.sourceforge.net" rel="nofollow">Portecle</a>. It's a graphical user interface to the java certificate management api. Also you should make sure that the certificate does not contain unneccessary whitespaces.</p>
Not able to run SSIS PACKAGE by DOS commands <p>I want to run a SSIS package in command prompt... for that i used the command dtexec/f "C:/Filename.dtsx"...but when i executethis command i am getting an error like "Product level is insufficient for the component "Data Conversion"...</p> <p>but when i run the SSIS package in BIDS,it executed successfully... why is that?? is it because of any installation problem?? Please help me this</p>
<p>See this post. <a href="http://blogs.msdn.com/michen/archive/2006/11/11/ssis-product-level-is-insufficient.aspx" rel="nofollow">ssis-product-level-is-insufficient</a></p>
Where can i get free GSM libraries/components for delphi or python? <p>Where can i get good free GSM libraries for <strong>Delphi</strong> or <strong>Python</strong>? Libraries i can use to send and receive sms's on my application?</p> <p>Gath</p>
<p>For free and open source <a href="http://sourceforge.net/projects/tpapro/" rel="nofollow">AsyncPro</a>></p> <p>Not free but the components has active development <a href="http://www.deepsoftware.com/nrcomm" rel="nofollow">nrComm Lib</a></p> <p>Another solution to use SMS gateway, such as <a href="http://www.clickatell.com/" rel="nofollow">ClickAtell</a>, with solution you can send sms using a simple post command to the gateway url or webservices.</p>
What permissions are needed to deploy a report project in VS2005? <p>When I try to deploy reports to a newly installed SSRS 2005 server (remote server) I get the following error in VS2005:</p> <p>The permissions granted to user 'CEINTERNAL\IUSR_COMPELLENT01' are insufficient for performing this operation. </p> <p><b>What permissions are needed to deploy a report project in VS2005? </b></p>
<p>Assign either the Admin or Publisher role to CEINTERNAL\IUSR_COMPELLENT01 to the root folder in the Report Manager hierarchy.</p> <p>Hope this helps,</p> <p>Bill</p>
Fastest way(s) to move the cursor on a terminal command line? <p>What is the best way to move around on a given very long command line in the terminal?</p> <p>Say I used the arrow key or <kbd>Ctrl</kbd>-<kbd>R</kbd> to get this long command line:</p> <pre><code>./cmd --option1 --option2 --option3 --option4 --option5 --option6 --option7 --option8 --option9 --option10 --option11 --option12 --option13 --option14 --option15 --option16 --option17 --option18 --option19 --option20 --option21 --option22 --option23 --option24 --option25 --option26 --option27 --option28 --option29 --option30 --option31 --option32 --option33 --option34 --option35 --option36 --option37 --option38 --option39 --option40 --option41 --option42 --option43 --option44 --option45 --option46 --option47 --option48 --option49 --option50 </code></pre> <p>Now I need to move (starting from the beginning or the end of the line) the cursor to <code>--option25</code> to modify something there. </p> <p>What is the fastest way to get there? What I usually do is <kbd>Ctrl</kbd>-<kbd>A</kbd> to get to the beginning and then repeatedly <kbd>Alt</kbd>-<kbd>F</kbd> to move forward, word by word (or <kbd>Ctrl</kbd>-<kbd>E</kbd> to go the end and <kbd>Alt</kbd>-<kbd>B</kbd> to then go backward). But on a long line that takes too much time. There must be a way to search and jump directly to the part I need to modify, e.g. <code>option25</code>?</p>
<p>To be clear, you don't want a "fast way to move the cursor on a <strong>terminal</strong> command line". What you actually want is a fast way to navigate over command line in you <strong>shell</strong> program.</p> <p><a href="http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29">Bash</a> is very common shell, for example. It uses <a href="http://en.wikipedia.org/wiki/GNU_readline">Readline</a> library to implement command line input. And so to say, it is very convenient to know Readline bindings since it is used not only in bash. For example, gdb also uses Readline to process input.</p> <p>In Readline documentation you can find all navigation related bindings (and more): <a href="http://www.gnu.org/software/bash/manual/bash.html#Readline-Interaction">http://www.gnu.org/software/bash/manual/bash.html#Readline-Interaction</a></p> <p>Short copy-paste if the link above goes down:</p> <p>Bare Essentials</p> <ul> <li>C-b Move back one character.</li> <li>C-f Move forward one character.</li> <li>[DEL] or [Backspace] Delete the character to the left of the cursor.</li> <li>C-d Delete the character underneath the cursor.</li> <li>C-_ or C-x C-u Undo the last editing command. You can undo all the way back to an empty line.</li> </ul> <p>Movement</p> <ul> <li>C-a Move to the start of the line.</li> <li>C-e Move to the end of the line.</li> <li>M-f Move forward a word, where a word is composed of letters and digits.</li> <li>M-b Move backward a word.</li> <li>C-l Clear the screen, reprinting the current line at the top.</li> </ul> <p>Kill and yank</p> <ul> <li>C-k Kill the text from the current cursor position to the end of the line. </li> <li>M-d Kill from the cursor to the end of the current word, or, if between words, to the end of the next word. Word boundaries are the same as those used by M-f. </li> <li>M-[DEL] Kill from the cursor the start of the current word, or, if between words, to the start of the previous word. Word boundaries are the same as those used by M-b. </li> <li>C-w Kill from the cursor to the previous whitespace. This is different than M- because the word boundaries differ.</li> <li>C-y Yank the most recently killed text back into the buffer at the cursor. </li> <li>M-y Rotate the kill-ring, and yank the new top. You can only do this if the prior command is C-y or M-y.</li> </ul> <p>M is Meta key. For Max OS X Terminal you can enable "Use option as meta key" in Settings/Keyboard for that. For Linux its more complicated.</p> <p><strong>Update</strong></p> <p>Also note, that Readline can operate in two modes:</p> <ul> <li>emacs mode (which is the default)</li> <li><a href="http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC22"><strong>vi</strong> mode</a></li> </ul> <p>To switch Bash to use vi mode:</p> <pre><code>$ set -o vi </code></pre> <p>Personaly I prefer vi mode since I use vim for text editing.</p>
Query Unmapped Columns in NHibernate <p>I have a class that is mapped to a table using NHibernate. The problem is that only some of the properties are mapped to columns in the table. This is fine because the only columns we use for display are mapped, however I was wondering if there is any way to query against other columns in the table that aren't mapped to properties in my class.</p> <p>For example we have a table with the following columns:</p> <pre><code>Customer ----------- CustomerId Name DateCreated </code></pre> <p>and we have an object</p> <pre><code>public class Customer { public virtual int CustomerId {get;set;} public virtual string name {get;set;} } </code></pre> <p>and <code>name</code> and <code>customerId</code> are mapped however <code>DateCreated</code> is not because we never display it anywhere. We would like to query the <code>Customer</code> table for customers that were created by a certain date. Is there any way to do this <strong>without</strong> mapping the <code>DateCreated</code>? Also it would be preferable to do this using the criteria API.</p>
<p>Ayende Rahien posted an article which describes specifying <code>access="noop"</code> in the mapping to specify query-only properties. See <a href="http://ayende.com/Blog/archive/2009/06/10/nhibernate-ndash-query-only-properties.aspx">NHibernate – query only properties</a>. I have not tried this myself.</p>
Which is the "best" data access framework/approach for C# and .NET? <p>(EDIT: I made it a community wiki as it is more suited to a collaborative format.)</p> <p>There are a plethora of ways to access SQL Server and other databases from .NET. All have their pros and cons and it will never be a simple question of which is "best" - the answer will always be "it depends".</p> <p>However, I am looking for <strong>a comparison at a high level of the different approaches and frameworks in the context of different levels of systems</strong>. For example, I would imagine that for a quick-and-dirty Web 2.0 application the answer would be very different from an in-house Enterprise-level CRUD application.</p> <p>I am aware that there are numerous questions on Stack Overflow dealing with subsets of this question, but I think it would be useful to try to build a summary comparison. I will endeavour to update the question with corrections and clarifications as we go.</p> <p>So far, this is my understanding at a high level - but I am sure it is wrong... I am primarily focusing on the Microsoft approaches to keep this focused.</p> <h2><a href="http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework">ADO.NET Entity Framework</a></h2> <ul> <li>Database agnostic</li> <li>Good because it allows swapping backends in and out</li> <li>Bad because it can hit performance and database vendors are not too happy about it</li> <li>Seems to be MS's preferred route for the future</li> <li>Complicated to learn (though, see <a href="http://stackoverflow.com/questions/267357/how-is-the-net-entity-framework-overkill-versus-linqtosql">267357</a>)</li> <li>It is accessed through <a href="http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework#LINQ_to_Entities">LINQ to Entities</a> so provides ORM, thus allowing abstraction in your code</li> </ul> <h2><a href="http://en.wikipedia.org/wiki/Language_Integrated_Query#LINQ_to_SQL">LINQ to SQL</a></h2> <ul> <li>Uncertain future (see <a href="http://www.infoq.com/news/2008/11/DLINQ-Future">Is LINQ to SQL truly dead?</a>)</li> <li>Easy to learn (?)</li> <li>Only works with MS SQL Server</li> <li>See also <a href="http://stackoverflow.com/questions/271384/pros-and-cons-of-linq-language-integrated-query">Pros and cons of LINQ</a></li> </ul> <h2>"Standard" ADO.NET</h2> <ul> <li>No ORM</li> <li>No abstraction so you are back to "roll your own" and play with dynamically generated SQL</li> <li>Direct access, allows potentially better performance</li> <li>This ties in to the age-old debate of whether to focus on objects or relational data, to which the answer of course is "it depends on where the bulk of the work is" and since that is an unanswerable question hopefully we don't have to go in to that too much. IMHO, if your application is primarily manipulating large amounts of data, it does not make sense to abstract it too much into objects in the front-end code, you are better off using stored procedures and dynamic SQL to do as much of the work as possible on the back-end. Whereas, if you primarily have user interaction which causes database interaction at the level of tens or hundreds of rows then ORM makes complete sense. So, I guess my argument for good old-fashioned ADO.NET would be in the case where you manipulate and modify large datasets, in which case you will benefit from the direct access to the backend.</li> <li>Another case, of course, is where you have to access a legacy database that is already guarded by stored procedures.</li> </ul> <h2>ASP.NET Data Source Controls</h2> <p>Are these something altogether different or just a layer over standard ADO.NET? - Would you really use these if you had a DAL or if you implemented LINQ or Entities?</p> <h2>NHibernate</h2> <ul> <li>Seems to be a very powerful and powerful ORM?</li> <li>Open source</li> </ul> <p>Some other relevant links; <a href="http://stackoverflow.com/questions/53417/nhibernate-or-linq-to-sql">NHibernate or LINQ to SQL</a> <a href="http://stackoverflow.com/questions/8676/entity-framework-vs-linq-to-sql">Entity Framework vs LINQ to SQL</a></p>
<p>I think LINQ to SQL is good for projects targeted for SQL Server. </p> <p>ADO.NET Entity Framework is better if we are targeting different databases. Currently I think a lot of providers are available for ADO.NET Entity Framework, Provider for PostgreSQL, MySQL, esql, Oracle and many other (check <a href="http://blogs.msdn.com/adonet/default.aspx" rel="nofollow">http://blogs.msdn.com/adonet/default.aspx</a>).</p> <p>I don't want to use standard ADO.NET anymore because it's a waste of time. I always go for ORM.</p>
Watin - how to test site with popup pages <p>I'm using WatiN (Web Application Testing in .Net) to do integration testing on a Dynamics CRM 4.0 website. CRM uses a lot of popup windows - eg clicking on a Contact in a list opens a new browser window with the Contact's details.</p> <p>I want to test:</p> <ul> <li>login to CRM (done)</li> <li>go to the Contact list (done)</li> <li>click on an Contact, thus trigger the popup (done)</li> <li>test functionality within the Contact entity/form (can't do)</li> </ul> <p>So I need to get hold of the popped up window. How?</p> <p>Thanks.</p>
<pre><code>//after the click that opens the popup: IE iepopup_1 = IE.AttachToIE(Find.ByUrl(theUrlOfThePopup)); //operate on iepopup_1 </code></pre>
Experiences with Javascript History Frameworks <p>I'm seeking a javascript history framework to handle navigation inside a page when the user selects multiple options which change the page behaviour.</p> <p>There are multiple artefacts on the page that change the data loading of the page and I'd like to store this as a stacked set of behaviour. In a wider sense, I'd like to add this as a toolkit to my future web projects for the same reasons.</p> <p>I'm primarily writing in ASP.NET with JQuery but I'm only really worried about JQuery for now. I do write other projects in PHP, Python and Perl (depending on the gig) so it would have to be platform agnostic.</p> <p>I've been looking on the net and have found a few but only one (covered on OReilly) looked like it would fit the bill. I have started playing with it but I wanted to know what toolkits other people were using and what others would recommend.</p> <p>So if you have any experience of history frameworks, handling the back button (etc) in Ajax I'd love to hear about what you've used and how it worked out. It would really help me make a final choice on library.</p> <p>Thanks,</p> <p>S</p>
<p>I had the similar problem a while ago building a flash only site. We tried:</p> <ul> <li><a href="http://code.google.com/p/reallysimplehistory/" rel="nofollow">Really Simple History</a> (which had some problems in combination of safari and flash)</li> <li><a href="http://extjs.com" rel="nofollow">ExtJS</a> which has a <a href="http://extjs.com/deploy/dev/docs/?class=Ext.History" rel="nofollow">history component</a> which worked great for us. (<a href="http://extjs.com/deploy/dev/examples/history/history.html" rel="nofollow">Demo</a>) [Beside we have used this framework already for other projects.]</li> </ul>
Cumulative Plot with Given X-Axis <p>I have data that looks like this. In which I want to plot accumulative value of dat1 with respect to x-axis. Also plot it together with dat2.</p> <pre><code>#x-axis dat1 dat2 -10 0.0140149 0.0140146 -9 0.00890835 0.00891768 -8 0.00672276 0.00672488 -7 0.00876399 0.00879401 -6 0.00806879 0.00808141 -5 0.0088366 0.00885121 -4 0.00856872 0.00857769 -3 0.0195384 0.0196094 -2 0.0160239 0.0161829 -1 0.0254455 0.0257845 0 0.0397413 0.0400913 1 0.0743316 0.0755453 2 0.0247501 0.0253324 3 0.0214285 0.021778 4 0.0241462 0.0244967 5 0.0150943 0.015241 6 0.0141398 0.0142373 7 0.0101515 0.0102948 8 0.0308843 0.031294 9 0.0095504 0.00960626 10 0.00729676 0.0073713 </code></pre> <p>What's the common way to do it in R?</p> <p>I looked at ECDF from Hmisc, it doesn't seem to do what I want. In particular it doesn't allow us to give x-axis value.</p>
<p>I think the function you are looking for is <code>cumsum()</code> which will do a cumulative sum on a vector. </p> <pre><code>#put your data into 3 vectors x&lt;-c(-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10) dat1&lt;-c(0.0140149,0.00890835,0.00672276,0.00876399,0.00806879,0.0088366,0.00856872,0.0195384,0.0160239,0.0254455,0.0397413,0.0743316,0.0247501,0.0214285,0.0241462,0.0150943,0.0141398,0.0101515,0.0308843,0.0095504,0.00729676) dat2&lt;-c(0.014015,0.008918,0.006725,0.008794,0.008081,0.008851,0.008578,0.019609,0.016183,0.025785,0.040091,0.075545,0.025332,0.021778,0.024497,0.015241,0.014237,0.010295,0.031294,0.009606,0.007371) #create a new vector called cdat1 to hold the cumulative sum cdat1&lt;-cumsum(dat1) plot(x,cdat1) points(x,dat2,col="red") </code></pre> <p>I use the function points above in order to add dat2 to the existing plot. Run this in R and see if it gives you what you need. </p>
Breakpoints cannot be set and have been disabled <p>If I add a breakpoint in a VC++ 6.0 project and then I start debugging, it displays this error message:</p> <blockquote> <p>One or more breakpoints cannot be set and have been disabled , Execution will stop at the beginning of the program</p> </blockquote> <p>and it shows the disassembly window. What kind of problem is this?</p> <p>How can I add a breakpoint and start the debugging?</p>
<p>Check :</p> <ol> <li><a href="http://www.tek-tips.com/viewthread.cfm?qid=326950" rel="nofollow">http://www.tek-tips.com/viewthread.cfm?qid=326950</a>]</li> <li><a href="http://www.codeguru.com/forum/archive/index.php/t-118951.html" rel="nofollow">http://www.codeguru.com/forum/archive/index.php/t-118951.html</a></li> </ol> <p>Plus:</p> <p>KB957912 - Update for Visual Studio 2008 SP1 Debugging and Breakpoints <a href="http://code.msdn.microsoft.com/KB957912/Release/ProjectReleases.aspx?ReleaseId=1796" rel="nofollow">http://code.msdn.microsoft.com/KB957912/Release/ProjectReleases.aspx?ReleaseId=1796</a></p>
Java WebServiceException: Undefined port type with JBoss <p>I am new to Web Services with JBoss. A client is connecting to an EJB3 based Web Service With JBoss AS 5 and JDK 6 using JAX-WS. I am stuck with the following exception:</p> <pre><code>Exception in thread "main" javax.xml.ws.WebServiceException: Undefined port type: {http://webservice.samples/}HelloRemote at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:300) at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:306) at javax.xml.ws.Service.getPort(Service.java:161) at samples.client.BeanWSClient.getPort(BeanWSClient.java:44) at samples.client.BeanWSClient.main(BeanWSClient.java:35) </code></pre> <p>BeanWSClient.java (client is a different project than EJB3 WS):</p> <pre><code>package samples.client; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; import samples.webservice.HelloRemote; public class BeanWSClient { /** * @param args */ public static void main(String[] args) throws Exception { String endpointURI ="http://192.168.22.100:8080/SampleWSEJBProject/HelloWorld?wsdl"; String helloWorld = "Hello world!"; Object retObj = getPort(endpointURI).echo(helloWorld); System.out.println(retObj); } private static HelloRemote getPort(String endpointURI) throws MalformedURLException { QName serviceName = new QName("http://www.openuri.org/2004/04/HelloWorld", "HelloWorldService"); URL wsdlURL = new URL(endpointURI); Service service = Service.create(wsdlURL, serviceName); return service.getPort(HelloRemote.class); } </code></pre> <p>HelloRemote.java:</p> <pre><code>package samples.webservice; import javax.jws.WebService; @WebService //@SOAPBinding(style=SOAPBinding.Style.RPC) public interface HelloRemote { public String echo(String input); } </code></pre> <p>HelloWorld.java:</p> <pre><code>package samples.webservice; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; /** * Session Bean implementation class MyBean */ @WebService(name = "EndpointInterface", targetNamespace = "http://www.openuri.org/2004/04/HelloWorld", serviceName = "HelloWorldService") @SOAPBinding(style = SOAPBinding.Style.RPC) @Remote(HelloRemote.class) @Stateless public class HelloWorld implements HelloRemote { /** * @see Object#Object() */ @WebMethod public String echo(String input) { return input; } } </code></pre>
<p>add endpointInterface in @WebSevice annotation, if you dont mention endpoint interface give fully qualified portname while using getPort method.</p>
How do I correctly create a Zend Feed? <p>I have successfully created a simple RSS feed, but entries keep coming back as unread and updated, and entries deleted from the client reappear everytime I ask mail to update the feed. </p> <p>What am I doing wrong?</p> <p>I use this simple function to create an rss feed:</p> <pre><code>public static function getFeed($db) { $title = 'Latest feeds'; $feedUri = '/rss/'; //link from which feed is available $link = 'http://' . $_SERVER['HTTP_HOST'] . $feedUri; //create array according to structure defined in Zend_Feed documentation $feedArr = array('title' =&gt; $title, 'link' =&gt; $link, 'description' =&gt; $title, 'language' =&gt; 'en-us', 'charset' =&gt; 'utf-8', //'published' =&gt; 1237281011, 'generator' =&gt; 'Zend Framework Zend_Feed', 'entries' =&gt; array() ); $itemObjs = array(); $select = $db-&gt;select('id')-&gt;from('things') -&gt;order('createddate desc') -&gt;limit(10); $results = $db-&gt;fetchAll($select-&gt;__toString()); $count = count($results); for($i=0;$i&lt;$count;$i++) { $itemObjs[] = SiteUtil::getItemObjectInstance($db, $results[$i]['id']); } $count = count($itemObjs); for($i=0;$i&lt;$count;$i++) { $obj = &amp; $itemObjs[$i]; $feedArr['entries'][] = array('title' =&gt; $obj-&gt;getSummary(), 'link' =&gt; 'http://' . $_SERVER['HTTP_HOST'] . $obj-&gt;getDetailUri(), 'description' =&gt; $obj-&gt;description, 'publishdate' =&gt; $obj-&gt;publishedDate, 'guid' =&gt; 'http://' . $_SERVER['HTTP_HOST'] . $obj-&gt;getDetailUri() ); } $feed = Zend_Feed::importArray($feedArr, 'rss'); return $feed; } </code></pre> <p>The action in the controller class is:</p> <pre><code>public function rssAction() { $feed = FeedUtil::getFeed($this-&gt;db); $feed-&gt;send(); } </code></pre> <p>So to access the feed, I point the client to: <a href="http://mysite.com/rss" rel="nofollow">http://mysite.com/rss</a></p> <p>I am using mac mail's rss client to test. The feed downloads just fine, showing all 5 items I have in the database for testing purposes. The problems are as follows:</p> <p>1) If I mark one or more items as 'read' and then tell mail to update the feed, it pulls all items again as if I never downloaded them in the first place. </p> <p>2) If I delete one or more items they come back again, unread, again as if it were the first time I subscribed to the feed.</p> <p>3) Feeds are <em>always</em> marked as updated. Is that supposed to be the case?</p> <p>Is is something to do with the parameters I'm setting, am I omitting something, or could the solution be something more subtle like setting HTTP content headers (e.g. '304 Not Modified')?</p> <p>My understanding of rss is that once an item has been marked as read or deleted from the client, it should never come back, which is the behaviour I'm after.</p> <p>Just to note, the 'link' and 'guid' parameters are always unique, and I have tried experimenting with 'published' and 'publishdate' (both optional) attributes only get the same result. The above code is a simplified version of what I have, showing only the relevant bits, and finally, yes, I have read the <a href="http://cyber.law.harvard.edu/rss/rss.html" rel="nofollow">rss specification</a>.</p> <p>Thanks in advance for any help offered here, I'll be happy to clarify any point.</p>
<p>According to the Zend Framework Doc, you must use the <strong>lastUpdate</strong> parameter to set the last modification date of an entry.</p> <pre><code> 'entries' =&gt; array( array( [...] 'lastUpdate' =&gt; 'timestamp of the publication date', // optional [...] </code></pre> <p>So <em>published</em> for the feed, and <em>lastUpdate</em> for the entries.</p>
Web services that take and return XML documents - why? <p>Are there benefits of writing a web service interface whose methods all take and return XML documents, rather than the more usual parameter lists of native types and classes?</p> <p>We have some existing web services that are designed like this. The XML documents that are passed to their methods are typically large (as in they contain maybe 100 pieces of data that are relevant to the method calls). We have XSD files that we use to validate the XML documents, but the overall client developer experience is poor and slow. Surely it would be preferable to have a strongly-typed interface?</p> <p>The web services are written in C#, and the clients are written in C# and also Java (some of our business partners use Java).</p>
<p>If you absolutely know for sure what your end-user/client technology is (for example pure .NET and Java where the feature set is probably the richest) then by all means go ahead and take advantage of strongly typed interfaces where available. But if your client base is a mixed bag of Perl, PHP, ASP, Python etc, then I'd keep life simple and accessible for these folks.</p> <p>We have a number of web services that have to be consumable by this sort of mixed bag of clients, and whilst I'd love to make life simple for us, we have to dumb down a bit purely to ensure maximum interoperability.</p>
CMake : how to use bash command in CMakeLists.txt <p>I'm wondering how I can use bash command in CMakeLists.txt. What I want is to get the number of processor retrieved using :</p> <pre><code>export variable=`getconf _NPROCESSORS_ONLN` </code></pre> <p>and set NB_PROCESSOR to variable using something like : </p> <pre><code>SET (NB_PROCESSOR variable) </code></pre> <p>So my question is how can I use the getconf command in CMakeLists.txt and how can I use the result (stored in variable) in CMake SET command?</p>
<p>This seems to do the trick, and saves the "set" too.</p> <pre><code>execute_process(COMMAND getconf _NPROCESSORS_ONLN OUTPUT_VARIABLE NB_PROCESSOR) </code></pre>
How to compute precision and recall in clustering? <p>I am really confused how to compute precision and recall in clustering applications.</p> <p>I have the following situation:</p> <p>Given two sets A and B. By using a unique key for each element I can determine which of the elements of A and B match. I want to cluster those elements based on features (not using the unique key of course).</p> <p>I am doing the clustering but I am not sure how to compute precision and recall. The formulas,according to the paper "Extended Performance Graphs for Cluster Retrieval" (<a href="http://staff.science.uva.nl/~nicu/publications/CVPR01_nies.pdf">http://staff.science.uva.nl/~nicu/publications/CVPR01_nies.pdf</a>) are:</p> <p>p = precision = relevant retrieved items/retrieved items and r = recall = relevant retrieved items/relevant items</p> <p>I really do not get what elements fall under which category.</p> <p>What I did so far is, I checked within the clusters how many matching pairs I have (using the unique key). Is that already one of precision or recall? And if so, which one is it and how can I compute the other one?</p> <p>Update: I just found another paper with the title "An F-Measure for Evaluation of Unsupervised Clustering with Non-Determined Number of Clusters" at <a href="http://mtg.upf.edu/files/publications/unsuperf.pdf">http://mtg.upf.edu/files/publications/unsuperf.pdf</a>.</p>
<p>I think you'll find wikipedia has a helpful <a href="http://en.wikipedia.org/wiki/Precision%5Fand%5Frecall">article on precision and recall</a>. In short:</p> <p>Precision = true positives / (true positives + false positives)</p> <p>Recall = true positives /( true positivies + false negatives)</p>
Should lookup tables be static <p>I have a Message class which parses text messages using lookup tables. I receive a lot of messages and create and destroy a lot of objects so I thought I declare those lookup tables as static members to prevent initializing the same tables with the same values again and again.</p> <p>Is it the correct approach or there's more appropriate C++ way?</p> <p>Thanks.</p>
<p>If your message classes share lookup information that it may be worth abstracting your static lookups into a class of their own so that they really are only initialised once. </p> <p>But regardless, static class members are definitely the way to go.</p>
Ant Flex problem <p>My Cairngorm program does some preliminary authentication against a RemoteObject before allowing Cairngorm's ServiceLocator to start using the same RemoteObject to get business data. Everything works fine with Flex Builder, but I need an Ant build. The Ant mxmlc task compiles everything ok, but at runtime the resulting code fails at the getService() method on Cairngorm's RemoteObjects class, because it can't find the service.</p> <p>Might this perhaps be due to the Cairngorm code being differently linked in the Ant-driven compilation? In the file resulting from -dump-config (and this file is fine, used with mxmlc on the command line) the only reference to the Cairngorm swc is in this element:</p> <pre> &lt;library-path> &lt;path-element>\path\to\directory\containing\Cairngorm.swc&lt;/path-element> &lt;/library-path> </pre> <p>The corresponding element in my build.xml is </p> <pre> &lt;compiler.library-path dir="${basedir}" append="true"> &lt;include name="libs"/> &lt;/compiler.library-path> </pre> <p>I can't see anything that would affect how Cairngorm is linked, apart from an explicit setting of static-link-runtime-shared-libraries to true in both the FB output and in my build.xml. Perhaps my linking theory is all wrong? But what else could be making Cairngorm's remote access fail when access from elsewhere in the same SWF to the same RemoteObject has been ok?</p>
<p>It sounds like the ANT build might be missing the <em>-services</em> flag to compile in the <em>services-config.xml</em> file that configures the RemoteObject endpoints.</p> <p>In FlexBuilder, look at the project properties and navigate to the Flex Compiler pane. You should see an "Additional Compiler Arguments" field. Make sure that these same additional arguments are passed to the ANT compile task. You're looking for something like "-services services-config.xml"</p>
Output buffering in PHP? <p>I seem to be confused about PHP output buffering. I have code like this:</p> <pre><code>function return_json($obj) { ob_get_clean(); ob_start(); header("Content-Type: application/json"); echo json_encode($obj); exit; } </code></pre> <p>But it doesn't seem to like the ob_get_clean(). I do that because some HTML might accidentally get generated before it gets to that point but I thought this was how you were meant to do it.</p> <p>What am I missing?</p>
<p>To use ob_get_clean (), you have to be sure, that at some point you have ob_start ()'ed earlier. Otherwise, there’s no buffer to clean, everything is already flushed to the user agent.</p>
Perl, LibXML and Schemas <p>I have an example Perl script which I am trying to load and validate a file against a schema, them interrogate various nodes. </p> <pre><code>#!/usr/bin/env perl use strict; use warnings; use XML::LibXML; my $filename = 'source.xml'; my $xml_schema = XML::LibXML::Schema-&gt;new(location=&gt;'library.xsd'); my $parser = XML::LibXML-&gt;new (); my $doc = $parser-&gt;parse_file ($filename); eval { $xml_schema-&gt;validate ($doc); }; if ($@) { print "File failed validation: $@" if $@; } eval { print "Here\n"; foreach my $book ($doc-&gt;findnodes('/library/book')) { my $title = $book-&gt;findnodes('./title'); print $title-&gt;to_literal(), "\n"; } }; if ($@) { print "Problem parsing data : $@\n"; } </code></pre> <p>Unfortunately, although it is validating the XML file fine, it is not finding any $book items and therefore not printing out anything. </p> <p>If I remove the schema from the XML file and the validation from the PL file then it works fine.</p> <p>I am using the default namespace. If I change it to not use the default namespace (xmlns:lib="http://libs.domain.com" and prefix all items in the XML file with lib and change the XPath expressions to include the namespace prefix (/lib:library/lib:book) then it again works file.</p> <p>Why? and what am I missing?</p> <p>XML:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;library xmlns="http://lib.domain.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://lib.domain.com .\library.xsd"&gt; &lt;book&gt; &lt;title&gt;Perl Best Practices&lt;/title&gt; &lt;author&gt;Damian Conway&lt;/author&gt; &lt;isbn&gt;0596001738&lt;/isbn&gt; &lt;pages&gt;542&lt;/pages&gt; &lt;image src="http://www.oreilly.com/catalog/covers/perlbp.s.gif" width="145" height="190"/&gt; &lt;/book&gt; &lt;book&gt; &lt;title&gt;Perl Cookbook, Second Edition&lt;/title&gt; &lt;author&gt;Tom Christiansen&lt;/author&gt; &lt;author&gt;Nathan Torkington&lt;/author&gt; &lt;isbn&gt;0596003137&lt;/isbn&gt; &lt;pages&gt;964&lt;/pages&gt; &lt;image src="http://www.oreilly.com/catalog/covers/perlckbk2.s.gif" width="145" height="190"/&gt; &lt;/book&gt; &lt;book&gt; &lt;title&gt;Guitar for Dummies&lt;/title&gt; &lt;author&gt;Mark Phillips&lt;/author&gt; &lt;author&gt;John Chappell&lt;/author&gt; &lt;isbn&gt;076455106X&lt;/isbn&gt; &lt;pages&gt;392&lt;/pages&gt; &lt;image src="http://media.wiley.com/product_data/coverImage/6X/07645510/076455106X.jpg" width="100" height="125"/&gt; &lt;/book&gt; &lt;/library&gt; </code></pre> <p>XSD:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xs:schema xmlns="http://lib.domain.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://lib.domain.com"&gt; &lt;xs:attributeGroup name="imagegroup"&gt; &lt;xs:attribute name="src" type="xs:string"/&gt; &lt;xs:attribute name="width" type="xs:integer"/&gt; &lt;xs:attribute name="height" type="xs:integer"/&gt; &lt;/xs:attributeGroup&gt; &lt;xs:element name="library"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element maxOccurs="unbounded" name="book"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="title" type="xs:string"/&gt; &lt;xs:element maxOccurs="unbounded" name="author" type="xs:string"/&gt; &lt;xs:element name="isbn" type="xs:string"/&gt; &lt;xs:element name="pages" type="xs:integer"/&gt; &lt;xs:element name="image"&gt; &lt;xs:complexType&gt; &lt;xs:attributeGroup ref="imagegroup"/&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre>
<p>From the <a href="http://search.cpan.org/perldoc?XML::LibXML::Node" rel="nofollow">XML::LibXML docs</a>:</p> <blockquote> <p>A common mistake about XPath is to assume that node tests consisting of an element name with no prefix match elements in the default namespace. This assumption is wrong - by XPath specification, such node tests can only match elements that are in no (i.e. null) namespace. ...(and later)... ...The recommended way is to use the <a href="http://search.cpan.org/perldoc?XML::LibXML::XPathContext" rel="nofollow">XML::LibXML::XPathContext</a> module</p> </blockquote> <p>So, from the perspective of XPath, there is no "default" namespace...for any non-null namespace, you have to specify it in your XPath. The XML::LibXML::XPathContext module lets you create a prefix for any namespace to use in your XPath expression.</p>