Tuesday, May 3, 2011

exporting tables to excel sheet in jsp

how can i export my table to excel sheet in jsp??

From stackoverflow
  • The easiest way would be to create a HTML table and send this HTML with the following response headers:

    Content-type = application/vnd.ms-excel
    Content-disposition = attachment;filename=whateverIsAppropriate.xls
    

    Another option would be to create the Excel using Apache POI and then send that as the response.

How to prevent HTML encoding for embedded expressions in XML Literals (VB.NET)?

With the following code:

Dim x As System.Xml.Linq.XElement = _
<div>
<%= message.ToString() %>
</div>
Dim m = x.ToString()

...if message is HTML, then the < and > characters get converted to &lt; and &rt;.

How can I force it to skip this encoding?

From stackoverflow
  • You need to open the HTML snippit as an XML document and append the document node to the Div node you are creating.

    If you want to add XML (or HTML) to an existing XML document then you have to add it as XML and not as text (cause that gets encoded).

  • What is the type of your message variable? If message is an XElement, then just leave off the .ToString call like this:

    Dim x As System.Xml.Linq.XElement = _
        <div>
            <%= message %>
        </div>
    Dim m = x.ToString()
    

    If message is some other type (like StringBuilder), then do this:

    Dim x As System.Xml.Linq.XElement = _
        <div>
            <%= XElement.Parse(message.ToString()) %>
        </div>
    Dim m = x.ToString()
    

In MySQL caculating offset for a time zone

Is there a way in mysql to calculate the offset for any timezone. For example to get the local time in the time zone 'Asia/calcutta' what i want to do is calculate the offset for this time zone and add that offset to GMT to get the local time.

From stackoverflow
  • DATEDIFF(NOW(), UTC_TIMESTAMP())

    Cheers,
    Eric

  • The offset will depend on the time that you're interested in - for instance, I'd currently have an offset of one hour from UTC, but during the winter my offset would be zero.

    Judging by the docs page on MySQL time zone support, you want to use the convert_tz function. If you're trying to convert UTC to local time, pass in "Etc/GMT+0" as the "from" time zone, and "Asia/Calcutta" as the "to".

  • SET time_zone = '-07:00';

    You can just pass in an offset

    http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html

creating video file

How would I create an class that records the users interactions with the desktop. and it should convert it to a video format such as wmv file?

From stackoverflow

Is there any way to programmatically determine in C/C++ how many parameters a Lua function expects?

Is there a way to determine how many parameters a Lua function takes just before calling it from C/C++ code?

I looked at lua_Debug and lua_getinfo but they don't appear to provide what I need.

It may seem a bit like I am going against the spirit of Lua but I really want to bullet proof the interface that I have between Lua and C++. When a C++ function is called from Lua code the interface verifies that Lua has supplied the correct number of arguments and the type of each argument is correct. If a problem is found with the arguments a lua_error is issued.

I'd like to have similar error checking the other way around. When C++ calls a Lua function it should at least check that the Lua function doesn't declare more parameters than are necessary.

