Tuesday, March 1, 2011

C# XElement: Node Formatting with HTML

I'm extracting XML node from an XElement. When I use XElement.Value it strips any HTML that may be in the node.

I know that if I do XElement.ToString() I can keep the HTML, but it also gives me the node tags. Is there any way to extract the content of a Node as is without the HTML being stripped out?


From stackoverflow
  • You need to concatenate the nodes inside the XElement, like this:

    node.Nodes().Aggregate(new StringBuilder(), (sb, n) => sb.Append(n.ToString())).ToString()

    Or, in .Net 4.0:

    Arnej65 : This worked perfectly. Makes total sense, when you see it. Cheers
  • Alternatively:

    using System.Xml.XPath;
    string xml = node.CreateNavigator().InnerXml;

Rails create_table query

Hi, I am a beginner in Rails. In the following code,there is an id which is set as false. What's the meaning of it?

class CreateCoursesStudents < ActiveRecord::Migration 
  def self.up
    create_table :courses_students, **:id => false** do |t| 
      t.integer :course_id,:null => false 
      t.integer :student_id, :null => false
    # Add index to speed up looking up the connection, and ensure # we only  
    enrol a student into each course once 
    add_index :courses_students, [:course_id, :student_id], :unique => true

  def self.down
    remove_index :courses_students, :column => [:course_id, :student_id]
    drop_table :courses_students 


From stackoverflow
  • :null=>false indicates that the field in question cannot be null for any row that gets created in the the courses_students table.

    Felix : Thanks :) and what about the id => false statement in the create_table line?
  • :id => false defines a table with no primary key, which is useful e.g. when you create a join table for a many-to-many relationship.

iPad modal view controller similar to Mail.app?

How can I create a modal window in my iPad app similar to the one shown on Apple's website for composing messages in Mail.app?



From stackoverflow
  • Just use a normal view controller, assign the modalPresentationStyle property, and present it as a modal view controller. Please read the "iPad Programming Guide" / "Views and View Controllers" for detail.

    norskben : http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/UserInterface/UserInterface.html
    Dimitris : The `modalPresentationStyle` you are looking for by the way igul222, is `UIModalPresentationFormSheet`.

Reading multiple files with PHPExcel

Hello there.

I just recently started using this library (the one from CodePlex), but I ran into some issues. My goal is to use it so I can process some data from multiple Excel files, and send such data to a database, per file. I'm doing something like:

foreach( $file_list as $file ) {

    $book = PHPExcel_IOFactory::load( $path . $file );


So, inside the foreach I'm (for now) just showing the data to the user, but after five files, I get a memory error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 50688 bytes) in /var/www/test/classes/PHPExcel/Shared/OLERead.php on line 76

Is there a way to __destruct the object after each file is loaded, so space is reserved (made free) for the next file, instead of accumulating it, or do you rather know of a reason and work-around for this?

Please let me know any suggestions you have.

Thanks in advance.

From stackoverflow
  • This has been an issue for awhile, and it doesn't look like there's a way around it -- that is, unless someone has come up with something clever since the release of 5.3......

    "...it seems that PHP 5.3 will fix this. However, I would like to see a confirmation of this somewhere." [Oct 21 2008]

    (source) (more stuff)

    KaOSoFt : I can try PHP 5.3. I'll check and report back. Thanks!
    Stephen J. Fuhry : Even if PHP 5.3 supports stuff to do it, it could be unimplemented.. also, when that post was made, PHP 5.3 was still ~8 months away.. but who knows. Maybe replying to that post will stir some more activity :)
    KaOSoFt : Definitely fixed on PHP 5.3, though I tried this version on Windows, and my current development environment is on Linux. I'll try updating my Linux PHP build later. It will take its time to complete (200+ files), but it works. Thanks for the reference: couldn't have done it without your help!
  • The latest SVN code for PHPExcel (just checked in today) introduces cell caching to reduce memory usage... it's such a new feature, I haven't even had the time to document it yet. While the default method is identical to the present method, with the worksheet <--> cell relationship containing a cyclic reference, I believe that using any of the memory-reducing cache mechanisms should eliminate this cyclic reference. If not, let me know and I should be able to break the reference when unsetting a workbook/worksheet using some of the caching logic that already disables this connection when serializing the cells for caching.

    KaOSoFt : Mark, I replaced the Classes folder I had with the latest generated Source on CodePlex, and now I get this error message: Fatal error: Call to undefined function imagecreatefromstring() in /var/www/competencias/Classes/PHPExcel/Reader/Excel5.php on line 774
    Mark Baker : imagecreatefromstring() is a GD2 function, although the call to this function in PHPExcel hasn't changed in the latest release: in fact, it goes back even before 1.6.7. You need to ensure that GD2 is enabled in your PHP build.
    KaOSoFt : Weird. I haven't touched my original development environment, which means that GD2 was enabled before. I'll check phpinfo() and report back.
    KaOSoFt : Mark, I had to hard reset my computer. Looks like restarting apache2 service on Ubuntu wasn't enough. My software processes the files now, although I seem to be having some logic issues. Oh, well, I most likely ask about it in another Question. Thank you!

