Select Value between two column from datatable

I have a datatable. I need to fetch a certain column value based on the user input. For example, lets say the datatable has three column intpkdata,intFrom,intTo
Here is my some code,

                drCurrentRow = dtCurrentTable.NewRow();
                drCurrentRow["intpkdata"] = new Random().Next(0, 99999).ToString();
                drCurrentRow["intFrom"] = txtFrom.Text;
                drCurrentRow["intTo"] = txtTo.Text;

                dtCurrentTable.Rows.Add(drCurrentRow);
                ViewState["Pcidata"] = dtCurrentTable;
                gdvpciData.DataSource = dtCurrentTable;
                gdvpciData.DataBind();

Requirement :

if intFrom/intTo data is already exist in datatable then msg should come.Pleas see the image for records

enter image description here

LINQ “Where” condition -> change value of property

I have a list of meetings inside which I have another list of attendees.

Model similar to this –

public class Meeting
    {
        public string Id { get; set; }
        public string Title { get; set; }
        public List Users { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
    }

I have list of Meeting

List meetings = GetMeetings();

Now I want to mask the Title of the meetings where one of the users is bot@domain.com. I can achieve this in multiple LINQ queries but I am looking for optimized LINQ query..

Can anyone help me with this?

What I tried –

var maskedMeetings = meetings.Where(x = x.Users.Any(a => a.Email.Equals("bot@domain.com"))); 

meetings = appointments.Except(maskedMeetings).ToList();

maskedMeetings = maskedMeetings.Select(x => { x.Title = "Bot"; return x; }).ToList();

meetings = meetings.Concat(maskedMeetings).ToList();

Can anyone help me with optimized way of writing this query?

Rahul.

How can I write a LINQ query which will coalesce column values in a DataTable into a comma delimited string?

I have a DataTable in a VB.Net application.

I would like to come up with a LINQ expression which would allow me
for a give column, take that column value from each row in the DataTable
and coalesce it into a comma separated string.

Consider a DataTable with rows that look like:

RowID  Value
============
1      A
2      B
3      C
4      D
5      E
6      F

The desire result “A,B,C,D,E,F”

I know I could iterate over the rows to create this result.
My question is,

Can I do this with a simple LINQ query?

Thanks,
JohnB

init function invocation of drivers compiled into kernel

In Linux if device drivers are built as loadable kernel modules, then upon inserting the device driver kernel module, the kernel calls the init function of the device driver as pointed out by module_init() macro.

How does this work for device drivers that are statically compiled into the kernel ? How is their init function called ?

How do I generate loadable modules during Linux kernel build?

I seem to successfully build a kernel image, but I can not generate all the modules I expect. I expect more modules since I see them enabled in the gconfig window. Here is a copy of my make session. Seems like make goes into the devices directories. I can not figure out why it is not create the .ko files. I expect to see .ko files. I have checked the Makefile in /drivers directory, and I can see that it is configured with a number of lines like

obj-$(CONFIG_PCI)               += pci/

Which directs make to build the pci module for instance. I think this implies that I should see a number .ko files. But I do not. I have seen just one .ko file for scsi module. I like to be able to build all of modules selected.

I also verified that a number of mudules are enabled when I issued:

make VARIANT_DEFCONFIG=msm8974_sec_hlte_spr_defconfig msm8974_sec_defconfig SELINUX_DEFCONFIG=selinux_defconfig gconfig

But as I said, I do not see any of them. What am I missing please?

@Subin – Thanks. I just tried make modules_install. I have to mention that I am cross compiling this for an arm target. I believe modules_install is for the purpose of installing the driver for the machine you are on? I got a message about needing to be in root, and I did not proceed. I have been wondering when I need to run it. What does it do exactly please?

Re: the make modules; I have run it before. I’ll run it again and post the result. Since I got one .ko file I figured the issue is something different between that one module, and every other one enabled in my config. Here is what I got when I ran make modules:

sansari@ubuntu:~/WORKING_DIRECTORY$ make modules
CHK     include/linux/version.h
CHK     include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
CALL    scripts/checksyscalls.sh
Building modules, stage 2.
MODPOST 1 modules

Re: your comment on the location of .ko files, I am doing a find to see if perhaps I am not looking at the right place, it only finds the one which was built. Not the other ones. Here is the output:

sansari@ubuntu:~/WORKING_DIRECTORY$ find . -type f -name "*.ko"
./drivers/scsi/scsi_wait_scan.ko
sansari@ubuntu:~/WORKING_DIRECTORY$ 

Should I perhaps run make v=1, in verbose mode that is? Would that provide more information on why the other modules are not built?

@Gil Hamilton – Thanks. You are right. Here is an excerpt of the .config file:

#
# SCSI support type (disk, tape, CD-ROM)
#
CONFIG_BLK_DEV_SD=y
# CONFIG_CHR_DEV_ST is not set
# CONFIG_CHR_DEV_OSST is not set
# CONFIG_BLK_DEV_SR is not set
CONFIG_CHR_DEV_SG=y
CONFIG_CHR_DEV_SCH=y
CONFIG_SCSI_MULTI_LUN=y
CONFIG_SCSI_CONSTANTS=y
CONFIG_SCSI_LOGGING=y
CONFIG_SCSI_SCAN_ASYNC=y
CONFIG_SCSI_WAIT_SCAN=m

This entry is the only one set to ‘m’.

Insert linux kernel module statically

When building the Linux kernel from sources one could decide if a certain functioninality is statically build into the kernel or packed into a module for dynamic insertion by .config.

If on the other hand I have sources for any 3rd party module, like for example a packaged device driver, is it possible to programatically integrate this code into the kernel statically instead?

buildroot using external toolchain – rootfilesystem creating

I am trying to build my own rootfile system for RPI using buildroot.
I am new to buildroot.

I have downloaded following cross compiler folder from git :–
https://github.com/raspberrypi/tools/tree/master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian
as mentioned in this link :–
http://hertaville.com/2012/09/28/development-environment-raspberry-pi-cross-compiler/

How i will come to know what is the kernel header is used by above cross compiler ?

My installer GCC compiler is :–
arm-linux-gnueabihf-gcc

crosscompiler is downloaded from git at following location:–
~/home/gcc-linaro-arm-linux-gnueabihf-raspbian

Please suggest what value to fill here for toolchain selection :–

Toolchain type : External toolchain
Toolchain : Custom toolchain
Toolchain origin : Pre-installed toolchain
Toolchain path : ?
Toolchain prefix : ?
external Toolchain kernel header series : ?
external toolchain c library : ?

Cross compiler not finding SDL package

i am cross compiling a small application which uses libsdl (SDL). I can compile using gcc but not able to with cross compiler. the cross compiler i am using is arm-arago-linux-gnueabi-gcc. error message come as

/arm-arago-linux-gnueabi/bin/ld: cannot find -lSDL
although libsdl1.2-dev is installed an i am getting pkg-config –cflags sdl output as -D_GNU_SOURCE=1 -D_REENTRANT -I/usr/include/SDL
and output of pkg-config –libs sdl as -lSDL.
Since my native compiler gcc is detecting SDL libs any idea why my cross compiler not able to find the libraries

Why does std::forward return static_cast and not static_cast?

Let’s have a function called Y that overloads:

void Y(int& lvalue)
{ cout << "lvalue!" << endl; }

void Y(int&& rvalue)
{ cout << "rvalue!" << endl; }

Now, let's define a template function that acts like std::forward

template
void f(T&& x)
{
   Y( static_cast(x) );   // Using static_cast(x) like in std::forward
}

Now look at the main()

int main()
{
   int i = 10;

   f(i);       // lvalue >> T = int&
   f(10);      // rvalue >> T = int&&
}

As expected, the output is

lvalue!
rvalue!

Now come back to the template function f() and replace static_cast(x) with static_cast(x). Let's see the output:

lvalue!
rvalue!

It's the same! Why? If they are the same, then why std::forward<> returns a cast from x to T&&?

Refactoring with C++ 11

Given the new toolset provided by c++ lots of programmers, aiming at code simplification, expressiveness, efficiency, skim through their old code and make tweaks (some pointless, some successful) to achieve their goals. Whilst trying not to loose too much time on such labors and just make non intrusive and self contained changes, what are the best practices?

Let me cross out the obvious :

  • Use auto to run iterator based loops :

    for (std::vector::const_iterator it(lala.begin()), ite(lala.end()); it != ite;     
    ++it);
    // becomes
    for (auto it(lala.cbegin()), ite(lala.cend()); it != ite; ++it);
    
  • Use tie for multiple assignments that just produce C-style rows of code ( how to assign multiple values into a struct at once? )

    a = 1;
    b = 2; 
    c = 3;
    d = 4; 
    e = 5;
    // becomes
    std::tie(a, b, c, d, e) = std::make_tuple(1, 2, 3, 4, 5);
    
  • To make a class non inheritable just declare it as “final” and delete the code that achieved such a behavior http://www.parashift.com/c++-faq/final-classes.html

  • Use the delete keyword to explicitly hide constructors/destructors instead of declaring them private (eg code to create heap based objects, non copyable objects etc)

  • Turn trivial functors created just to facillitate the execution of a single STL algorithm into lambda functions (apart from reducing code cluttering you’ll have guaranteed inlined calls)

  • Simplify RAII wrapping of an object by just using a smart pointer

  • Get rid of bind1st, bind2nd and just use bind

  • Replace hand written code for type traits (Is_ptr_but_dont_call_for_const_ptrs<> and such 🙂 ) with standard code provided by < type_traits >

  • Stop including boost headers for functionallity now implented in STL (BOOST_STATIC_ASSERT vs static_assert)

  • Provide move semantics to classes (although this wouldn’t qualify as a dirty/quick/easy change)

  • Use nullptr where possible instead of the NULL macro and get rid of the code that filled containers of pointers with 0’s casted to object type

    std::vector f(23);
    for (std::size_t i(0); i < 23; ++i)
    { f[i] = static_cast(0); }
    // becomes
    std::vector f(23, nullptr);
    
  • Clear the vector data accessing syntax

    std::vector vec;
    &vec[0];    // access data as a C-style array
    vec.data(); // new way of saying the above
    
  • Replace throw() with noexcept (apart from avoiding the deprecated exception specifiation you get some speed benefits http://channel9.msdn.com/Events/GoingNative/2013/An-Effective-Cpp11-14-Sampler @ 00.29.42)

    void some_func() noexcept; // more  optimization options
    void some_func() throw();  // fewer optimization options
    void some_func() ;         // fewer optimization options
    
  • Replace code where you’d push a tempory in a container and hoped that the optimizer would ellide the copy away, with an “emplace” function where available, in order to perfectly forward the argument and construct directly an object into a container without temporary at all.

    vecOfPoints.push_back(Point(x,y,z)); // so '03
    vecOfPoints.emplace_back(x, y, z);   // no copy or move operations performed
    

UPDATE

The answer by Shafik Yaghmour was rightfully awarded the bounty for having the greatest acceptance by the audience.

The answer by R Sahu was my accepted one, because the combination of features it proposes captures the spirit of refactoring : making code clearer and cleaner and simpler and elegant.

Passing derived class to base function

I’m having trouble passing a derived class to a function which accepts the base class as argument. The base class is consists of “obstacles” which are to be placed on a “board” void Board::setvalue(int length, int width, Obstacle& obstacle);

However, this causes the compiler to give the “no known conversion for argument…”-error. Reading up around the site i found that i should be passing the derived object as a const, this however causes problems because a const can’t be assigned to the board (since it holds pointers to non-const Obstacles).
In turn, changing Board to hold const Obstacles causes a lot of issues elsewhere in the project, especially with the operator<< of Board and Obstacle.
I have tried passing the objects as consts and then using Obstacle ob = new obstacle(the const obstacle) but this made them generic Obstacle objects rather than Player/Barrel/Wall objects.

Is there any way to pass these objects as non-consts or assigning them as non-consts? i tried using const_cast() but this caused undefined behaviour.

An example of the function call:

Board_->setvalue(x, y, Player(data, moveable, x, y));

Here is my code:

The base class

class Obstacle
{
    public:
    Obstacle* _properlyinitialized;
    string Name;
    bool Moveable;
    int x;
    int y;
    Obstacle();
    Obstacle(string Name, bool Moveable, int x, int y);
    virtual ~Obstacle();
    bool properlyInitialized();
    friend std::ostream& operator<<(std::ostream& stream, Obstacle& Obstacle);
};

An example of the derived classes (other derived classes don't have special functions yet)

class Player: public Obstacle
{
public:
    Player():Obstacle(){};
    Player(string Name, bool Moveable, int x, int y):Obstacle(Name, Moveable, x, y){this->_properlyinitialized = this;};
    ~Player(){};
    /*void Moveleft();
    void Moveright();
    void Moveup();
    void Movedown();*/
};

The Board class header

class Board
{
private:
    Board* _properlyinitialized;
    int length;
    int width;
    Obstacle * * * playfield;

public:
    /*
     **ENSURE(this->properlyInitialized(),
                "Object wasn't initialized when calling object");
     */
    Board();
    Board(int length, int width);
    ~Board();
    bool properlyInitialized();
    /*
     **REQUIRE(this->properlyInitialized(),
            "Object wasn't initialized when calling properlyinitialized");
     */
    void clear();
    const int getLength();
    const int getWidth();
    Obstacle*** getBoard();
    Obstacle* getTile(int length, int width);
    void setvalue(int length, int width, Obstacle& obstacle);
    friend std::ostream& operator<<(std::ostream& stream, Board& Board);
};

std::ostream& operator<<(std::ostream& stream, Board& Board);

And finally, the setvalue function.

void Board::setvalue(int length, int width, Obstacle& obstacle)
{
    this->playfield[length][width] = &obstacle;//value;
    return;
}

I'm happy to provide more code if needed.

Unable to set TextArea value using Jquery

I am only setting one simple value in text area using jquery on radio button click. but it sets nothing.

My Code is:

Javascript
---------
$("input[name=radio_workitem]").on("change",function(){

   $("input[name='workItemVO.note']",'#id_form_workitem_view').val("dummyNote");
}




    ">

    
        
        

        

What I have Tried:

$("input[name='workItemVO.note']",'#id_form_workitem_view').html("dummyNote");
$("input[name='workItemVO.note']",'#id_form_workitem_view').text("dummyNote")

Doesn’t work.

Here: if I set value using text area id, it works properly
example: $(“#Note”).val(“dummyNote”); // works fine

But I want to use “Name” not “Id”

Plz help, i am very new in Stack overflow, may be some mistake in my description. Plz let me know.

Thanks in Advance

Need to get TAG name by element name using Jquery [duplicate]

This question already has an answer here:

I have set of html elements and I named those for all input/select/textarea. Anyway the names are unique for each element.

Now I need to get the Html TAG (Input/Select/Textarea) by Element name.

For EX:


I need to get the ‘input’ TAG by using element name ‘sample’.

I dont want to mention the TAG name on selector part in jquery. I have only unique names to find the TAGs.

Please help on this.

Thanks in advance.!

How do I remove the space between inline-block elements?

Given this HTML and CSS:

span {
    display:inline-block;
    width:100px;
    background-color:palevioletred;
}

Foo Bar

As a result, there will be a 4 pixel wide space between the SPAN elements.

Demo: http://jsfiddle.net/dGHFV/

I understand why this happens, and I also know that I could get rid of that space by removing the white-space between the SPAN elements in the HTML source code, like so:

Foo Bar

However, I was hoping for a CSS solution that doesn’t require the HTML source code to be tampered with.

I know how to solve this with JavaScript – by removing the text nodes from the container element (the paragraph), like so:

// jQuery
$('p').contents().filter(function() { return this.nodeType === 3; }).remove();

Demo: http://jsfiddle.net/dGHFV/1/

But can this issue be solved with CSS alone?

How do I remove the space between inline-block elements?

Given this HTML and CSS:

span {
    display:inline-block;
    width:100px;
    background-color:palevioletred;
}

Foo Bar

As a result, there will be a 4 pixel wide space between the SPAN elements.

Demo: http://jsfiddle.net/dGHFV/

I understand why this happens, and I also know that I could get rid of that space by removing the white-space between the SPAN elements in the HTML source code, like so:

Foo Bar

However, I was hoping for a CSS solution that doesn’t require the HTML source code to be tampered with.

I know how to solve this with JavaScript – by removing the text nodes from the container element (the paragraph), like so:

// jQuery
$('p').contents().filter(function() { return this.nodeType === 3; }).remove();

Demo: http://jsfiddle.net/dGHFV/1/

But can this issue be solved with CSS alone?

Display: Inline block – What is that space? [duplicate]

This question already has an answer here:

Inline Blocks have this weird space in-between them. I could live with it, up to a point where, if I load more content with an AJAX Call, the tiny space goes away. I know I’m missing something here.

div {
    width: 100px;
    height: auto;
    border: 1px solid red;
    outline: 1px solid blue;
    margin: 0;
    padding: 0; 
    display: inline-block;
}

http://jsfiddle.net/AWMMT/

How to make the spacing consistent in Inline blocks ?

How to remove the space between list items [duplicate]

This question already has an answer here:

How to you get rid of the white space between list items? I am trying to make it so that the images are right next to each other. Even though I have set the styling to margins: 0;, they are still separated.

CSS

ul.frames{
  margin: 20px;
  width: 410px;
  height: 320px;
  background-color: grey;
  float: left;
  list-style-type: none;
}

ul.frames  li {
  display:inline;
  margin: 0;
  display: inline;
  list-style: none;
}

ul.frames li img {
  margin: 0 0 0 0;
}

HTML

  • How can I eliminate spacing between inline elements in CSS? [duplicate]

    This question already has an answer here:

    I have a div with a bunch of image tags inside, here is an example:

    Foo1 Foo2 Foo3

    Because there is whitespace between the tags, browsers will display some whitespace between the images (Chrome decides on 4px). How can I tell the browser to show NO whitespace whatsoever between the images, without placing the > and < directly next to each other? I know letter-spacing applies in addition to what the browser decides to use, so that's useless even with a negative value. Basically I'm going for something like Twitter has at the bottom of their home page. I looked at their code and they're using an unordered list. I could just do that but I'd like the technical explanation for why there appears to be no way to eliminate the white space from between these images.

    How to deserialize json to multiple types dynamically in c# [duplicate]

    This question already has an answer here:

    I have a json string like below :

    {
    “error” : “xxxx” ,
    “data” : int type or {…other complex json object}
    }

    I don’t know when return int or other json string from data field , and how to deserialize this ?

    when type of data is object or dynamic , the real deserialized type of data is int or Dictionary using JavaScriptSerializer.Deserialize(string json).

    the real deserialized type of data is Int64 or JContainer when using Json.Net.

    is there a elegance way to solve this ? I don’t think reflection is a good way.

    Deserialize json to anonymous C# object [duplicate]

    This question already has an answer here:

    I need to deserialize custom JSON to anonymous C# object.

    My sample JSON (can be any, even with nested properties as objects):

    var json = "{ 'Surname': 'Wick'}"; 
    

    And I want to be deserialized as:

    var jsonResult = new { Surname = "Wick" };
    

    But I end up with something like this:

    enter image description here