Thursday, April 28, 2011

Httpwebrequest / Httpwebresponse - Redirect Count

Hi Guys,

I'm trying to figure out how many times my web request was redirected before I finally landed at the end content.

I'm creating my web request as follows:

var httpRequest = (HttpWebRequest) WebRequest.Create("some arb path");
httpRequest.AllowAutoRedirect = followRedirects; 

I've had a look at the following URL http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.maximumautomaticredirections.aspx

However, I do not want to impose the limit. I actually want it to follow all redirects (not really wanting a reference to all the URL's), but just for example saying "You have been redirected X times".

I hope there's a quick way to do it as currently I'm assuming I would have to capture all 3xx codes and create a new request for each (hopefully not!).

From stackoverflow
  • There is no way to achieve what you want. You will have to capture each 3xx request and issue a new one with the location header of the redirect.

    However, if you want to use native C/C++ code and write directly to WININET (which is the library used by IE) it will provide you (via a callback mechanism) notification for each redirect that happened.

    Madabitjer : Giving you a point as you're the only guy that answered (even though I thought of the same solution)

Writing huge amounts of text to a textbox

I am writing a log of lots and lots of formatted text to a textbox in a .net windows form app.

It is slow once the data gets over a few megs. Since I am appending the string has to be reallocated every time right? I only need to set the value to the text box once, but in my code I am doing line+=data tens of thousands of times.

Is there a faster way to do this? Maybe a different control? Is there a linked list string type I can use?

Thanks.

From stackoverflow
  • Build your String together with a StringBuilder, then convert it to a String using toString(), and assign this to the textbox.

    Jimmy Hoffa : Maybe StringBuffer is a class I've never heard of, but I'm wagering it's more likely you meant StringBuilder
    Marc : Wrong language, `StringBuffer` is java. =)
    Frank : Yes, you are correct, I will edit the answer.
  • StringBuilder will not help if the text box is added to incrementally, like log output for example.

    But, if the above is true and if your updates are frequent enough it may behoove you to cache some number of updates and then append them in one step (rather than appending constantly). That would save you many string reallocations... and then StringBuilder would be helpful.

    Notes:

    1. Create a class-scoped StringBuilder member (_sb)
    2. Start a timer (or use a counter)
    3. Append text updates to _sb
    4. When timer ticks or certain counter reached reset and append to text box
    5. restart process from #1
    Marc : While your answer is definitely relevant, I think the statement *I only need to set the value to the text box once, but in my code I am doing line+=data tens of thousands of times.* means it won't be an answer to his specific problem.
    Steven Sudit : @Marc: Actually, Paul's answer is very good. One thread locks the SB, appends to it, unlocks. It does this many, many times. The UI thread can poll some small number of times per second, lock the SB, get the ToString and Clear it. This way, the UI update frequency is completely independent of the concatenation frequency.
  • No one has mentioned virtualization yet, which is really the only way to provide predictable performance for massive volumes of data. Even using a StringBuilder and converting it to a string every half a second will be very slow once the log gets large enough.

    With data virtualization, you would only hold the necessary data in memory (i.e. what the user can see, and perhaps a little more on either side) whilst the rest would be stored on disk. Old data would "roll out" of memory as new data comes in to replace it.

    In order to make the TextBox appear as though it has a lot of data in it, you would tell it that it does. As the user scrolls around, you would replace the data in the buffer with the relevant data from the underlying source (using random file access). So your UI would be monitoring a file, not listening for logging events.

    Of course, this is all a lot more work than simply using a StringBuilder, but I thought it worth mentioning just in case.

    HTH,
    Kent

    Steven Sudit : @Kent: If you look carefully at Paul Sasik's answer, including my comments, I think you'll find that it will not slow down with large strings. This is because we still use AppendText when writing to the TextBox and keep clearing the StringBuilder.
    Kent Boogaart : @Steven: but the `TextBox` still has all the data, thus you're still restricted in terms of how big your data can get. Virtualization does away with that since it only looks at a small window of the whole data set. You're only really limited by disk space.
    Steven Sudit : @Kent: Any cost/benefit analysis must include the costs. A virtualized textbox is much less useful, since you can't even do simple things such as Ctrl+A, Ctrl+C. Virtualization is appropriate in cases such as a grid attached to a database table.
    Kent Boogaart : @Steven: I'm simply pointing it out as an option. If you were to implement data virtualization, it's because you have large amounts of data. You *wouldn't want* Ctrl+A to work in that case because the user can shoot themselves in the foot. And even if you *did* want it to work (say, if there's less than 10MB data) you still could by virtualizing the selection. Or you could warn the user if they're about to copy a large amount of text (from the file) onto their clipboard.
    Steven Sudit : @Kent: Fair enough, data virtualization would be a correct general answer for how to handle unlimited amounts of data. I'll toss this an upvote so it gets noticed.

