Monday, February 21, 2011

Correct command to retrieve remote mercurial updates pushed from my second machine

I'm new to Mercurial.

  1. I initialized a Mercurial project on Machine A, committed my changes and uploaded them to a remote repository.

  2. Then I cloned that repository on Machine B, committed some additional changes and uploaded them to the same remote repository.

In both cases, I uploaded the changes with the same command:

hg push https://username:password@domain/user/repository/

Now I'm back on Machine A and I'm not sure how to update my local repository with the last changes I uploaded to the remote repository from Machine B.

The commands hg clone or hg pull look like they might work but I'm not sure.

Would appreciate any guidance. Thanks.

From stackoverflow
  • Use hg pull; pull transfers only changesets which are missing in the existing destination repository.
    hg clone creates local copy of a remote repository.

    See also this so question.

  • hg pull will transfer any remote changesets not present in your local repo. Afterwards, you'll need to either hg update or hg merge depending on the presence of local changes.

Is it possible to perform case sensetive search in OpenGrok?

Looking at the OpenGrok help page reveals that the search query is based on Lucene, and Lucene in turn indicates that search queries are converted to lower case. I was wondering if there is any way to change this behavior and perform a cases sensetive search.

From stackoverflow
  • Reference search (-r) is case sensitive, as is definition (-d).

Windows file association to open with Eclipse/CDT editor.

How can I open a file with Eclipse/CDT when I double click it in windows explorer?

I set the file association in windoes to eclipsec.exe and it opened Eclipse/CDT, but not the file.

If Eclipse is open, it says "Workspace in use..."

Ideas?

mcb

From stackoverflow

jQuery Ajax problem when modularized

I can't seem to make this work. I'm accessing this method from a seperate .js file.

function TabLoaderAJAX(xurl, xdata) {
    var result = null;
    $.ajax({
        type: 'POST',
        url: '/services/TabLoader.asmx/' + xurl,
        data: xdata,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function(msg) {
            result = msg.d;
        }
    });

    return result;
}
From stackoverflow
  • Your request is asynchronous so when you return result variable it is set to null because the ajax request is not finished yet. You have to do a synchronous request by adding async:false in the option list. In this way you wait until the request finishes and then return the value of result.

    Martin Ongtangco : that clarifies things, thanks!

I want to insert a checkbox inside a accordion header in my Application (AIR).Can any one of you please help it out?

In my application i want checkbox on the accordion ,so is it possiable to set checkbox ? if it is possiable How can i identified child ?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 width="100%" height="100%">
      <mx:Accordion>
                <mx:headerRenderer>
                        <mx:Component>
                                <mx:CheckBox label="myCkb"
/>
                        </mx:Component>
                </mx:headerRenderer>
                <mx:Panel title="Content1" label="P1" width="200"
height="200" />
                <mx:Panel title="Content2" label="P2" width="200"
height="200" />
                <mx:Panel title="Content3" label="P3" width="200"
height="200" />
        </mx:Accordion>
</mx:Application>
From stackoverflow
  • What you meen by "insert a checkbox inside a accordion header". Add a CheckBox icon? Add a CheckBox funcionality?

    Probably you need new component like this - "Accordion with Icons". Look how it's done. You must create your own CheckBox logic or use CheckBox component instead of a icon.

    R.Vijayakumar : CheckBox funcionality (if i select that checkbox within accordion header child also select ) is it possiable to create checkbox component on the accordion header
    Konrad : Only if you write your own accordion. It's not so hard. Then you will add events listeners for MouseEvent to part of accordion header under CheckBox component - not on main container of accordion header. That will work.
  • If you did not want to just change the arrow, then you can make an itemRenderer for the Accordion's header, and place it inside Accordion.headerRenderer

    http://blog.flexexamples.com/2007/09/24/creating-a-simple-flex-accordion-inline-header-renderer/

What's the harm in giving full trust to a website when ACL's are in place?

Some websites require full trust for whatever reason like using third party controls which require full trust.