change an attribute of css

newbie question in css:

I have the following style defined:

TABLE.tabulardata th {
    font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    background: #CAE8EA url(images/bg_header.jpg) no-repeat;

I want to create an identical style but with different background color.

question: is it possible to parameterize the attribute. Background color in this case Or do i need to copy the same style again

From stackoverflow
  • Like this?

    .myclass {
        font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
        background: url(images/bg_header.jpg) no-repeat;
    TABLE.tabulardata th {
        background-color: #CAE8EA;

    Then just add "myclass" to any element you want to share the attributes..

    Jeriko : If you like this kind of thing, you might want to check out something like LESS - http://lesscss.org/ You can declare variables to hold styles, and call them whenever you want, to reuse / mix a bunch of styles together into new ones :)
    balalakshmi : thanks Jeriko for the quick answer. that helped me I will look into the LESS option as well :)
    Jeriko : LESS and HAML were great finds for me - they turn the most boring part of being a developer (IMO, at least) into a breeze. Glad to help!
  • background-color: red

    Sohnee : This question isn't about setting the background-color (he has already done that in the example in the question) it is about having a similar style between elements, with some differences. See Jeriko's answer.
  • this is not possible with pure css. what you can do is to create 3 styles with classes, one being common two both and then assign them to an element

    .font { font-family: Linux Biolinum; }
    .red { color:red; }
    .blue { color:blue; }
    <div class="font red">red</div>
    <span class="font blue">blue</span>
  • One way would be:

    TABLE.tabulardata th, TABLE.tabulardataOther th {
        font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
        background: #CAE8EA url(images/bg_header.jpg) no-repeat;
    TABLE.tabulardataOther th {
        background: #FFF url(images/other_header.jpg) no-repeat;

    This works because of CSS precedence. The first line sets tabulardata and tabulardataOther to the same style. Then the second line overrides just the background of tabulardataOther (leaving the other attributes the same).

IE8 Slide Toggle Issue

Im having some trouble with jQuery's slideToggle function in IE8 for some reason the DIV its opening closes immediately after its opened

heres the code im using

$("h3 a").click(function(){
    id = $(this).attr("href");      

and the HTML

<h3><a href="#promo-materials">Graphic and Pormotional Materials</a></h3>
    <div id="promo-materials" class="center gallery">
        <a href="images/portfolio/bistro.png" rel="facebox">
            <img src="images/portfolio/thumbs/bistro.png" alt="" />
        <a href="images/portfolio/direct-savings.png" rel="facebox">
            <img src="images/portfolio/thumbs/direct-savings.png" alt="" />

Here is a link to the functional page it works in all other browsers including IE7

I forgot to post it:


I currently have it triggering Compatiblity Mode since I had to get to work today.

From stackoverflow
  • You could try this:

    $("h3 a").click(function(){
        id = $(this).attr("href");
        $('#' + id).slideToggle("slow");
    jef2904 : The only problem is that i do this for multiple "h3 a" that point to different DIVs
    Sarfraz : @jef2904: see my answer, updated, i think that should do the trick. you were not adding the `#` in your selector.
    Nick Craver : @Sarfraz - His `href` has a `#` in it already, it's in the code he posted...and that wouldn't explain why *only* IE8 has the issue.
  • I am betting Nick's comment about it being fired twice is the answer. I copied your code above and it works great for me in IE8.

  • Remove this style from the h3 right before the gallery

    display: inline-block;

    that seems to fix the problem in IE8.

    jef2904 : Worked perfectly Thanks

Excel and Tab Delimited Files Question

I am encountering what I believe to be a strange issue with Excel (in this case, Excel 2007, but maybe also Excel 2003, but don't have access to it as I write this).

I can reliably convert some server data over into a tab-delimited format (been doing this for years) and then open it using Excel - no issue.

However, what seems to be happening is if I have an html <table> inside one of the fields, it looks like Excel 2007 thinks it should be converting the table into rows and columns inside Excel (not what I want). As you might imagine, this throws off the entire spreadsheet.

So question is, is there any way to set up excel to NOT do this (perhaps some setting in Excel that pertains to reading tab delimited files), or am I missing something?


From stackoverflow
  • When you open the tab-delimited file, you are shown an import mapping dialog that lets you pick each columns' data type (date, text, currency, etc.). For the columns that have HTML data present, choose text. This will tell it basically to import as-is and not try to automatically parse the data into a derived format.

    OneNerd : the thing is, i am not shown the 'import mapping' dialog -- it opens right up and does its thing. How are you getting that dialog to appear? Thanks -
    JYelton : What is the extension on the file you are opening? Some file types Excel will open automatically where others provide the dialog. Try changing the file extension to CSV (comma separated values). You'll still be able to choose tab as the delimiter.
    OneNerd : i see - wont work for what I am trying to do. I am used to saving the tab delimited file as an .xls file, and excel always opened it up properly. Adding that extra step kills the ease-of-use. Is there another delimited format that will 'just work' without having to tell excel about it? Am wondering if this is an excel-2007-only issue.
    JYelton : If you save it with an .xls extension, then Excel uses some internal defaults for mapping the data. How to control those defaults... is unfortunately beyond me. Sorry.
  • If nothing else, import it into OpenOffice.org Calc, save as an .xls file, then open in Excel.

  • Excel 2003 does the same. I don't think there is a way to do it with a config because Excel finds delimiters in the html table and breaks the html in cells and columns as it does for the other columns.

    If the column containing html is always the same, you can use JYelton suggestion of renaming the file as csv and record a small VBA macro to load the file selecting automatically the html column as text in the import mapping dialog and you load the file calling the macro instead of double-clicking on the file.

  • Save your file as .txt

    Now open the file in excel using Drag and Drop (rather than double clicking your hookey .xls)

    Slightly more work to open the file, but your tab text formatting will now be respected.

android: having two listviews in two listactivities didn't work

I guess my previous question wasn't clear enough ( http://stackoverflow.com/questions/2549585/android-failed-to-setcontentview-when-switching-to-listactivity ), so I explain as follows.

In my app I have two listactivities which uses two different listviews:

public class Activity1 extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
public class Activity2 extends ListActivity {
public void onCreate(Bundle savedInstanceState) {


As required by android, listview must have an ID which is exactly "@android:id/list". If I set the listview in both listview1 and listview2 with the same ID, then they will end up using the same format of listview, which is not what I want. But if I set one of the IDs to be sth like "@+id/listview2", android gave me the error: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

How do I handle this dilema?

btw: my listview is sort of complicated, customed list with image icons and text, so in my code, I also extended the ListAdapter:

this.mListAdapter = new myListAdapter(this, 
            R.layout.listview1, mTiebaInfo);
From stackoverflow
  • Don't use ListActivities. Use Activities and have a ListView in the each xml which you can name however you want.

    Yang : can you be more concreate? The reason I am using ListView is because my list is complicated, and I also extended ListAdapter.
    jqpubliq : Complexity should have nothing to do with it. You can extend `BaseAdapter` and override getView() as you were showed previously to return any kind of view you want. Then simply get a reference to the ListView you defined and set its adapter to your custom one by calling setAdapter(adapter) on it.
    Yang : I unserstand what you are saying. I've already extended my adapter based on ListAdapter. The thing is, If I dont extend ListActivity, I won't be able to call setListAdapter(). If I only extend Activity and setAdapter() as you mentioned, how can I make it a list?
    jqpubliq : If you read [this](http://developer.android.com/resources/tutorials/views/hello-listview.html) you'll see that setListApapter just adds a list to the view and then sets the lists adapter. So if you just add your own list set to fill_parent and call setAdapter() on it, it is equivalent.

How to implement "circular side-scrolling" in my game?

I'm developing a game, a big part of this game, is about scrolling a "circular" background ( the right end of the Background Image can connect with the left start of the Background image ).

Should be something like this: ( Entity moving and arrow to show where the background should start to repeat )

alt text

This happens in order to allow to have an Entity walking, and the background repeating itself over and over again.

I'm not working with tile-maps, the background is a simple Texture (400x300 px).

Could anyone point me to a link , or tell me the best way I could accomplish this ?

Thanks a lot.

From stackoverflow
  • I don't know how different it is on the iPhone (OpenGL ES, I believe?), but in normal OpenGL, you'd set the texture tiling to repeat and then simply change the UV coordinates by the distance that the player moved. The texture tiling is set using:

    Mr.Gando : Could you add a code example for this ? or link me to one ? , thanks !
  • Alternatively you can translate the texture using an appropriate texture matrix. This saves you from having to recalculate/upload your UV coordinates each frame.

Why is there no Microsoft Certified Master program targetted at developers?

In the lower level certifications, developer technology is all over the place.

At the highest level (Microsoft Certified Architect), the Solutions track appears to be a good fit for high level application designers and architects.

MCA requires an MCM as a prerequisite.

However, none of the MCM tracks are targeted towards development. Obviously to be a good architect you need to have knowledge of other technologies, servers, sql, messaging etc. But those seem like things that should be part of the course load, and not the sole focus.

Are the lower tiers really as high as you can go for application focused professionals?

For most developers, the SQL MCM seems to be the best fit.

Are the MCM and MCA really targeted ad more administrators and not developers?

From stackoverflow
  • I have a great answer for you. Programming is considered a narrow skill, mostly outsourced to India. To be a well-paid programmer you have to ascend into a Systems Developer, that cannot only code but also has the experience to say which language to code in, can make technical architectural choices and so forth. Microsoft certifies their developers targeting their own products, such as C#. This means you can only learn some narrow techniques, and it's very hard to create a high-level developer certification using solely their products.

    Jason Coyne : While I agree with you on the surface, this doesn't jive with the rest of the tracks MS offers for MCM and MCA. Those are also narrowly targeted at Microsoft products, yet there are certifications for them, but none for the developer tracks.

How do I make a div that stays in a fixed position regardless of where you are on the page?

Case example: I have a long list of items, and when I put my mouse over this div changes to that picture of that item. No matter where you scroll to, the div remains in a fixed position.

Sort of like a frame.

From stackoverflow
  • the div remains in a fixed position.

    position: fixed? Test it here.

  • Use the CSS property position:fixed.

    Example: <div id="items" style="position: fixed; top: 20px; right: 20px">Hello there!</div>

  • Absolute positioning:

        <div style="position: absolute; top: 0; right: 0; width: 100px; height: 100px;">
    Guffa : That keeps the element in a fixed position relative to the page, I think that the OP want's it relative to the window.
    Dustin Laine : @Guffa - I don't think it is clear in message, I saw two fixed position answers and posted this to provide an alternative as I am unclear of his desired outcome.
  • Are you asking about div in fixed position? If you want to this the div by css itself, you can use the paramater like

    Guffa : That keeps the element in a fixed position relative to the page, I think that the OP want's it relative to the window.
    Karthik : Instead of fixed, we can absolute also
  • For newer browsers you can use position:fixed to make an element follow the window when you scroll.

    If you need to be compatible with older browsers, you would need a Javascript that gets the scroll offset from the window and changes the coordinates of an absolutely positioned element.

    fivetwentysix : Great answer thanks!

Navigate with location.href during XMLHttpRequest asynchronous call

I have a web page containing something like this:

<div onclick="location.href = 'AnotherPage';">

This page also uses asynchronous XMLHttpRequests for some ajax updating.

I have found that while an asynchronous XMLHttpRequest is in progress, clicking on this div does not load the new page. If I cancel my request first then it works fine. This seems wrong, but I cannot find any documentation that describes what should happen.

So the question is: what should happen to asynchronous XMLHttpRequests in progress when a new page is loaded using location.href?

edit - I worked around this problem by handling window.onbeforeunload and aborting my pending async request there. The question remains though, whether I should need to do this?

From stackoverflow
  • You might check out a similar question:


    I also saw a few questions where browser history issues were arising in similar circumstances, and the workaround was to wrap the location change in a setTimeout() call with 0 delay. If that were to fix the behavior, I'd be baffled as to the reasoning, but it'd be interesting to see the effect nevertheless.

    OlduwanSteve : Thanks I did see that, but in the answer the asker states that the reason was server-side. I think if I was going to wrap all my location changes then I might as well just call a function that could also cancel the requests.

php import to mysql hosted on godaddy

Yeah, I know! It's not my choice.

I am doing a large data import using a PHP script into a mysql DB hosted on godaddy. It seems their mysql connection gets killed every few hours regardless of what work it's doing. Their tech support is useless, and I've exhausted myself writing attempted workarounds. Right now, I'm trying to do a mysql_ping every few minutes, and if the ping returns false, I attempt to open up a new db connection.

My script (which takes many hours to complete), keeps failing with the very unhelpful message of "mysql server has gone away". I understand mysql trying to close a connection that's been open too long, but the connection is not idle-- it's busy basically the whole time, and with the pings I've written in, it should not be idle longer than 5 minutes at most at any time.

(These same scripts work with no errors on Amazon AWS servers, my local servers, etc.)

Any help most appreciated! I'm about to give up.

From stackoverflow
  • This makes complete sense to me. I've worked with many different hosting companies and almost all (the good ones anyway) will kill long running processes on any servers to keep it running trim and snappy for all the other people on the shared box.

    In short, don't import everything all at once, or perhaps contact godaddy support and try to give them a mysql dump (they may be able to import it for you)

    julio : I'm not importing everything at once, which is the odd thing. I even tried closing the connection and re-opening it after each segment and I still get the "gone away" error. Not sure what's up with that, though I assume it's something to do with their load balancing/clustering.

Rails - Populate test database with development data

Is there any trivial way to copy the data from developmenet database into the test one? I know theres a way to copy schema and recreate database, but is there any rake task to populate test database with development one?

From stackoverflow
  • You can use:

    rake db:test:clone

    To copy the development db into test.

    mdrozdziel : Doesn't work for me at all. Structure is created, but no records are copied. Is that task ment to copy the data at all? The description isn't pointing that directly.
  • You can use mysql directly:

    mysqldump app_development | mysql app_test

How can i get the source of a 777 - CHMOD php file?

A moderator of a forum i own did so. I still can't belive on it, and i can't understand how he did it. Can someone explain me? He said he used only HTTP GET requests

The moderator said that the server (nginx) would normally send the output of the executed php files, but since that the files are 777 adding some parameters to the URL he can get the unparsed version of it.


From stackoverflow
  • If there's a badly written download script on the site then it's as easy as rewriting the url to download any file (including PHP source files). That could be just what he did, so you'd better check if the forum software (and installed 3rd party modules) you are using don't contain any known vulnerabilities.

    cedivad : The problem is that the mod stated he didnt used any bugged/explotsble php script...
  • The answer lies here. Probably...


  • A properly configured server will only execute .php files, not reveal their source. But a badly configured server CAN serve up the PHP source via a .phps symbolic link pointing at the original file.

    Beyond that, query parameters cannot tell PHP to serve up the source, unless the source in question has a backdoor in it, something like:

    if (isset($_REQUEST['gimme_the_codez'])) {

    Of course, since the file's mode 777, if you can get into the directory it's in, you can get the file directly, or slap in the backdoor trivially.

    cedivad : Can you explain this better? ------- Of course, since the file's mode 777, if you can get into the directory it's in, you can get the file directly, or slap in the backdoor trivially. -------
    Marc B : If you have shell access to the server, or at least some way of executing an arbitrary program on the server, a mode 777 file can be subverted, as it's universally accessible.
    cedivad : Yes, but teorically you shouldn't have it...

What's a good matrix manipulation library available for C ?


I am doing a lot of image processing in C and I need a good, reasonably lightweight, and above all FAST matrix manipulation library with a permissive license. I am mostly focussing on affine transformations and matrix inversions, so i do not need anything too sophisticated or bloated.

Primarily I would like something that is very fast (using SSE perhaps?), with a clean API and (hopefully) prepackaged by many of the unix package management systems.

Note this is for C not for C++.



From stackoverflow
  • I'd say BLAS or LAPACK.

    Here you have some examples.

    banister : this looks great :) but i can't find a precompiled binary of the library anywhere for my (unfortunately right now) windows system. Any idea where i could find it?
    High Performance Mark : Start looking here: http://blogs.msdn.com/hpctrekker/archive/2009/02/24/hpc-math-attacks-blas-lapack-linpack-atlas-dgemm-acml-mkl-cuda.aspx
    Victor Liu : BLAS and LAPACK are generally considered interfaces, in the same way that OpenGL is an interface with many underlying implementations by graphics card vendors. That said, the fastest BLAS out there right now is GotoBLAS2, but its license is restrictive. Intel and AMD provide their own libraries (MKL and ACML) but those are also restrictive. Stick to the netlib reference implementations if you want truly free. You generally need to compile these yourself for your processor to get the best performance.
    stephan : @banister: the other option to downloading an existing binary is to build your own. A good way to do so is to use ATLAS (http://math-atlas.sourceforge.net/), which produces a BLAS tuned to your machine. See http://math-atlas.sourceforge.net/errata.html#WinBuild and http://math-atlas.sourceforge.net/errata.html#winpt for windows-specific info (also read the rest of the errata).
  • OpenCV

    alt text

    banister : no, i want matrix manipulation not image manipulation (im writing my own image manipulation lib) thanks though :)
    TheMachineCharmer : Look there is good MATRIX MATH in it too. Also it simplifies image processing.
    banister : Thanks a lot :) but i really *just* need the matrix manipulation, i am looking for something lightweight that provides just the functionality i need.. :)
    TheMachineCharmer : :D cool. Then BLAS looks good! +Pablo
  • I found this library and it's brilliant: Meschach

What is wrong with this mysql stored procedure?

I use the following mysql procedure,

DROP PROCEDURE IF EXISTS `allied`.`GetRegistrationData`$$
CREATE DEFINER=`allied`@`%` PROCEDURE `GetRegistrationData`()

 select aboutUsId,name from aboutus where isDeleted=0
 select ageId,name from age where isDeleted=0
 select desiredsetId,name from desiredsetting where isDeleted=0
 select disciplineId,name from discipline where isDeleted=0
 select employeementId,name from employeement where isDeleted=0
 select salutationId,name from salutation where isDeleted=0
 select timeId,name from timetocall where isDeleted=0


when i execute this i get an error,

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds 
to your MySQL server version for the right syntax to use near 
'select ageId,name from age where isDeleted=0
select desiredsetId,name from desir' at line 4

Any suggestion...

From stackoverflow
  • you missed the semicolons at the end of each SELECT line

  • You simply need to terminate your SELECT statements with a semicolon, to fix that error.

    bala3569 : @Daniel look at my question comments and suggest me..
    Pekka : @bala your current question is completely different from your original one. I think it would be appropriate to accept one of the answers given (maybe throw a coin :) and start a new one.
    Daniel Vassallo : I choose "heads" :)

Float: left not showing up after a certain point.


This works fine in Safari but shows incorrectly in the latest version of Firefox ( was fine in 3.5) and in some versions of IE.

In the middle column the product thumbnails drop down below when the 'float: left;' parameter is used. It is as if it is being escaped by a tag from that point forward no 'float: left's work and all the items are centered moving forward.

From stackoverflow
  • #sidebar_CAP:link visited active {

    You are missing an apostrophe.

    Bobby K : Thank you. Sometimes its simpler than one thinks. I had validated the HTML but had not tried checking the CSS itself. Thanks again. I can not vote this up yet but this fixed the issue.

Ajaxcontrolkit calendar control - customisation


Can the calendar control be customsised so that, say you have a system of renting out a holiday home. can the dates that have been booked appear as red and disabled on the ajaxcalendar control?

Cheers -- Jonesy

From stackoverflow
  • Run forest - run away from the ajax control toolkit. jQuery is your friend.

    Heres a link to the jquery Ui calendar. Other good plug-ins exists as well as other good javascript libraries, but MS is getting behind jQuery and jQuery UI is the official UI library.


    iamjonesy : the thing i love about the ajax control toolkit is its just so easy to use (apart from the question this post is about!). Like adding a calendar for a simple date picker. Just click on the text box and add the calendar extender! How does this compare to jQuery?
    iamjonesy : I've started a discussion about the Ajaxcontroltoolkit and jQuery - http://stackoverflow.com/questions/2628664/ajaxcontroltoolkit-vs-jquery
    James Westgate : Its interesting that others feel the same way - I think the upfront investment in getting into jQuery will help you later with lots of things relating to javascript and client side dev.
    iamjonesy : @James - wow that calendar plugin is slick! cheers!

simple c++ file opening issue

#include <iostream>
#include <fstream>
using namespace std;

int main ()
  ofstream testfile;
  testfile.open ("test.txt");
  testfile << "success!\n";
  return 0;

1)called "g++ testfile.cpp"
2)created "test.txt"
3)called "chmod u+x a.out"
5)file remains blank.

I feel like an idiot for failing at something as trivial as this is supposed to be.

From stackoverflow
  • When performing file I/O, you almost always need to test for errors:

    #include <iostream>
    #include <fstream>
    using namespace std;
    int main ()
      ofstream testfile;
      testfile.open ("test.txt");
      if ( ! testfile.is_open() ) {
         cerr << "file open failed\n";
         return 1;
      if ( ! testfile << "success!\n" ) {
         cerr << "write failed\b";
         return 1;
      testfile.close();   // failure unlikely!
      return 0;
    Robert : 1) use "(!( testfile << "success!\n" ))" not (! testfile << "success!\n" ) still does nothing. I also tried adding "cout<<"something";" at the start of the main function. I am beginning to believe the problem is not in the executable syntax
    anon : @Robert Good catch. I think your problem is to do with your environment, or your understanding of it, and not with your understanding of C++.
    wilhelmtell : you don't have to close the file. it's on the stack.
  • In theory they're equivalent, but just to make sure, do try << endl instead of "\n" to flush the stream.

    ofstream testfile;
    testfile.open ("test.txt");
    testfile << "success!" << endl;
    GMan : `close()` flushes anyway.

mysql create procedure script

I am a bit confused with mysql create procedure script. My script looks like as follows:

insert into hi (name,id)VALUES ('apple','2010');

It does not insert into table hi.

From stackoverflow

Selecting only first level element, not child elements with the same element name

How would I select only the first level .block and not any of the children?

$('.block:not("Children of this here")') <--

<div class="block"> <!-- this -->
  <div class="block"> <!-- not this -->
    <div class="block"> <!-- not this -->


<div class="block"> <!-- and this -->
  <div class="block"> <!-- not this -->
    <div class="block"> <!-- not this -->

From stackoverflow
  • If that sample markup has a parent element, for example below. If not, the parent will be body if it is valid HTML.


    <div id="parent">
    <div class="block">
      <div class="block">
        <div class="block">


    $('#parent > .block').css({ border: '1px solid red' });
    Alex Sexton : yay for reasonable solutions!
  • Try this:

    $("div.block:first").<what you want to do>

    edit: removed the spaces. thanks :-)....now it should be good.


    SLaks : This will not work (Because of the spaces)
    alex : You still have an extra space there, unless the `.block` is a child of a `div` element.
  • You can use the :first selector to select only the first matching .block element:


    This works because jQuery matches elements in document order. The outermost .block element will be the first element matched by .block, and :first will filter to only return it.

    Note that :first is not the same as :first-child.

    EDIT: In response to your update, you can write the following, which will only work if all of the elements are nested three deep:

    $('.block:note(:has(.block .block))')

    You can write a more robust solution using a function call:

    $('.block').not(function() { return $(this).closest('.block').length; })

    This will find all .block elements, then remove any matched elements that have an ancestor matching .block. (You can replace closest with parent if you want to).

    tester : Sorry I updated the question.. I need to match the first .block of each nest of blocks, so I don't know if this will work since it finds the very first block in the doc

C# Batching Process?

Can every body tell me by simple answer where & what i can create a batch process for ordinary operations such saving, changing file properties and so...

From stackoverflow
  • Have you tried starting with the C# Console Application template from File|New Project ?

  • A batch can be done by a simple forloop or while loop. What do you want to achieve?

    pRoF3SoR BaLtHaZaR : Thanks for your answers but i want details for some applicable batch processing such as converting image format via open dialogs such as batch image coverting tools in ACDSEE, PhotoShop, and ... Pls Write Step by Step, I' beginner in C# and need this code as soon as possible!!! Pls Hurry
    PoweRoy : Sorry but this site is for helping others with problems, not providing complete code. What have you tried yourself?

How to implement parent-child windows and pass values from child to parent?

I am working on an ASP.NET MVC 2 application.

In one of my data entry forms, I have an "employer" field which has a "search" link next to it. When a user clicks on this link, another window is opened with a search form. The user uses the search form to search for the correct employer. A list of employers is shown to the user. Currently, the user has to then copy and paste the correct employer from the child window into the original window.

I want to implement it so that each employer search result in the child window is a hyperlink. The user would then click on the correct employer and then the correct employer value would be populated in the original parent window employer field.

How would I go about implementing this in ASP.NET MVC 2?

From stackoverflow
  • Personally I would not use a new window but a modal dialog. jQuery UI has a nice modal dialog that you could load using AJAX

String literals C++?

I need to do the following C# code in C++ (if possible). I have to const a long string with lots of freaking quotes and other stuff in it.

const String _literal = @"I can use "quotes" inside here";
From stackoverflow
  • There is no raw string literals in C++. You'll need to escape your string literals.

    std::string str = "I can use \"quotes\" inside here";

    C++0x offers a raw string literal when it's available:


    By the way you should not name anything with a leading underscore as such identifiers are reserved in C++.

    Dennis Zickefoose : Names beginning with an underscore and then followed by a capital letter are reserved for the implementation for any use, so you can't use them at all. Names beginning with an underscore in general are only reserved as names in the global namespace.
    R Samuel Klatchko : @Brian - raw strings use parentheses `R"(C:\mypath)"`
  • There is no such mechanism in C++. You'll have to do it the old fashioned way, by using escapes.

    You might be able to use a scripting language to make the escaping part a little easier, though. For instance, the %Q operator in Ruby will return a properly escaped double-quoted string when used in irb:

    irb(main):003:0> %Q{hello "world" and stuff     with    tabs}
    => "hello \"world\" and stuff\twith\ttabs"
    jalf : are you seriously suggesting embedding a Ruby interpreter in your C++ program just to escape a string?
    Mark Rushakoff : @jalf: Absolutely not! I was suggesting to paste the string into Ruby once, then paste that result back into his source file. I can see where my answer could be interpreted in that ridiculous manner, though.
  • There is no equivalent of C#'s "@" in C++. The only way to achieve it is to escape the string properly:

    const char *_literal = "I can use \"quotes\" inside here";
  • That is not available in C++03 (the current standard).

    That is part of the C++0x draft standard but that's not readily available just yet.

    For now, you just have to quote it explicitly:

    const std::string _literal = "I have to escape my quotes in \"C++03\"";

    Once C++0x becomes reality, you'll be able to write:

    const std::string _literal = R"(but "C++0x" has raw string literals)";

    and when you need )" in your literal:

    const std::string _literal = R"DELIM(more "(raw string)" fun)DELIM";
    paxdiablo : +1 for educating me.
    R Samuel Klatchko : @paxdiablo - you're welcome. On a side note, my earlier example was incorrect. Raw strings use parentheses, not square bracket as delimiters. Also raw strings have more flexibility then my example shows (you can add a delimiter so that you can put `)"` in the actual string.