Filling std vector

Hello, I can't understand why does vector empty after it's filling.

The code is:

bool fillArray (vector<int> &array)
{        
    string temp;
    getline(cin, temp);

    if (temp  == "-1")
       return false
    else
       return true;

    int res = atoi(temp.c_str());
    array.push_back(res);
}

void showArray(const vector<int> array)
{
    for (int i = 0; i < array.size(); i ++)
        cout << array[i] << " ";
}


int main(int argc, char** argv)
{
    vector<int> array;

    while (fullArray (array))
    {}

    showArray(array);
    return 0;
}

When I input -1 the cycle breaks but the size of vector is 0, why?

From stackoverflow
  • These lines are your problem:

        if (temp  == "-1")
           return false
        else
           return true;
    
        int res = atoi(temp.c_str());
        array.push_back(res);
    

    In the case of good input, you're returning true from your fillArray method before you actually call push_back with the value on your vector.

    Ockonal : Stupid error =\. Thank you.
    Philipp : Is that your real code after all? The compiler issues an error because the semicolon after `return false` is missing.
    Praetorian : I don't understand why everyone seems to re-type their code into SO instead of copy-pasting. Not only is the `;` missing after `return false` but the call within `main()` is to some function called `fullArray()` instead of `fillArray()`
  • int res = atoi(temp.c_str()); array.push_back(res);

    is never reached in your fillArray Method, because the if returns true or false

parsing assembly code in perl.

0000000000033a1b subq $0x28,%rsp

I am having trouble extracting 0x28 from the above line. I am able to extract subq from a big list of assembly code but i only want 0x28 since this gives me the stack size. I was thinking of using substr() function buy there are variations to it, another one could look like this:

0000000000033a1c subq $0x000000b8,%rsp

in this case i only want 0x000000b8.

I am using perl.

Thank you.

From stackoverflow
  • If your input of the following format always:

    instruction_address operand $stack_size,register
    

    you can do:

    $a = '0000000000033a1b subq $0x28,%rsp';
    $a =~s/^.*?\$(.*?),.*$/\1/;
    print $a; # prints 0x28
    
    rashid : Thank you so much, it worked!. Could you please explain to me what is happening? I do not just want to copy and paste the code, i want to learn it. Thank you.
    Axeman : @rashid, he's escaping the dollar-sign for one...
    zen : rashid, the regex reads: ^ from start of string . any character * zero or more times ? non greedy modifier \$ a literal dollar sign ( begin capturing . any character * zero or more times ? non greedy modifier ) end capture group 1 , a literal comma .* everything else up to the $ end of string \1 substituted by capture group 1 --- see Recipe 6.15 in the "perl cookbook" for an explanation of greedy modifiers.
  • Without code, my guess is that you're not escaping the dollar sign. Thus you are asking for it to match the end of the line, and then '0x28'.

    In any regex, /\$0x(\p{XDigit}+)/ should capture '28' out of that string.

Glassfish - Deploying a WSDL with 2 functions of the same name

Hi all, i am using Netbeans to create a Web Service and the code is written in java. My problems arises from creating 2 functions that will be accessible by a client. The functions look alike by name but their parameters are different.

When building the web service(int a war file) i get no complaints. However when deploying the war file onto a glassfish server renders errors that would make me conclude that glassfish somehow is getting confused about 2 functions of the same name without looking into the parameter list. Is this a common occurrence and is there a workaround?

For example:

@WebMethod() public Long startMission(@WebParam(name="session") Session session, String name{ ..... }

@WebMethod() public Long startMission(@WebParam(name="session") Session session, Long num{ ..... }

The error on the glassfish server comes back to me and tells me that the 2nd StartMission function does not contain an entry point for parameter @Long num - which tells me that it does not recognize 2 functions of the same name. Perhaps i am thinking about this the wrong way. Any help, options, suggestions would be appreciated. thanks!

From stackoverflow
  • You can distinguish between the two methods by specifying the operation that they correspond to. This is done by specifying the operationName member value for the WebMethod annotation.

    For example,

    @WebMethod(operationName='startMissionWithName') public Long startMission(@WebParam(name="session") Session session, String name{ ..... }
    
    @WebMethod(operationName='startMissionWithId') public Long startMission(@WebParam(name="session") Session session, Long num{ ..... }
    
    cws : will the client see the operation name in intellisense causing confusion or will that be hidden from the user internally?
    Vineet Reynolds : The operation name described in the annotation is the one that is present in the generated (and published) WSDL, unless the client is using a different WSDL document. So, as far the client is concerned, it will now see two distinct operations.
    cws : so then whats the difference in adding the operation name and just make 2 separate function names? it would be nice to give the client the same function name with options on parameters and the execution of code beyond the function call would depend on the parameters passed.
    Vineet Reynolds : Well, to answer that question, here's another question - how is the container supposed to determine the name of the operation in the generated WSDL, and more importantly, map incoming requests against webmethod annotated methods, if two methods exposed in a service have the same name? You can find that someone has faced similar problems: http://planet.petalslink.com/home/chamerling/2009/05/14/an-operation-with-name-already-exists-in-this-service/
    cws : well i would have hoped that the container, just like a standalone library would be able to decipher the functions beyond just name scope and look at the parameter list - but for some reason this isnt possible. I looked at your link and the solution was what you had given to me - to put in the operationName annotation. But i see really no difference in that and just making the functions have different names, unless i am missing something.

PHP calling tree objects

$var is an array:

Array (
    [0] => stdClass Object ( [ID] => 113 [title] => text )
    [1] => stdClass Object ( [ID] => 114 [title] => text text text )
    [2] => stdClass Object ( [ID] => 115 [title] => text text )
    [3] => stdClass Object ( [ID] => 116 [title] => text )
)

How can we call [title] from some [ID]? (without touching [0], [1], [2], [3])

Like, if we call $var['114']['title] it should give text text text

Thanks.

From stackoverflow
  • You can't.

    You can make a new array which has the ID as keys, and after that you can access the title fast, or you can loop through the array every time you need to search some ID.

    Happy : looping each time seems not a good idea for performace.
    Gordon : @Ignatz yeah, but that's not Sjoerd's fault. He's just saying it like it is. You cannot omit the array index to get to the stdObject properties without any additional code.
    Sjoerd : I don't know how big your dataset is, but it is usually better to worry about performance when you really have a problem. If you search linearly for 50 items in an array with 100 items, this takes in the order of 1 millisecond. Is your user going to notice that? First solve the problem, then find the hotspots and optimize them.
  • Why don't you structure it like:

    Array (
        [113] => stdClass Object ( [title] => text )
        [114] => stdClass Object ( [title] => text text text )
        [115] => stdClass Object ( [title] => text text )
        [116] => stdClass Object ( [title] => text )
    )
    

    Problem solved.


    Say your records are in $records. You can convert it doing:

    $newArray = array();
    foreach ($records as $record) {
        $id = $record->id;
        unset($record->id);
        $newArray[$id] = $record;
    }
    
    print_r($newArray);
    
    Happy : CMS creates this array. Question is updated.
    NullUserException : @Ignatz And said CMS doesn't provide a better way to access data?
    NullUserException : @Ignatz answer's been updated
  • If I have understood you right, then here is my example:

    <?php
    // This is your first Array
    $var = array();
    
    // And here some stdClass Objects in this Array
    $var[] = (object) array( 'ID' => 113, 'title' => 'text' );
    $var[] = (object) array( 'ID' => 114, 'title' => 'text text text' );
    $var[] = (object) array( 'ID' => 115, 'title' => 'text text' );
    $var[] = (object) array( 'ID' => 116, 'title' => 'text' );
    
    // Now here the new Array
    $new_var = array();
    foreach( $var as $k => $v )
    {
        $new_var[$v->ID] = (array) $v;
    }
    
    // Now you can use $new_var['113']['title'] and so on
    echo $new_var['113']['title'];
    ?>
    
    NullUserException : What if the records have more properties (ie: `'title' => 'something', 'date' => 2009-02-30)`?
    Happy : thanks man, looks good

How to repeat a few characters a few times in bash?

In a bash script, I have to include the same file several times in a row as an argument. Like this:

convert image.png image.png image.png [...] many_images.png

where image.png should be repeated a few times.

Is there a bash shorthand for repeating a pattern?

From stackoverflow
  • #!/bin/bash
    
    function repeat {
        for ((i=0;i<$2;++i)); do echo -n $1 " "; done
    }
    
    convert $(repeat image.png 3) many_images.png
    
  • You can do this using brace expansion:

    convert image.png{,,} many_images.png
    

    will produce:

    convert image.png image.png image.png many_images.png
    

    Brace expansion will repeat the string(s) before (and after) the braces for each comma-separated string within the braces producing a string consiting of the prefix, the comma-separated string and the suffix; and separating the generated strings by a space.

    In this case the comma-separated string between the braces and the suffix are empty strings which will produce the string image.png three times.

    Philipp : This is the best solution for a fixed, small number of repetitions, but doesn't work well for a large or flexible number of repetitions.
    BastiBechtold : This is neat. I like this. But as Philipp mentioned, I kind of have to prefer a parametrized solution.
  • Here is a solution that uses arrays and is thus robust for strings containing spaces, newlines etc.

    declare -a images
    declare -i count=5
    for ((i=0; i<count; ++i))
    do
        images+=(image.png)
    done
    convert "${images[@]}" many_images.png
    
    Dennis Williamson : You can get by without the `declare` statements. In your example, Bash will do the right thing for you. You would just set your count like this: `count=5`. The array will be created by virtue of the parentheses.
  • This works with a given integer (10 in the example below).

    $ echo $(yes image.png | head -n10)
    image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png
    

    It can also be used with xargs:

    $ yes image.png | head -n10 | xargs echo
    image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png
    
    smichak : Yep - that's it...

How to have a carriage return without bringing about a linebreak in VIM ?

Is it possible to have a carriage return without bringing about a linebreak ? For instance I want to write the following sentences in 2 lines and not 4 (and I do not want to type spaces of course) :

  1. On a ship at sea: a tempestuous noise of thunder and lightning heard. Enter a Master and a Boatswain
  2. Master : Boatswain! Boatswain : Here, master: what cheer?

Thanks in advance for your help

Thierry

From stackoverflow
  • I think here is the answer to your question:

    http://stackoverflow.com/questions/759577/how-do-i-make-text-wrapping-match-current-indentation-level-in-vim

    ThG : I am sorry, I did not pay attention to the way my question was transcribed in Stack Overflow It should have been : Is it possible to have a carriage return without bringing about a linebreak ? For instance I want to write the following sentences in 2 lines and not 4 (and I do not want to type spaces of course) : 1. On a ship at sea: a tempestuous noise of thunder and lightning heard. Enter a Master and a Boatswain 2. Master : Boatswain! Boatswain : Here, master: what cheer? Sorry again, and thanks for your help Thierry
    ThG : Oops even worse...I have problems with carriage returns. In fact the question sums up to : may I have a theater dialog transcribed in 1 Vim line but with carriage returns to distinguish the protagonists (here the Master and the Boatswain). Needless to say I am a newbie
  • In a text file, the expected line-end character or character sequence is platform dependent. On Windows, the sequence "carriage return (CR, \r) + line feed (LF, \n)" is used, while Unix systems use newline only (LF \n). Macintoshes traditionally used \r only, but these days on OS X I see them dealing with just about any version. Text editors on any system are often able to support all three versions, and to convert between them.

    For VIM, see this article for tips how to convert/set line end character sequences.

    However, I'm not exactly sure what advantage the change would have for you: Whichever sequence or character you use, it is just the marker for the end of the line (so there should be one of these, at the end of the first line and you'd have a 2 line text file in any event). However, if your application expects a certain character, you can either change the application -- many programming languages support some form of "universal" newline -- or change the data.

  • Just in case this is what you're looking for:

    :set wrap
    :set linebreak
    

    The first tells vim to wrap long lines, and the second tells it to only break lines at word breaks, instead of in the middle of words when it reaches the window size.

Session object with WCF?

Hi

Is it possible to use Session object with WCF to store session related data? If yes the can you describe how?

Thanks

From stackoverflow
  • You can set the Instance mode to PerSession. And then your object that implements the OperationContract becomes the session object.

  • You can use Per Session Instance Management.

How do I detect when a device attached to the system is ready for use?

Hi all

I'm sorry if this is similar to an earlier question but this is something I just noticed. I can detect when my device is attached to the system (via usb) and trap the message correctly however if I unplug and plug the device back, attempting to access the device via the CreateFile() function always returns an error: ERROR_GEN_FAILURE 31 (0x1F) which translates to -A device attached to the system is not functioning, this is however, attempted after recieving the DBT_DEVICEARRIVAL message which by microsoft's own definition says "A device or piece of media has been inserted and is now available". I believe what's going on here is that the error has more to do with the device not being ready even though it's reported as being ready because if I re-enumerate the list of devices on the system again, the device is ready. Has anyone else encountered and gotten past this problem? Or is there something I'm missing/overlooking?

From stackoverflow

I can install an application but I don't see its icon in the set of installed applications(on the emulator).

Hey, When I load an application(which I just compiled) in the emulator. I don't see its icon in the icons of the installed application(on the emulator). The command "adb install ..." tells me that the application is successfully installed(I can even uninstall it with "adb uninstall ..." command). The application is nothing more than a "Hello World" type of application, you get when you create a project with "android create project --target ...." command. I can compile and run other application perfectly with the same set of tools.

Give me some pointers, what am I missing? what have I overlooked? Please help me.

From stackoverflow
  • Did you set the <category android:name="android.intent.category.LAUNCHER" /> intent-filter in your manifest?

    Sohail : Hey, thanks for the reply. Here is a portion of the androidManifest.xml file...
    Falmarri : In your `` portion set to the correct image?
    Sohail : Hey, It was very late at night and I went to bed... I did not manually set the icon image("android create project..." command did it for me). Here is that application element line which you mentioned from the AndroidManifest.xml file... . As per my understanding the value of attribute android:icon="@drawable/icon will be resolved with the help of file R.java and here is the related portion of that file... public static final class drawable {public static final int icon=0x7f020000;}
    Sohail : For some odd reasons, the things are working now. I can see the skeleton application icon on the emulator and the application works. Falmarri, thankyou very much for your time. If I'm able to find out what I was doing wrong, I'll put it here. Thank you once again.

clear property is not working in ie 7

Hi all,

I m using a div in my web site by using float:left and float:right after that is used clear:both, its working fine in all browser except ie7 i have tried a lot of things please tell me a solution to resolve this problem....

css:

.clear
{
    clear : both;
    margin : 0px;

} 

html:

<div style="float:left">some text</div>
<div style="float:left">some text</div>
<div class="clear"></div> 
<div style="float:left">some text</div>
<div style="float:left">some text</div>

Thanks

From stackoverflow
  • Try adding some content to the div:

     <div class="clear">&nbsp;</div> 
    

    A much better way to do this, though, is clearfix.

    Mayur : Hi sorry but it's not working
     
    Pekka : @Mayur strange! Then I don't know what it could be, sorry. Are you sure the CSS is getting loaded?
    Mayur : Pekka sorry, now i have tried a clearfix property its working thanks a lot....

How do I truncate a file X bytes from the end?

Lets say there is a file which is 150 bytes long and I want to truncate the last 16 (or any number) of it from the end...

Is there any other way to do it than re writing the complete file?

UPDATE: The SetLength should do the thing, but unfortunately NotSupportedException is thrown

using (FileStream fsFinalWrite = new FileStream(FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{

  fsFinalWrite.Seek(16, SeekOrigin.End);

  fsFinalWrite.Write(SwappedBytes, 0, 16);

  Debug.WriteLine("fsFinalWrite Can Seek = " + fsFinalWrite.CanSeek);
  Debug.WriteLine("fsFinalWrite Can Write = " + fsFinalWrite.CanWrite);

  fsFinalWrite.SetLength((long)lengthOfFile);

}

Both print true! But still it throws a NotSupportedException. Anyone know how to handle this?

From stackoverflow
  • On linux (or other posix systems): truncate, ftruncate

  • using System.IO;    
    using System.Linq; // as far as you use CF 3.5, it should be available
    
    byte[] bytes = File.ReadAllBytes(path);
    byte[] trancated = bytes.Take(bytes.Lenght - 15);
    File.WriteAllBytes(path, trancated);
    

    let's encapsulate it a bit:

    void TruncateEndFile(string path, int size)
    {
        byte[] data = File.ReadAllBytes(path);
        File.WriteAllBytes(path, data.Take(data.Lenght - size));
    }
    
    Ranhiru Cooray : Thank you :) Although this will work, this will take complete file to memory, change it and then write it back... Isn't there a more efficient way of handling this?
    abatishchev : @Ranhiru: Not the best way, of course. I will think about something more effective
  • What about FileStream.SetLength()?

    Kevin Brock : I was about to add this. Link http://msdn.microsoft.com/en-us/library/system.io.filestream.setlength.aspx
    Ranhiru Cooray : Thanx this should work :)
    Ranhiru Cooray : Unfortunately there is a `NotSupportedException` thrown when SetLength is used... But i checked, `CanSeek` and `CanRead` are both true... I don't know why it is Not Supported
    Gary : What about CanWrite?
    Ranhiru Cooray : Just checked...CanWrite is true as well. Please check the updated question

How can I use jQuery Dialog for Add/Edit screens?

Clicking a link would open a List page in a jQuery Dialog popup. From this page, I would like the ability to Add (one jQuery Dialog) a record and also edit the record (another jQuery Dialog) with validation. I'm not sure how to handle multiple popups with Ajax posts that actually call the add/edit function. I'm working with ASP.NET MVC 2.

Looking for code samples or links to relevant tutorials--haven't been able to find anything with add/edit capability.

From stackoverflow
  • I've answered this before:

    http://stackoverflow.com/questions/1843894/simple-asp-net-mvc-crud-views-opening-closing-in-javascript-ui-dialog

    David : When you say `The next step is to create your form. I use the default property name = input name` what does that mean? I think you're talking about binding it to a specific model's property, but is this form in a new view, partial view, something else entirely? Do I need to add one of these views for each table I'm working with, or are you indicating that jQuery.Forms can "scaffold" this for me?
    David : Your other answer also doesn't include the jQuery I need--you use a modal window called ColorBox. Can I use jQuery's Dialog for this?

Overriding inline CSS styles in IE7

I have a html tag with inline CSS style like: <body><div style="position:absolute;top:100px;"></body> and I want to override this inline position property. So, I wrote a CSS rule like this:

body > div[style]{position:relative !important;top:0px !important;}

The above code works in Firefox. But in IE7 it does not work. Am I missing anything for IE?

PS: Even though I could see my overridden attributes in Firebug lite window, it's not affecting anything on my page. (Plz refer the attached image).

alt text

From stackoverflow
  • Your selector doesn't need to be that specific - I'm not sure but I'm not sure IE7 would understand it. The !important should override it.

    Have you tried this?

    body div {position:relative !important;top:0px !important;}
    
    Veera : yeah.. if i changed like this, it works. :)
  • The style attribute selector is not supported in IE7: http://reference.sitepoint.com/css/css3attributeselectors

    derekerdmann : This isn't a CSS3 attribute selector. All it does is match any elements that have `style` defined. http://reference.sitepoint.com/css/attributeselector
    Will Prescott : Sure, I was only referring to the compatibility section of that page which suggests that style cannot be used in any attribute selectors in IE7 (CSS3 or otherwise), which having tested it seems to be true.

php.ini: what i must change, to write <? instead <?php?

in my local hosting the script doesn't work, if i wrote <? instead of <?php.

what i must change in php.ini to correct it?

Thanks

From stackoverflow
  • http://php.net/manual/en/ini.core.php

    short_open_tag
    

    Is the property you seek.

    Syom : @Bisko Thanks man;) it can be `On` or `Off` ?
    bisko : Sure, It must be ON to allow
    Syom : ie. it doesn't work in versions >= 5.3.0 ???
    Richard Knop : No it doesn't work for version >= 5.3.0.
  • It is:

    short_open_tag

    Make sure to read:

  • It's already been said how to do it, but I'm just saying that it might not be such a great idea. Almost anyone you ask will tell you not to use short tags. Unless you have a specific reason to use short tags, you should just type <?php. It's only 3 more characters.

box turn effect

I want to implement box turn effect as in the following site when mouseover

(please see the boxes below animation)

http://pepsi.com/

It is made using flash,but i want to develop it using other than flash. will it be possible?

From stackoverflow
  • You can do this in something like jQuery. There are plenty of examples where you can turn a div and all you need to do is when the div is at it's narrowest then you substitute the graphic for another one and continue turning.

    Though I have to agree with @Peter, Please don't!

    http://lab.smashup.it/flip/

I need small tests to practice on

I am looking for small exercises to do with javascript. I found a few, such as http://www.ling.gu.se/~lager/kurser/webtechnology/lab4.html, which was great, and zipped right through. I also found http://code.google.com/codejam/ which was AWESOME but each one is taking about a day for me.

tl;dr : Im looking for mid level programing exercises to do.

From stackoverflow
  • You could always try to do the exercises from ProjectEuler, although I must admit I am not entirely sure what type of exercises you were looking for.

    jason : simple stuff, object oriented javascript tasks would be ideal, stuff that shows design patterns, but anything interesting, really. edit : projecteuler looks like fun! Thanks!
    Tim : Was going to suggest this :o) ++
  • Take on your own project! Make something cool/useful, and then learn the code necessary to complete it.

    jason : I do. Most of its hideous. Little of it is actually useful. All fun though!

Full-text search with wildcard

I have a table with full text search enabled. But I can't get query the table using wildcard.

select * from products where contains(Description, 'Computer') returns rows with the word "Computer"

select * from products where contains(Description, 'Compute*') [replace "r" with "*"] returns nothing

What's going on?

From stackoverflow
  • Assuming SQL Server, add double quotes around the wildcarded expression like so

    SELECT * 
    FROM products 
    WHERE contains(Description, '"Compute*"')
    

In TFS Build (MSBuild), how can I only have a specifc project in my drop folder

"Out of the box" the build in TFS will compile a complete solution and put all the "deliverables" from all its project into the drop folder.

How can I have only the deliverables from a single "main" project end up in the drop folder, why still having all other projects (which it depends upon) compiled?

From stackoverflow
  • You need to create a separate Solutions for your projects. So then you can control which project should go to Drop Folder in one of the solutions and those that do not in another solution

    urig : Not quite what I need. The projects are in the solution for a reason - the main project depends on them.
  • Not quite sure if this is what you want, but try:

    <Target Name="AfterBuild">
        <Copy SourceFiles="c:\drop\myfile.dll"  DestinationFiles="c:\temp"  />
        <Delete Files="c:\drop\myfile.dll" />
    </Target>
    

    Basically, moving them away from the drop location after build.

    urig : Thanks. That's a promising direction. But that would require me to specify each and every file that I need to preserve. Isn't there some way for me to indicate the project I'm interested and have its products automagically preserved for me? :)
    pm_2 : You can recursively copy files if that's what you mean: http://blogs.msdn.com/b/msbuild/archive/2005/11/07/490068.aspx
    urig : Thanks again. I don't think recursion helps me. What I need is a filter - Something that will give me only those DLLs and files that come from the direct compilation of the "main" project. The non-essential deliverables from all other projects in the solution are cluttering my drop folder.

C#: Iterate over each Day between StartDate and EndDate

I have a DateTime StartDate and EndDate.

How can I, irrespective of times, iterate across each Day between those two?

Example: StartDate is 7/20/2010 5:10:32 PM and EndDate is 7/29/2010 1:59:12 AM.

I want to be able to iterate across 7/20, 7/21, 7/22 .. 7/29.

Help?

From stackoverflow
  • for(DateTime date = StartDate; date.Date <= EndDate.Date; date = date.AddDays(1))
    {
        ...
    }
    

    The .Date is to make sure you have that last day, like in the example.

    Dean Harding : I think you want `date.Date <= EndDate.Date` so that you get the final day.
    corvuscorax : This goes into an infinite loop, the AddDays method doesn't change date, but returns a new DateTime instance. Use date = date.AddDays(1) instead.
    Yuriy Faktorovich : @Dean: Thanks, saw your comment after change.
  • DateTime date = DateTime.Now;
    DateTime endDate = date.AddDays(10);
    
    while (date < endDate)
    {
      Console.WriteLine(date);
      date = date.AddDays(1);
    }
    
  • You have to be careful about end-date. For example, in

    "

    Example: StartDate is 7/20/2010 5:10:32 PM and EndDate is 7/29/2010 1:59:12 AM. I want to be able to iterate across 7/20, 7/21, 7/22 .. 7/29.

    "

    date < endDate will not include 7/29 ever. When you add 1 day to 7/28 5:10 PM - it becomes 7/29 5:10 PM which is higher than 7/29 2 AM.

    if that is not what you want then I'd say you do

    for (DateTime date = start.Date; date <= end.Date; date += TimeSpan.FromDays(1))
    {
         Console.WriteLine(date.ToString());
    }
    

    or something to that effect.

Sending Values to Iframe HTML PAGE

Hi All,

I have an asp page and in asp page there is iframe having HTML page. What i need is to send two values from asp page to inner HTML page. How is it possible.

From stackoverflow
  • You can pass them as query string vars:

    <iframe src="page.asp?var1=<%=var1%>&var2=<%=var2%>"></iframe>
    
    David Dorward : `&`! Your vars are not entity names.
    Anil : Thanks for reply but I have HTML page in the iframe.... SO...
    Sarfraz : @Anil Kumar: If it is html page how will you process the query string vars? Shouldn't it be asp page too?
    Anil : @ sAc..Thanks for reply...Yes i know but i it is a HTML template( NEEDED HTML) which brigs dynamic news article. so all the things are going well but i need the article id of asp page to send farward using javascript.
    Sarfraz : @Anil Kumar: Yes just replace name and extension in my answer in the `src` to html eg `src="pageName.html?var1=<%=var1%>&var2=<%=var2%>"` and you get the vars for url using `Request.QueryString("Name")`
    Anil : let me check....
    Anil : Thanks, sAc....
    Sarfraz : @Anil Kumar: You are welcome :)

integrating a new component in an old website ?

hi,

I have an old website and I've been asked to implement a small forum to display in a specific website block.

I've implemented this forum with Drupal and now I need to integrate it into the old website.

I was wondering how to integrate it:

  • should I just create a 1 to 1 copy of the old website page and add the Drupal forum
  • or should I use an iframe to include my Drupal work in the original old page ?

What's the best approach ?

I'm not even sure if the old website and the new Drupal installation is going to be stored on the same server.

Thanks

From stackoverflow
  • Not knowing the details of your situation, I would prefer to customize a theme in Drupal to match the visual design of the old site, copy the navigation to link back to the main site, and then add a "Forum" link to the navigation of the old site pointing to the new Drupal forum. That solution will keep both sites fairly independent, and you won't need to worry about Drupal navigation and other things showing through like you would if you did it in an iframe.

    But this is just an advice, to give a proper answer I'd need to know more about your old site - what technology it is using etc. Perhaps it would even be possible to include the main site's navigation into Drupal, instead of copying, thus reducing redundancy.

  • Just do the whole thing in Drupal, you'll have less to maintain and you'll achieve consistency for later changes.

    Patrick : but in this way I have to keep my 1-1 copy (surrounding my forum block) consistent with the other pages of the website, right ? I also think it is better... anyway
  • There can be a lot of factors that may determine a good approach.

    It's a no brainer to combine the old site into the Drupal system when:

    1. The old site and the forum can share the same theme
    2. The content to the old site can easily be ported to Drupal
    3. The content on the old site changes frequently (or would if it could)

    Maintaining content through a (Drupal) CMS can be much simpler and less error prone than static HTML files.

    If you have to create two different themes and section the Drupal system it becomes more involved, but, of course, doable! Drupal has some powerful multi-site capabilities.

    If you have to incorporate multiple-themes or implement it as a multi-site then you might look at the Domain or Sections modules

    Emyr : This is what I meant. No point having two separate "systems" when Drupal will easily run everything.

Is it possible with Views module to create a search and results page?

I know Drupal has built in search module, but I want more flexibility and control. Is it possible using Views to create the search form and results pages?

From stackoverflow
  • Sure. There's two ways. One is to use Views filters: just create the view for the results page, add a filter, and expose the filter. You can create a search block by checking the option to create a block for the exposed form in the Views settings. Load the Advanced Help module for more information about Views filters.

    The other way is to use Apache Solr and the Apache Solr Views module. Same idea as just using Views filters, but it'll use the Solr search backend instead of just doing SQL queries to the database.

    Tim : Thanks again Mark, this has put me on the right track. Currently the search block is submitting to my home page and adding the search term onto the query string, is this the intended behaviour? I have the search block appearing in a panel what I would like to happen after the user submits it is it submits the search query to another page/panel with the results view
    Mark Trapp : I'm not familiar with how Panels works, so it could be interfering with the exposed filter block. Outside of that, if you have a page display in a view with exposed filters in a block, the intended functionality is that when you submit the form in the block it takes you to the page from which the block is derived regardless of where the block is.
    Tim : Actually, I didnt have a page display, once I set it to page, it worked fine. cheers.