This is the scenario: say you're hosting a site with full trust and the site owner decided to do something nefarious on the system. The site can only connect to its database. The site is running under a user which is only used for that site. That user has locked down rights on the file system where they can only write/delete/read files in the site's folder/subfolders, in the system's temp folder and in the 'Temporary ASP.NET Files' folder.

My question is can a full trust web site do any harm to the system where the admin can't control? I am no expert in asp.net security but I think one can create a custom config file for the site where certain permissions are revoked while giving them full trust?

I appreciate posting a good resource on securing full trust sites. I don't believe full trust equals having a free ride on the system!

From stackoverflow
  • The risk is there may be things you (we) haven't thought of. It's not like Windows has never had a bug to allow user escalation.

Embed video on a asp.net-mvc website

I will be embedding a video to my asp.net mvc website. A video on the homepage which will help people to better understand the website. I have never done this. Can anyone tell me whats the best way of doing it. Flash or silverlight??

From stackoverflow
  • My suggestion would be to go with Flash and to achieve what you're looking for, utilize swfobject. It's really quite simple to use and has a bunch of options that will be useful when you get more used to using video.

  • I have had pretty good success using silverlight with the Silverlight 2 Video Player as an example. However, it depends on what your requirements are.

    Pros to Silverlight:

    • Performs Video Streaming very well
    • Easier to develop/customize if you are a .NET developer
    • Works on a variety of browser and platforms

    Cons to Silverlight:

    • Does not support every video media type (the example above only plays .WMV files, Silverlight in general supports .WMV and .MP4)
    • Is not installed on as many client machines (less penetration)
    • Is not as well known (users may be reluctant to install it compared to Flash)
    • Is not as popular so there are less solutions/resources out there

    Here is another discussion on the topic.

  • I've used JW FLV Media Player. I was pretty happy with it, and it's easy to use. Flash-based.

    http://www.longtailvideo.com/

  • I would go with flash for only one reason: the 99% (or whatever it is today) installed base.

    Then go with swfobject or JW FLV Media Player as suggested in the other answers. There is also a jQuery plugin floating around somewhere that helps deal with flash video on a site.

"Normalize" procedure in C#

Could someone explain to me what the normalization procedure for 3D surface mesh in C# is?

In a reference book, there is a line as follows :

The GetNormalize method is used to map the region of your surface into a region of [-1, 1], which gives you a better view on your screen.

From stackoverflow
  • You calculate the box bounding your surface mesh, get the longest side of the box and scale everything down by that value. The result will be [0,1] for that side and [0,<1] for the rest.

    If you need [-1,1], you double everything and substract 1, getting [0,1]*2-1=[0,2]-1=[-1,1].

Why does ContentResult controller in ASP.NET MVC return UTF-16 when UTF-8 specified?

I have an ActionResult that returns XML for an embedded device. The relevant code is:

return Content(someString, "text/xml", Encoding.UTF8);

Even though UTF-8 is specified, the resulting XML is:

<?xml version="1.0" encoding="utf-16"?>

The ASP.NET MVC is compiled as AnyCPU and runs on a Windows 2008 server.

Why is it not returning UTF-8 encoded XML?

From stackoverflow
  • You are confusing the encoding of the HTTP response with the encoding of the XML contained in the response. When you serialize the XML you need to specify that it needs to be UTF-8 encoded. Setting the encoding on the ContentResult simply informs the browser on the other end how the response was encoded, it doesn't transform the XML from one encoding to another. If you look at the code for ContentResult, you'll see that it it simply does a Response.Write( Content ) -- after setting the Response headers with the encoding and content types you specify.

    Todd Brooks : Many thanks! I knew I was confusing something so obvious!

Location of labels

I'm trying to find out if there is a way to determine if a label is in a given location on a form. Basically the user will drag a panel into 1 of 225 labels and I need to determine which label the panel is on.

Jon

From stackoverflow
  • The "sender" parameter that is given in most GUI events represents the control which generated the event.

    Also, you can call the GetChildAtPoint() function to get the control present at a given mouse location.

    Jon : Thanks a lot! I got it working.

Missing report in History?