From stackoverflow
  • What you're asking for isn't possible in Lua.

    You can define a Lua function with a set of arguments like this:

    function f(a, b, c)
       body
    end
    

    However, Lua imposes no restrictions on the number of arguments you pass to this function.

    This is valid:

    f(1,2,3,4,5)
    

    The extra parameters are ignored.

    This is also valid:

    f(1)
    

    The remaining arguments are assigned 'nil'.

    Finally, you can defined a function that takes a variable number of arguments:

    function f(a, ...)
    

    At which point you can pass any number of arguments to the function.

    See section 2.5.9 of the Lua reference manual.

    The best you can do here is to add checks to your Lua functions to verify you receive the arguments you expect.

    Ashley Davis : Well I did say I know what I am doing is not in the spirit of Lua :) With functions implemented and called entirely within Lua it will work the way you say, however what I want is a way to robustify the Lua/C++ interface. When you implement a C++ interface using Lua functions (using our custom Lua/C++ binding system) it makes sense to automatically enforce that the Lua functions that are being called from C++ implement the correct number of arguments. That said I suspect that it isn't possible to do what I want. Thought I'd ask all the same!
  • No, not within standard Lua. And is Aaron Saarela is saying, it is somewhat outside the spirit of Lua as I understand it. The Lua way would be to make sure that the function itself treats nil as a sensible default (or converts it to a sensible default with something like name = name or "Bruce" before its first use) or if there is no sensible default the function should either throw an error or return a failure (if not name then error"Name required" end is a common idiom for the former, and if not name then return nil, "name required" end is a common idiom for the latter). By making the Lua side responsible for its own argument checks, you get that benefit regardless of whether the function is called from Lua or C.

    That said, it is possible that your modules could maintain an attribute table indexed by function that contains the info you need to know. It would require maintenance, of course. It is also possible that MetaLua could be used to add some syntax sugar to create the table directly from function declarations at compile time. Before calling the Lua function, you would use it directly to look up any available attributes and use them to validate the call.

    If you are concerned about bullet-proofing, you might want to control the function environment to use some care with what (if any) globals are available to the Lua side, and use lua_pcall() rather than lua_call() so that you catch any thrown errors.

  • I wouldn't do this on the Lua side unless you're in full control of Lua code you're validating. It is rather common for Lua functions to ignore extra arguments simply by omitting them.

    One example is when we do not want to implement some methods, and use a stub function:

    function do_nothing() end
    
    full_api = {}
    function full_api:callback(a1, a2) print(a1, a2) end
    
    lazy_impl = {}
    lazy_impl.callback = do_nothing
    

    This allows to save typing (and a bit of performance) by reusing available functions.

    If you still want to do function argument validation, you have to statically analyze the code. One tool to do this is Metalua.

    Ashley Davis : Thanks. I am going to take a look at metalua. Static analysis of the Lua code might actually be better in my case than trying to do the checking at runtime.
    Alexander Gladysh : You're welcome. If you do so, please drop a line to Metalua's mailing list (http://lists.luaforge.net/mailman/listinfo/metalua-list). It is likely that you'll get some valuable advice from Metalua author.
  • The information you ask for is not available in all cases. For example, a Lua function might actually be implemented in C as a lua_CFunction. From Lua code there is no way to distinguish a pure Lua function from a lua_CFunction. And in the case of a lua_CFunction, the number of parameters is not exposed at all, since it's entirely dependent on the way the function is implemented.

    On the other hand, what you can do is provide a system for functions writers (be it in pure Lua or in C) to advertise how many parameters their functions expect. After creating the function (function f(a, b, c) end) they would simply pass it to a global function (register(f, 3)). You would then be able to retrieve that information from your C++ code, and if the function didn't advertise its parameters then fallback to what you have now. With such a system you could even advertise the type expected by the parameters.

    Ashley Davis : You made some good points. Although the system you propose in the 2nd paragraph is just as open to human error as the default case, eg in the normal case you have to rely on the coder to get the arguments right, in the second case the coder needs to get right both the arguments and the argument-metadata.

breaking a running emacs lisp program

I'm having a problem with an emacs lisp package that I pulled down from the ubuntu distribution. The package is JDEE, and it complains of 'Args out of range: "63", 0, 4' in the mini buffer and the Messages buffer whenever I open a file. This bug appears to have been reported last September but no action has been taken. I'm not an emacs newbie, having written some elisp code myself, but I've never attempted to debug anything like this. I would like to stop the file load in a debugger when this error happens to at least get an idea of where the problem is coming from. I've read section 18.1.1 of the elisp manual on "Entering the debugger on error" but trying to load the file after playing with various combinations of values for debug-on-error, debug-ignored-errors, and debug-on-signal appears to have no effect. Has anybody got any suggestions for my next step?

From stackoverflow
  • If debug-on-error isn't working, I'd start with the source itself. Find the keybinding/event that is causing the problem, and locate the function.

    C-h k <keystrokes>
    M-x find-function <function-name-from-above>
    

    Now, once you are at the source

    M-x edebug-defun
    

    And the next time you hit the key, you should be able to step through the program. At that point, you can see which portion causes an error - and drill down that way.

    You can also try setting the variable 'stack-trace-on-error to see if you can find the culprit (though 'debug-on-error usually works for me, not sure why it doesn't for you).

    As a last resort (if edebug-defun doesn't work), you can redefine the routine with a call to (debug) in it, sort of does the same.

  • I suppose JDEE is somehow inhibiting debug-on-error. Perhaps grep through its files for the error message "Args out of range". While debugging, make sure to load the uncompiled .el files, not the byte-compiled .elc files (you will notice it in the debugger if you are running byte-compiled code) by entering commands like (load "foo.el") instead of (load "foo").

sql query for string contains in C#

how to write sql query to do String contains operation.?

Consider,

string strTest = "Hash.System.Data.DataSet has.ds";
string str1 = "Hash.System.Data.DataSet has(System.Collections.Hashtable, Int32).ds";
string str2 = "Hash.System.Data.DataSet has(System.Collections.Hashtable, System.Collections.Hashtable).ds";

Here 1)if i compare strTest with str1 it should return true. 2)if i compare strTest with str2 it should return true.

i.e i can ignore the part of string which is enclosed within '(' and ')'.

edit: i'm trying to access MS access table using C# and need to check such conditions.

i need to check everything in 'strTest' excluding the part of string contained in brackets with str1 and str2.

str1 and str2 are entries in MS access table.

myCommand1.CommandText = "SELECT TableName FROM HashTableConfig WHERE ItemIdentity LIKE '" + strTest + "'";

This is the query where i should do changes so that it satisfies condition 1 and 2. ItemIdentity can have values like str1 and str2.

From stackoverflow
  • field LIKE 'Hash.System.Data.DataSet has(%).ds'