I have a scheduled SSRS report that runs at 5am and takes 5s to process, the output of this task normally appears in the History tab. This morning the report is not in the history tab! A manually run report does appear, and on checking the actions for the morning, SQL5 says that the action ran successfully. My question is this; Has any one else come across missing scheduled reports from their history tab, and if so what can be done to stop it happening again?

From stackoverflow
  • I would try re-adding the job and testing it out. That should do the trick.

    Jon : I shall give it a go. Many thanks :-)

Question of accessing data in Cache object that is updating

Hi,

What happen if multiple clients try to access objects in cache that are undergoing update?

Can anybody give any information?

Thanks,

Ricky.

From stackoverflow
  • Hello,

    System.Web.Caching.Cache internally uses Monitor class for synchronization. So if there is undergoing updates, your reader threads will be blocked.

Problem while disabling scrolling of UITableview

Hi, I am facing a problem while disabling the scrolling of table view.When i disabled the scrolling then the cells are not responding to user clicks,even delegates( like - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath) are not firing .Still dont know how to resolve looking for a solution Thanks in advance....

From stackoverflow
  • Simply set the property scrollEnabled inside your UITableViewController code. I tested the following successfully:

    - (void)viewDidLoad {
        self.tableView.scrollEnabled = NO;
    }

Unable to set focus to textbox in dojo datagrid

I have a Dojo Datagrid with one of the columns being rendered as a textbox by a formatter function. When I click on the rendered textbox to enter some value, the cursor appears in the textbox and focus is immediately lost (i.e, the cursor disappears - typing does not produce anything). I have to click once more on the textbox for the focus to set - only then can I enter values.

Is there any way to set the focus on the first click itself?

Here is the code:

<table dojoType="dojox.grid.DataGrid" store="selectedItemsStore" class="resultsGridClass" jsid="selecteditems">
<thead>
<tr>
<th field="field1" formatter="renderTextBox" width="20%">Field 1</th>
</tr>
</thead>
</table>

And here is the formatter function:

function renderTextBox(value, rowIndex) {
var htmlString = "<input type='text' name= 'exp' />";
return htmlString;
}
From stackoverflow
  • Try setting editable and alwaysEditing attributes to true:

    <th alwaysEditing="true" editable="true" field="field1" formatter="renderTextBox" width="20%" >Field 1</th>
    
    Shivasubramanian A : Nope. Does not work.
    ivalkeen : You can try to repeat behavior from this test page (when Toggle dSingleClickEdit is pressed): http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_edit.html

Android application configuration

Where should I store my Android application's configuration settings? Coming from the .NET world I was expecting something like .config. Do I create a file under res/values, and use that?

From stackoverflow
  • There is no res/assets. There are assets/ and res/raw/ for arbitrary files, and res/xml/ for arbitrary XML files. However, all of those are packaged as part of the APK and are not modifiable at runtime.

    Take a look at SharedPreferences and the PreferenceScreen system for collecting them from users, if these are user-selected configuration settings.

    fatcat1111 : SharedPreferences is what I need. Thank you!

JQuery slide.Toggle menu firefox problem

Well, take a look at www.creade.biz

Now click o A4 ITEM and JQuery to see slideToggle in action. It works fine in IE but crash in Firefox. If you try to close the opene A4 ITEM It will reopen. How I can fix It?

Thanx for your help!

From stackoverflow
  • Your XHTML document has a whole bunch of validation errors:

    • Using a <div> tag as a direct child of a <ul> tag.
    • Using <li> tags without a <ul> (or <ol>) tag as its direct parent.
    • Using <p> tags as children for <span> tags.

    If you change <div class="collSub"> into <li class="collSub">, start a new <ul> tag for the nested list elements under the A4 item, and change all of your <p> tags into <span> tags, it'll work out for you.

    Also, for future reference, you can check the markup validity of your XHTML documents by using The W3C Markup Validation Service.

    natspace : Thanx a lot Tinister! You're a guru!

Any free mobile IDEs that run on a Blackberry?

I was just wondering if there were any IDEs that I can run on my blackberry. My old Palm had on board C and a BASIC interpreter. On board C used the Palm's builtin text editor but the BASIC interpreter had its own simple editor built in.

Anything like this for Blackberry or j2me in general?

From stackoverflow
  • As far as I know, there are no Basic or C interpreters or IDEs that run specifically on the BlackBerry, but there is an open source J2ME basic dialect called CellularBasic which is meant to be coded with/executed on the device itself. It targets J2ME, so it may run on the BlackBerry: http://cellbasic.sourceforge.net/

  • I'm working on a Hecl port for BlackBerry, but it's not quite there yet. If you're curious, join the Google Group, where I post updates about the state of things.

Degrafa Best Practices

I've been learning Degrafa recently, and I have noticed that there is not much consistency amongst examples posted on the web. Is there a place where I can find degrafa best practices (esp. for skinning)? or can anyone suggest examples that use best practices?

From stackoverflow
  • This is not really an answer, just a comment, I'm afraid :)

    I think one of the challenges is that we (the Degrafa team) continue to develop Degrafa and therefore continue to introduce new (and easier) ways to do things - so some of the older samples are out of date and need to be refreshed. We will be refreshing a number of the older samples on the Degrafa site soon.

    We'd love it if the user community starting making more examples as well - I know some people have and that there are a number of discrete examples and tutorials around but it takes a bit of googlehunting to find them and there is not a definitive guide somewhere. I can let you know that at least a couple of people (Jason Hawryluk and Josh McDonald) are working on full theme style skinning examples that will be able to be used as skinning templates to guide people for their own skinning, so this type of thing will be available in time - but I can't say when.

    I realise that's not particularly helpful, but if you have specific questions about particular approaches to doing something then please consider posting the questions on the degrafa google group (in addition to posting here as well if you want) as it may get more visibility from current degrafa users, and it will be easier for us to incorporate the solution into a future sample/tutorial, or a collection of best practices.

    -Degrafa

    asawilliams : Thanks for the info, I am looking forward to those themed examples, I think it will really help the community
    Sophistifunk : Not much I can add to Greg's reply, but my work in progress skin is available here: http://code.google.com/p/tickertape/ We're floating around the toobs if you've any specific questions, or queries about skinning a particular component.

Issues accessing an HTML table within a Repeater

Very simple scenario: I have a Repeater with a table spanning its Header, Item, and Footer Templates. Because it spans templates, I cannot simply do <table id="Blah" runat="server"> and then access it via FindControl.

Is there any way to overcome this?

EDIT: The goal is to be able to retrieve the HtmlTable then pass it into another method which parses over it, converting it to excel xml.

From stackoverflow
  • In short, no. By turning it into a server control (with runat=server) you can't make it span templates. Why do you need to get to the table element?

    Habaabiai : To pass it elsewhere (just edited this in, see above). I'm currently doing the same with GridViews, passing the entire GridView to an excel export function. Switched to repeaters because they gave us better performance and easier integration with our custom ajax.
  • I was approaching the problem incorrectly. I should have been trying to pass the Repeater, not the HtmlTable. After changing methods, I was able to accomplish my goal and can now export the Repeater contents as XML.

asp.net 3.5 + update panel doesn't work in mozilla

Hi,

I show/hide few images basing on the button clicks in update panel. I use an update progress also for this. Everything works fine in IE7. But in Firefox Version 3.0.14 when I click on the button in the update panel the event itself is not getting fired.

What may be the problem?

From stackoverflow
  • I dont think there is any reason for it to work in IE and not in FF. What plugins you have installed on Firefox? Disable all plugins and then check.

    Sunny : Even after disabling the plugins I am getting the same problem
    Mahin : Does Tools->Error Console shows you any error ?
  • Check for JavaScript errors.

  • I found the issue. This is because, I didn't set the CausesValidation property to false. I need this because there are usercontrols which performs their own validations.

    But now, I am wondering why IE allowed the button click?

How to get current localtime using Mysql and PHP?

I read from mysql website, I execute this:

SELECT CURTIME()

But then how to get the value? Using mysql_fetch_assoc()??

From stackoverflow
  • SELECT CURTIME() as time_now
    

    *EDIT

    $conn = mysql_connect("localhost", "mysql_user", "mysql_password");
    $sql = "SELECT CURTIME() as time_now";
    $result = mysql_query($sql);
    while ($row = mysql_fetch_assoc($result)) {
        echo $row["time_now"];
    }
    
    xiasue1982 : how to get the result??
    halocursed : Are you using classes? if not check greg's answer
  • Yes, you execute it as a normal query. You might want to alias the column to a nicer name:

    $data = mysql_query('SELECT CURTIME() AS the_time');
    $row = mysql_fetch_assoc($data);
    $theTime = $row['the_time'];
    

    It's going to be more efficient to get the time through PHP rather than doing an expensive SQL query.

    You can use the date() function:

    $theTime = date('H:i:s');
    

how to read data from xml file

<?xml version="1.0" encoding="utf-8" ?> 
<user>
  <username>prince</username> 
  <password>user1</password> 
</user>

This is my xml file name as user.xml.

Now when i click the button in the page, i need to get the data from that file and place that data in variable like:

string strusername =  data  cmg from  xml file (prince)
string strPassword =  data  cmg from  xml file (password)

Can anyone tell me how to do this with syntax?

thank you

From stackoverflow
  • LINQ to XML is the modern way to do what you want, see here

     XDocument xDoc = XDocument.Load("user.xml");
     string strusername =  xDoc.Descendants(XName.Get("username")).First().Value;
     string strPassword = xDoc.Descendants(XName.Get("password")).First().Value;
    
    Jon Skeet : Any reason for using XName.Get instead of just using the implicit conversion from string? `Descendants("username")`...
    ArsenMkrt : Descendants doesn't have version that take string as an argument, isn't it?
    marc_s : Works great, if you're on .NET 3.5 and up - use XmlDocument on .NET 3.0 and below
    prince23 : thank you ArsenMkrt
  • You could try something like the XmlReader, XmlTextReader and XmlDocument. They are all relatively straight forward to use.

What's the appropriate Unicode character to flag users on the website?

I run a quiz-like website at slagalica.tv (content is not in English). We often have users that try to cheat the system, so we flag those accounts and they get special treatment. Now I'd like to add some character beside their name to be visible everywhere across the website, so that everyone knows those accounts are flagged.

I'm currently considering to use the "dagger" character

http://en.wikipedia.org/wiki/Dagger_(typography)

which is used for different purposes in different domains. But I fear that I do not know about some cool Unicode character that would fit this purpose better.

Any ideas?

From stackoverflow
  • What about Skull & CrossBones?

    Some other possibles at: http://www.alanwood.net/unicode/miscellaneous_symbols.html

    Wez : Good call hehe! Also add a ALT tag to the symbol so they see an informative tooltip what it means.
    Milan Babuškov : How do I add ALT tag to text?
    Matt Lacey : ALT only applies to images. Wrap it in a span with a title to get the tooltip effect.

Caching stream in c#

I have a bunch of files that are being read by another bunch of threads. Some parts of files get read multiple times using multiple file opens. I'd like to have a sort of caching file stream.

If part of the file was read before, all subsequent reads would come from cache, otherwise file part would be read and content added to cache.

Files do not change, so there is no need to invalidate cache.

Is anyone aware of such class being available somewhere or similar mechanism that would help with such problem?

From stackoverflow
  • If the file size is small you can use shared MemoryStream object to cache the file streams. But am not sure about caching the part of a file and identifying the part of a file from cache.

    You can cache the whole file in a memorystream and you can use it whenever needed. And you can identify this using the filename as a key. For this you have to maintain a list or dictionary kind of structure to store filename (key) - binarystream(value) pairs.

    these below links discussed the same topics. have a look

    hope this helps

    Cheers

    Ramesh Vel

    bh213 : Files are rather big and I'd like to partially cache them.

What are the scan codes for:

What are the scan codes for:

PageUp PageDown

Up Arrow Down Arrow

Space Bar

From stackoverflow
  • Javascript Char Codes (Key Codes)

    Key Pressed     Javascript Key Code
    backspace   8
    tab     9
    enter   13
    shift   16
    ctrl    17
    alt     18
    pause/break     19
    caps lock   20
    escape  27
    page up     33
    page down   34
    end     35
    home    36
    left arrow  37
    up arrow    38
    right arrow     39
    down arrow  40
    insert  45
    delete  46
    0   48
    1   49
    2   50
    3   51
    4   52
    5   53
    6   54
    7   55
    8   56
    9   57
    a   65
    b   66
    c   67
    d   68
    e   69
    f   70
    g   71
    h   72
    i   73
    j   74
    k   75
    l   76
    m   77
    n   78
    o   79
    p   80
    q   81
    r   82
    s   83
    t   84
    u   85
    v   86
    w   87
    x   88
    y   89
    z   90
    left window key     91
    right window key    92
    select key  93
    numpad 0    96
    numpad 1    97
    numpad 2    98
    numpad 3    99
    numpad 4    100
    numpad 5    101
    numpad 6    102
    numpad 7    103
    numpad 8    104
    numpad 9    105
    multiply    106
    add     107
    subtract    109
    decimal point   110
    divide  111
    f1  112
    f2  113
    f3  114
    f4  115
    f5  116
    f6  117
    f7  118
    f8  119
    f9  120
    f10     121
    f11     122
    f12     123
    num lock    144
    scroll lock     145
    semi-colon  186
    equal sign  187
    comma   188
    dash    189
    period  190
    forward slash   191
    grave accent    192
    open bracket    219
    back slash  220
    close braket    221
    single quote    222
    
  • ASCII Table

GWT - ListBox - pre-selecting an item

Hey there Stackoverflow,

I got a doubt regarding pre-selecting(setSelectedIndex(index)) an item in a ListBox, Im using Spring + GWT.

I got a dialog that contains a painel, this panel has a flexpanel, in which I've put a couple ListBox, this are filled up with data from my database.

But this painel is for updates of an entity in my database, thus I wanted it to pre-select the current properties for this items, alowing the user to change at will.

I do the filling up in the update method of the widget.

I tried setting the selectedItem in the update method, but it gives me an null error.

I've searched a few places and it seems that the listbox are only filled at the exact moment of the display. Thus pre-selecting would be impossible.

I thought about some event, that is fired when the page is displayed.

onLoad() doesnt work..

Anyone have something to help me out in here?

Thx in advance,

Rodrigo Dellacqua

From stackoverflow
  • I really think you can set the selection before it's attached and displayed, but you have to have added the data before you can select an index. If this is a single select box you could write something like this:

    void updateListContent(MyDataObject selected, List<MyDataObject> list){
         for(MyDataObject anObject : list){
              theListBox.addItem(anObject.getTextToDisplay(), anObjec.getKeyValueForList());
         }
         theListBox.setSelectedIndex(list.indexOf(selected));
    }
    

    if this is a multiple select box something like this may work:

    void updateListContent(List<MyDataObject> allSelected, List<MyDataObject> list){
         for(MyDataObject anObject : list){
              theMultipleListBox.addItem(anObject.getTextToDisplay(), anObjec.getKeyValueForList());
         }
         for(MyDataObject selected : allSelected){
             theMultipleListBox.setItemSelected(list.indexOf(selected), true);
         }
    }
    

    (Note I haven't actually compiled this, so there might be typos. And this assumes that the selected element(s) is really present in the list of possible values, so if you cant be sure of this you'll need to add some bounds checking.)

  • I've been happily setting both the values and the selection index prior to attachment so as far as I'm aware it should work. There's a bug however when setting the selected index to -1 on IE, see http://code.google.com/p/google-web-toolkit/issues/detail?id=2689.

ASCII "graphics" library?

Is there a platform-independent C/C++ library that can draw simple "graphics" in pure ASCII in a console program? For example (VERY roughly) I could call a function in the library like rectangle(3, 6); to get the following output:

******
*    *
******

Ultimately, I would love to be able to plot simple graphs based on input data tables like:

|
|*
|
|  *
|     *
|         *
|                *
|                           *
+---------------------------------

And does anyone know if there is a way to specifically render data plots/graphs in ASCII or UTF8?

From stackoverflow
  • I don't know if its exactly what you're searching for, but this library will render images and viedos to the console.

    http://aa-project.sourceforge.net/aalib/

  • In addition to aalib there is also libcaca (this one will render in full color)

  • From what you have said, you don't need ASCII graphics library as they purpose is to render bitmap into ASCII characters so the look of ASCII data will become 'similar' to the bitmap. For the task you have mentioned consider writing your own library, because:

    1. Your task is not really bitmap rendering
    2. It is not so complicated

    If you really want to use ASCII art lib, you may choose a library for graph bitmap rendering and then pass that generated bitmap data to ASCII lib so you will get the output.

  • I suppose you can use curses (and derivatives like ncurses).

How to redirect request a.com/script.pl to server b.com, but avoid touching a.com server?

Hi! My site is hosted on a virtual hosting server - "Alpha". Also I host a web-service at Alpha. The service is a perl script and it works slow. There are a lot of clients that access the script. That makes the site work slow or even crash.

To solve the problem, I have transferred the service to a dedicated server - "Beta". Now there is a .htaccess redirect on "Alpha" that redirects service requests to "Beta"

Redirect /cgi-bin/weather/server/index.pl http://server.webhop.org/cgi-bin/weather/server/index.pl

However all the service requests go through "Alpha" and that seems to make the site work slow anyway.

Do you know how to redirect requests to alpha.com/cgi-bin/weather/server/index.pl to beta.com/cgi-bin/weather/server/index.pl avoiding requests to alpha.com server?

I know this would be easy to achieve with subdomains, but I cannot change the code on clients that all request to alpha.com/cgi-bin/weather/server/index.pl

My domain name is parked at godaddy.com.

From stackoverflow
  • Short answer: No.

    Only the first part of the URL (alpha.com) is used to determine where requests are sent to. The remainder of the URL is interpreted by the server that receives the request. So the minimal impact way of redirecting clients (without making changes on the client) appears to be exactly what you're doing - a redirect from alpha.com.

    Edit

    Alternate answer - get another server to act as a proxy for alpha.com, and forward the requests to the alpha and beta servers (and don't expose them to the net at all)

    Pavel : Thank you very much! I will be using the alternative way.

How do I create a Mac installer for my Java application?

I have created an executable JAR file for my Java application. If I double-click then it works fine. But I want to create installer for Mac OS, because I cannot give a JAR file to my users. Any suggestions?

From stackoverflow
  • I'd agree that a jar should be sufficent; but maybe you want to check this (ClickInstall MacOSX 1.0.2) Installer Build Tool for OSX.

  • The very first hit on Google for "Mac Installer" is the Wikipedia article about the Mac Installer.

    You can click through from there to read Apple's Software Delivery Guide. It tells you in exhaustive detail everything you could possibly want to know about this.

    Please, for your own good, read up on How To Ask Questions The Smart Way. You'll get much better results that way.

  • Well, all you have to do here is to create a beautiful icon for your app, bundle it to your jar file to make it look more sophisticated, instead of using the default coffee cup icon.

    Here is how you can do it:

    http://www.centerkey.com/mac/java/

    Please read the sessions starting from session 7.

    Mac has java by default. And if your users are not technical, it makes no different for them if they are using a mac .exe or not, right?

  • Just a comment to clear some of this up. Mac applications normally dont have installers. At all. They dont have a registry and normally you just drag the icon (which is actually a folder with the executables in a specific folder structure) into the applications folder. Thats it. Thats why if you have an executable with a nice icon and you put it in a .dmg image file nobody is gonna know the difference.

  • Try jarbundler from http://informagen.com/JarBundler/. You can create a nice OSX app including icon with it. Just ship that. The user can drag this app to Application. No explicit installation step necessary.

    I use this for my projects.

Static dataset in ASP.NET

Will declaring a dataset as STATIC in ASP.net website help in persisting data across post backs?

I was looking at an application and somehow a static dataset was able to persist the data even if we closed the application and opened it again.

From stackoverflow
  • Yes, it can. static variables are stored in server memory. Note that they are shared among all users (like Application state) and it might require a locking mechanism to ensure thread safety.

    Note that it will be gone if the application ends.

  • yes, but try to use Application object like

    Application.Add("yourDS",Dataset);
    

    Note: When your application restart application object lose data.

  • I strongly recommend you to avoid using any global objects in ASP.NET application (of course there are exceptions, like Cache). You will always have to deal with concurrency while updating this DataSet and additionally, you'll make a lot of your modules dependent on single data structure.

Why is the output of cout << 7/9*9; is zero?

Why is the output of the following code equals to 0 or serven?

cout << 7/9*9;   //output 0 (zero)   why?

float nine = 9;
float seven = 7;
float i = seven/nine*nine;
cout << i     //output 7   Why?

Thanks for the help.

From stackoverflow
  • 7/9*9 evaluates those numbers as integers, so 7/9 evaluates to 0, and 0*9 = 0.

    When you made them floats, you were performing the intended calculation.

    Try 7.0/9*9 to get 7, and then you'll be doing a floating point operation.

    Kai : Haha! Its awesome how the super simple questions become a sniping contest. Well explained though.
    Matt : wow, 11 upvotes in 1 min
    Jacob : I know .. haha, pays to check out SO when you're wrestling with a bug :D
    Hao : too bad for programmers in the other part of the world (asia), we can't catch up with sniping low-hanging-fruit questions :-)
    Jacob : Haha, well put :)
  • In C, when you divide integers, the remainder gets discarded. Here, you're doing 7 / 9, then taking the result of that and multiplying by 9. In steps, heres what C thinks:

    7 / 9 = 0
    0 * 9 = 0
    

    When you use floats it works properly because the remainder is no longer discarded.

    Steve314 : Strictly, with floats, there's still a discarded remainder. IOW there's a roundoff error. Pedantically, division is the inverse of multiplication, which isn't possible for all integers or all floats. By definition, approx-quotient + (remainder * divisor) = dividend, where approx-quotient means the result from the division algorithm. There is a remainder with floating point and fixed point division as well as integers - though hardly anyone cares about its exact value, so don't expect an operator for it.
    Kai : Thanks for mentioning that Steve! Small fast responses tend to miss subtle but important details like that.
  • 7/9*9 equals (7 / 9) * 9, but as 7 and 9 are integers and not floating point numbers, 7 / 9 equals 0 (the quotient of the division).

  • In:

    cout << 7 / 9 * 9;
    

    you are doing integer arithmetic. So 7/9 is 0 and 0*9 is 0.

    To use floating point arithmetic (which is what you are using in your second example), you want to do:

    cout << 7.0 / 9 * 9;
    
  • I think it's a precision issue. The / and * operators are equal precedence, so 7/9*9 is evaluated left to right at as (7/9)*9. The catch is that (7/9) is 0 in integer arithmetic. When you explicity store them as floats, that / operation is done in floating point, which can store 7/9 with greater precision than an int.

    If you want to do the calculation in one line without the precision issue, try:

    cout << 7.0f / 9.0f * 9.0f;

  • Many correct answers already. An addition note: if you want to leave this as an integer operation and not use floating point, you want to order it so you do multiplies before divides to get the most precision (as long as overflow doesn't occur during multiplication. Thus rather than (7.0/9)*9 which will convert to floats, you can do (9*7)/9.

ContentType is application/pdf but it still generates Excel sheet

I am using the following code to generate a PDF document from a JSP, but it generates an Excel sheet.

<%@ page buffer="7024kb" %>
<%@ page contentType="application/pdf"%>
<%
  String reportType=request.getParameter("reportType");
  String fileName=reportType;
  response.addHeader("Content-disposition", "attachment; filename="+fileName);
%>
<%= request.getParameter("file") %>

Can you tell me why this is happening? How can I rectify this?

From stackoverflow
  • Delivering a file from a Servlet rather than a JSP is a much easier approach.

    Get your PDF into a byte array and then you can do something like this:

    Servlet Code:

    byte[] pdf = PDFObject.getBytes(); // You may need to use a ByteArrayOutputstream or similar depending on the PDF Object
    
    out.write(pdf, 0, pdf.length);
    

    You can add your output headers to the HttpServletResponse as usual.

    But as its delivering as an Excel/CSV sheet rather than a PDF are you sure that your object is actually a PDF? are the contents readable in Excel?