Iterate through char array and print chars
I am trying to print each char in a variable.
I can print the ANSI char number by changing to this printf("Value: %d\n",
d[i]); but am failing to actually print the string character itself.
What I am doing wrong here?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int len = strlen(argv[1]);
char *d = malloc (strlen(argv[1])+1);
strcpy(d,argv[1]);
int i;
for(i=0;i<len;i++){
printf("Value: %s\n", (char)d[i]);
}
return 0;
}
Friday, 27 September 2013
C Socket Programming for stdin
C Socket Programming for stdin
In C socket programming, I have to read from keyboard and accept client
socket creation . The socket connection is created successfully but the
fails to take input from keyboard. Below is code snippet.
int listener; fd_set readfds;
listener=serverConnect(listener,serveraddr,yes);
FD_SET(listener, &readfds);
FD_SET(STDIN, &readfds);
fdmax = listener;
addrlen=sizeof(clientaddr);
for(;;)
{
select(fdmax+1, &readfds, NULL, NULL, NULL);
printf("$");
if(FD_ISSET(listener, &readfds))
{
if((newfd = accept(listener, (struct sockaddr *)&clientaddr,
&addrlen)) == -1)
{
perror("Server-accept() error\n");
}
else printf("Connection is done\n");
}
if (FD_ISSET(STDIN, &readfds))
{
printf("$");
scanf("%s",command1,command2,command3);
printf("The command entered is: %s\n",command1);
if (strcmp(command1, "MYIP")==0)
{
printf("Get ip address\n");
myip();
fflush(stdout);
}
In C socket programming, I have to read from keyboard and accept client
socket creation . The socket connection is created successfully but the
fails to take input from keyboard. Below is code snippet.
int listener; fd_set readfds;
listener=serverConnect(listener,serveraddr,yes);
FD_SET(listener, &readfds);
FD_SET(STDIN, &readfds);
fdmax = listener;
addrlen=sizeof(clientaddr);
for(;;)
{
select(fdmax+1, &readfds, NULL, NULL, NULL);
printf("$");
if(FD_ISSET(listener, &readfds))
{
if((newfd = accept(listener, (struct sockaddr *)&clientaddr,
&addrlen)) == -1)
{
perror("Server-accept() error\n");
}
else printf("Connection is done\n");
}
if (FD_ISSET(STDIN, &readfds))
{
printf("$");
scanf("%s",command1,command2,command3);
printf("The command entered is: %s\n",command1);
if (strcmp(command1, "MYIP")==0)
{
printf("Get ip address\n");
myip();
fflush(stdout);
}
jQuery UI sortable & contenteditable=true not working together
jQuery UI sortable & contenteditable=true not working together
I am creating a list & want to make its item sortable and editable. So i
am doing it like this:
<ul id="ul_list">
<li><span contenteditable="true">A</span></li>
<li><span contenteditable="true">B</span></li>
<li><span contenteditable="true">C</span></li>
</ul>
$("#ul_list").sortable();
http://jsfiddle.net/7jzVa/
But if i use jquery ui sortable then my list item is losing focus for
editing and that's why i am not able to edit them.
So please suggest how can i do this?
I am creating a list & want to make its item sortable and editable. So i
am doing it like this:
<ul id="ul_list">
<li><span contenteditable="true">A</span></li>
<li><span contenteditable="true">B</span></li>
<li><span contenteditable="true">C</span></li>
</ul>
$("#ul_list").sortable();
http://jsfiddle.net/7jzVa/
But if i use jquery ui sortable then my list item is losing focus for
editing and that's why i am not able to edit them.
So please suggest how can i do this?
Html interpretation for different browsers
Html interpretation for different browsers
Recently, I downloaded a JQuery plugin for animation on tabbed content of
a html page. The html defined for Tabs and their respective contents and
animation is obtained by the JQuery. here is a sample html of my tabs.
<ul>
<li><a href="#two">PED</a></li>
<li><a href="#Five">SPDE</a></li>
<li><a href="#one">SDE</a></li>
</ul>
<div class="box-wrapper">
<div id="Seven" class="content-box">
<div class="col-one col">
<a href="" target="_blank" title="Click to go to
Advanced-Design Team Site">
<img src=""/></a>
</div>
<div class="col-two col">
<h3>
<a href="" target="_blank" style="color:
Black; text-decoration: underline"
title="Click to go to Advanced-Design Team
Site">
Advanced Design</a></h3>
<p>
Welcome to Advanced Design Group.</p>
</div>
There are remaining divs as coded above.
I displayed this tabbed html page in another page using an iframe tag.When
I click on any one of the tabs the page auto snaps to the starting of the
content page. This doesn't happen in Firefox, but it displays the content
as expected without snapping. In IE and Chrome, the page snaps to the
starting of the respective tab. We need to re scroll to the top of the
page.
Not sure why this happens, Is there any issue in the way browsers
interpret the HTML or my HTML code is wrong? I don't see any other way
except to use the approach. I know this is causing the issue but is there
any way out to make the page not snap in IE or chrome or do I need to
develop my page with tabbed content without using the approach I did now.
this is kind of Road end for me. Dont know where to go.
Any pointers would be of great help. Thanks,
Recently, I downloaded a JQuery plugin for animation on tabbed content of
a html page. The html defined for Tabs and their respective contents and
animation is obtained by the JQuery. here is a sample html of my tabs.
<ul>
<li><a href="#two">PED</a></li>
<li><a href="#Five">SPDE</a></li>
<li><a href="#one">SDE</a></li>
</ul>
<div class="box-wrapper">
<div id="Seven" class="content-box">
<div class="col-one col">
<a href="" target="_blank" title="Click to go to
Advanced-Design Team Site">
<img src=""/></a>
</div>
<div class="col-two col">
<h3>
<a href="" target="_blank" style="color:
Black; text-decoration: underline"
title="Click to go to Advanced-Design Team
Site">
Advanced Design</a></h3>
<p>
Welcome to Advanced Design Group.</p>
</div>
There are remaining divs as coded above.
I displayed this tabbed html page in another page using an iframe tag.When
I click on any one of the tabs the page auto snaps to the starting of the
content page. This doesn't happen in Firefox, but it displays the content
as expected without snapping. In IE and Chrome, the page snaps to the
starting of the respective tab. We need to re scroll to the top of the
page.
Not sure why this happens, Is there any issue in the way browsers
interpret the HTML or my HTML code is wrong? I don't see any other way
except to use the approach. I know this is causing the issue but is there
any way out to make the page not snap in IE or chrome or do I need to
develop my page with tabbed content without using the approach I did now.
this is kind of Road end for me. Dont know where to go.
Any pointers would be of great help. Thanks,
IE8 opacity animate on a png transparent
IE8 opacity animate on a png transparent
I try to animate the opacity of a div which have a .png background.
<div id="image" style="background:url('background.css') repeat-x";></div>
For that, I use this code :
$("#image").stop().animate({
opacity: 1
}, 1000, "easeInOutSine", function() {
$("#image").stop().animate({
opacity: 0
}, 1000, "easeInOutSine");
});
It's ok for recent browsers. But in IE 7 and 8, the transparence is
black... I looked for a solution but none works. Someone can help me?
Thanks
I try to animate the opacity of a div which have a .png background.
<div id="image" style="background:url('background.css') repeat-x";></div>
For that, I use this code :
$("#image").stop().animate({
opacity: 1
}, 1000, "easeInOutSine", function() {
$("#image").stop().animate({
opacity: 0
}, 1000, "easeInOutSine");
});
It's ok for recent browsers. But in IE 7 and 8, the transparence is
black... I looked for a solution but none works. Someone can help me?
Thanks
Password Regex Validation: Preventing Spaces
Password Regex Validation: Preventing Spaces
Okay, so I'm trying to adhere to the following password rule:
Must be 6 to 15 characters, include at least one lowercase letter, one
uppercase letter and at least one number. It should also contain no
spaces.
Now, for everything but the spaces, I've got:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{6,15}$
Problem is, that allows spaces.
After looking around, I've tried using \s, but that messes up my lowercase
and uppercase requirements. I also seen another suggestion to replace the
* with a +, but that seemed to break the entire thing.
I've created a REFiddle if you want to have a live test.
Okay, so I'm trying to adhere to the following password rule:
Must be 6 to 15 characters, include at least one lowercase letter, one
uppercase letter and at least one number. It should also contain no
spaces.
Now, for everything but the spaces, I've got:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{6,15}$
Problem is, that allows spaces.
After looking around, I've tried using \s, but that messes up my lowercase
and uppercase requirements. I also seen another suggestion to replace the
* with a +, but that seemed to break the entire thing.
I've created a REFiddle if you want to have a live test.
Thursday, 26 September 2013
check the update command, m i doing mistake in its syntax?
check the update command, m i doing mistake in its syntax?
his there all, i'm working on a cms, while trying the update command to
update the records, its not working.
here's m complete code for update,
Dim ID, RegNo, BedNo, BedType, Charges, PatName, PatAge, PatAddr, Phone,
CheckupDate, Disease, BloodGroup, Doctor, Remarks As String
RegNo = txtRegNo.Text
BedNo = CmbBedNo.SelectedItem.ToString()
BedType = CmbBedType.SelectedItem.ToString()
Charges = txtCharges.Text
PatName = txtPatName.Text
PatAge = txtPatAge.Text
PatAddr = txtPatAdd.Text
Phone = txtPhone.Text
CheckupDate = txtDate.Text
Disease = txtDisease.Text
BloodGroup = cmbBloodGrp.SelectedItem.ToString()
Doctor = cmbDoctor.SelectedItem.ToString()
Remarks = txtRemarks.Text
ID = txtRegNo.Text
Dim conStudent As New OleDbConnection
Dim comStudent As New OleDbCommand
conStudent.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=F:\DBProject\hspms.mdb"
conStudent.Open()
comStudent.CommandText = "UPDATE AdmitPt SET ID =" & ID & ",
Bedcategory='" & BedType & "', BedNo=" & BedNo & ", BedCharges=" &
Charges & ", PtName='" & PatName & "', PtAge=" & PatAge & ",
Address='" & PatAddr & "', PhoneNo='" & Phone & "', Dates='" &
CheckupDate & "', Disease='" & Disease & "', BloodGroup='" &
BloodGroup & "', Doctor='" & Doctor & "', Remarks='" & Remarks & "'
WHERE ID=" & RegNo
comStudent.Connection = conStudent
comStudent.CommandType = CommandType.Text
If (comStudent.ExecuteNonQuery() > 0) Then
MsgBox("record successfully updated")
End If
conStudent.Close()
one thing, that the fields named with ID, BedNo, BedCharges, Age are set
to Number as data type.
his there all, i'm working on a cms, while trying the update command to
update the records, its not working.
here's m complete code for update,
Dim ID, RegNo, BedNo, BedType, Charges, PatName, PatAge, PatAddr, Phone,
CheckupDate, Disease, BloodGroup, Doctor, Remarks As String
RegNo = txtRegNo.Text
BedNo = CmbBedNo.SelectedItem.ToString()
BedType = CmbBedType.SelectedItem.ToString()
Charges = txtCharges.Text
PatName = txtPatName.Text
PatAge = txtPatAge.Text
PatAddr = txtPatAdd.Text
Phone = txtPhone.Text
CheckupDate = txtDate.Text
Disease = txtDisease.Text
BloodGroup = cmbBloodGrp.SelectedItem.ToString()
Doctor = cmbDoctor.SelectedItem.ToString()
Remarks = txtRemarks.Text
ID = txtRegNo.Text
Dim conStudent As New OleDbConnection
Dim comStudent As New OleDbCommand
conStudent.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=F:\DBProject\hspms.mdb"
conStudent.Open()
comStudent.CommandText = "UPDATE AdmitPt SET ID =" & ID & ",
Bedcategory='" & BedType & "', BedNo=" & BedNo & ", BedCharges=" &
Charges & ", PtName='" & PatName & "', PtAge=" & PatAge & ",
Address='" & PatAddr & "', PhoneNo='" & Phone & "', Dates='" &
CheckupDate & "', Disease='" & Disease & "', BloodGroup='" &
BloodGroup & "', Doctor='" & Doctor & "', Remarks='" & Remarks & "'
WHERE ID=" & RegNo
comStudent.Connection = conStudent
comStudent.CommandType = CommandType.Text
If (comStudent.ExecuteNonQuery() > 0) Then
MsgBox("record successfully updated")
End If
conStudent.Close()
one thing, that the fields named with ID, BedNo, BedCharges, Age are set
to Number as data type.
Wednesday, 25 September 2013
How to administer computer when no inbound connection is possible?
How to administer computer when no inbound connection is possible?
I have to periodically administer my parent's Linux computer, because they
are too old to understand how to do this themselves. Computer is in the
remote location. I always used ssh through the port forwarding on the
router. However, their provider recently removed the ability to make any
inbound connection and my ssh doesn't connect any more.
My question is: what is the next best way to administer it?
I know that VPN can possibly be used. I can (maybe) set up VPN network
with this computer. Also I can make it try to connect with ssh to my home
computer on a particular port for ex. every 15 minutes, establishing the
port forwarding back to it. Custom shell script should be used for this.
But what are the alternatives? Any other, nicer way to be able to connect
to this Linux machine from outside?
I have to periodically administer my parent's Linux computer, because they
are too old to understand how to do this themselves. Computer is in the
remote location. I always used ssh through the port forwarding on the
router. However, their provider recently removed the ability to make any
inbound connection and my ssh doesn't connect any more.
My question is: what is the next best way to administer it?
I know that VPN can possibly be used. I can (maybe) set up VPN network
with this computer. Also I can make it try to connect with ssh to my home
computer on a particular port for ex. every 15 minutes, establishing the
port forwarding back to it. Custom shell script should be used for this.
But what are the alternatives? Any other, nicer way to be able to connect
to this Linux machine from outside?
Thursday, 19 September 2013
How to set up dependency injection using Dagger for other things then Activities and Fragments?
How to set up dependency injection using Dagger for other things then
Activities and Fragments?
I started setting up dependency injection using Dagger as follows. Please
feel encouraged to correct my implementation since I might have mistakes
in there! In the following you can see how I successfully added dependency
injection for Activities and Fragments. I try to keep it easy for now so I
decided to inject Timber as a logger substitution for Android's log util.
import android.app.Application;
import dagger.ObjectGraph;
import com.example.debugging.LoggingModule;
public class ExampleApplication extends Application {
private ObjectGraph mObjectGraph;
@Override public void onCreate() {
super.onCreate();
mObjectGraph = ObjectGraph.create(new LoggingModule());
}
public void inject(Object object) {
mObjectGraph.inject(object);
}
}
I prepared LoggingModule which provides access to Timber.
package com.example.debugging;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import com.example.BuildConfig;
import com.example.activities.BaseFragmentActivity;
import com.example.activities.DetailsActivity;
import com.example.fragments.BaseListFragment;
import com.example.fragments.ProfilesListFragment;
import timber.log.Timber;
@Module(injects = {
// Activities
BaseFragmentActivity.class,
DetailsActivity.class,
// Fragments
BaseListFragment.class,
ProfilesListFragment.class
})
public class LoggingModule {
@Provides @Singleton Timber provideTimber() {
return BuildConfig.DEBUG ? Timber.DEBUG : Timber.PROD;
}
}
The base class for Activities injects itself into the object graph ...
package com.example.activities;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import javax.inject.Inject;
import com.example.ExampleApplication;
import timber.log.Timber;
public class BaseFragmentActivity extends SherlockFragmentActivity {
@Inject Timber mTimber;
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
super.onCreate(savedInstanceState);
((ExampleApplication) getApplication()).inject(this);
}
}
... and any sub class benefits from Timber being already present.
package com.example.activities;
import android.os.Bundle;
import com.example.R;
public class DetailsActivity extends BaseFragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
mTimber.i("onCreate");
// ...
}
}
Same for Fragments: the base class does the dirty job ...
package com.example.fragments;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockListFragment;
import javax.inject.Inject;
import com.example.ExampleApplication;
import timber.log.Timber;
public class BaseListFragment extends SherlockListFragment {
@Inject Timber mTimber;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
((ExampleApplication) getActivity().getApplication()).inject(this);
}
}
... and the sub class benefits from its super class.
package com.example.fragments;
import android.os.Bundle;
public class ProfilesListFragment extends BaseListFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setEmptyText("No data loaded");
mTimber.i("onActivityCreated");
// ...
}
}
So far so good. But how can inject Timber into BaseCursorAdapter,
BaseContentProvider, BaseSQLiteOpenHelper, BaseService, BaseAsyncTask and
static helper methods?
References:
Dagger
Jesse Wilson - Dagger: A Fast Dependency Injector for Android and Java
Eric Burke - Android App Anatomy
Activities and Fragments?
I started setting up dependency injection using Dagger as follows. Please
feel encouraged to correct my implementation since I might have mistakes
in there! In the following you can see how I successfully added dependency
injection for Activities and Fragments. I try to keep it easy for now so I
decided to inject Timber as a logger substitution for Android's log util.
import android.app.Application;
import dagger.ObjectGraph;
import com.example.debugging.LoggingModule;
public class ExampleApplication extends Application {
private ObjectGraph mObjectGraph;
@Override public void onCreate() {
super.onCreate();
mObjectGraph = ObjectGraph.create(new LoggingModule());
}
public void inject(Object object) {
mObjectGraph.inject(object);
}
}
I prepared LoggingModule which provides access to Timber.
package com.example.debugging;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import com.example.BuildConfig;
import com.example.activities.BaseFragmentActivity;
import com.example.activities.DetailsActivity;
import com.example.fragments.BaseListFragment;
import com.example.fragments.ProfilesListFragment;
import timber.log.Timber;
@Module(injects = {
// Activities
BaseFragmentActivity.class,
DetailsActivity.class,
// Fragments
BaseListFragment.class,
ProfilesListFragment.class
})
public class LoggingModule {
@Provides @Singleton Timber provideTimber() {
return BuildConfig.DEBUG ? Timber.DEBUG : Timber.PROD;
}
}
The base class for Activities injects itself into the object graph ...
package com.example.activities;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import javax.inject.Inject;
import com.example.ExampleApplication;
import timber.log.Timber;
public class BaseFragmentActivity extends SherlockFragmentActivity {
@Inject Timber mTimber;
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
super.onCreate(savedInstanceState);
((ExampleApplication) getApplication()).inject(this);
}
}
... and any sub class benefits from Timber being already present.
package com.example.activities;
import android.os.Bundle;
import com.example.R;
public class DetailsActivity extends BaseFragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
mTimber.i("onCreate");
// ...
}
}
Same for Fragments: the base class does the dirty job ...
package com.example.fragments;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockListFragment;
import javax.inject.Inject;
import com.example.ExampleApplication;
import timber.log.Timber;
public class BaseListFragment extends SherlockListFragment {
@Inject Timber mTimber;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
((ExampleApplication) getActivity().getApplication()).inject(this);
}
}
... and the sub class benefits from its super class.
package com.example.fragments;
import android.os.Bundle;
public class ProfilesListFragment extends BaseListFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setEmptyText("No data loaded");
mTimber.i("onActivityCreated");
// ...
}
}
So far so good. But how can inject Timber into BaseCursorAdapter,
BaseContentProvider, BaseSQLiteOpenHelper, BaseService, BaseAsyncTask and
static helper methods?
References:
Dagger
Jesse Wilson - Dagger: A Fast Dependency Injector for Android and Java
Eric Burke - Android App Anatomy
what is wrong with this program? 3.31
what is wrong with this program? 3.31
my code is as follows but wont work:
inputStr=input('enter the number of quarters: ')
quarters=int(inputStr)
if inputStr.isdigit() :
total=total+quarters*0.25
print('Total: ', total)
else:
print('input error. ')
What is wrong with this?
my code is as follows but wont work:
inputStr=input('enter the number of quarters: ')
quarters=int(inputStr)
if inputStr.isdigit() :
total=total+quarters*0.25
print('Total: ', total)
else:
print('input error. ')
What is wrong with this?
How to split a string in Python by 2 or 3, etc [duplicate]
How to split a string in Python by 2 or 3, etc [duplicate]
This question already has an answer here:
What is the most "pythonic" way to iterate over a list in chunks? 16 answers
Split python string every nth character? [duplicate] 6 answers
Does anyone know if it's possible in python to split a string, not
necessarily by a space or commas, but just by every other entry in the
string? or every 3rd or 4th etc.
For example if I had "12345678" as my string, is there a way to split it
into "12", "34", "56", 78"?
This question already has an answer here:
What is the most "pythonic" way to iterate over a list in chunks? 16 answers
Split python string every nth character? [duplicate] 6 answers
Does anyone know if it's possible in python to split a string, not
necessarily by a space or commas, but just by every other entry in the
string? or every 3rd or 4th etc.
For example if I had "12345678" as my string, is there a way to split it
into "12", "34", "56", 78"?
Netbeans giving me an error message but it works as I want it
Netbeans giving me an error message but it works as I want it
I have a subclass which contains a function which returns a float. I call
that function in a try catch statement, if the an if statement fails and
the else catches it I want that function to "crash" by returning noting
like this return;
Here is that function:
function calc(... some arguments ...) {
...
if (operator.equals("+")) number = num1+num2;
else if (operator.equals("-")) number = num1-num2;
else if (operator.equals("*")) number = num1*num2;
else if (operator.equals("/")) number = num1/num2;
else return; // Here Netbeans gives me an error saying "Missing return
value"
}
Now this function is getting called in a try and I if the else gets
executed I want the function to "crash" and go to the catch statement and
give the user an error message. This works exactly the way I want it but
why does Netbeans give me an error?? Is there another way to do this?
I have a subclass which contains a function which returns a float. I call
that function in a try catch statement, if the an if statement fails and
the else catches it I want that function to "crash" by returning noting
like this return;
Here is that function:
function calc(... some arguments ...) {
...
if (operator.equals("+")) number = num1+num2;
else if (operator.equals("-")) number = num1-num2;
else if (operator.equals("*")) number = num1*num2;
else if (operator.equals("/")) number = num1/num2;
else return; // Here Netbeans gives me an error saying "Missing return
value"
}
Now this function is getting called in a try and I if the else gets
executed I want the function to "crash" and go to the catch statement and
give the user an error message. This works exactly the way I want it but
why does Netbeans give me an error?? Is there another way to do this?
How can I change my NHibernate mapping involving a composite id to execute the expected sql statement?
How can I change my NHibernate mapping involving a composite id to execute
the expected sql statement?
I'm using FluentNHibernate and building a system where a Customer object
exposes several CustomerProperty objects, basically a per-customer
key-value store.
public class CustomerMap : ClassMap<Customer> {
public CustomerMap() {
Table("Customer");
Id(x => x.Id);
Map(x => x.UserName);
HasMany(x => x.Properties);
}
}
public class CustomerPropertyMap : ClassMap<CustomerProperty> {
public CustomerPropertyMap() {
Table("CustomerProperty");
CompositeId()
.KeyReference(x => x.Customer, MapData<Customer>.KeyColumn)
.KeyProperty(x => x.Key);
Map(x => x.Value);
}
}
This works and generates proper NHibernate mappings. I've exported them
using the built-in capabilities of FluentNHibernate.
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" dynamic-update="true"
name="Bazinga.Domain.CustomerProperty, Bazinga.Domain,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=108b91ac50cc98b9"
table="CustomerProperty">
<composite-id>
<key-many-to-one name="Customer"
class="Bazinga.Domain.Customer, Bazinga.Domain,
Version=0.0.0.0, Culture=neutral,
PublicKeyToken=108b91ac50cc98b9">
<column name="CustomerId" />
</key-many-to-one>
<key-property name="Key" type="System.String, mscorlib,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<column name="Key" />
</key-property>
</composite-id>
<property name="Value" type="System.String, mscorlib,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<column name="Value" />
</property>
</class>
</hibernate-mapping>
This mapping, however, generates a sql query that does not visually please
me. (I can be pretty pedantic.) NHibernate Profiles shows me that the
following query executes.
SELECT properties0_.CustomerId as CustomerId1_,
properties0_.[Key] as Key2_1_,
properties0_.CustomerId as CustomerId13_0_,
properties0_.[Key] as Key2_13_0_,
properties0_.[Value] as Value3_13_0_
FROM CustomerProperty properties0_
WHERE properties0_.CustomerId = 1337 /* @p0 */
There are duplicate references to the CustomerId and the Key column. How
can I remove these and only return a result of three columns (CustomerId,
Key, Value)?
the expected sql statement?
I'm using FluentNHibernate and building a system where a Customer object
exposes several CustomerProperty objects, basically a per-customer
key-value store.
public class CustomerMap : ClassMap<Customer> {
public CustomerMap() {
Table("Customer");
Id(x => x.Id);
Map(x => x.UserName);
HasMany(x => x.Properties);
}
}
public class CustomerPropertyMap : ClassMap<CustomerProperty> {
public CustomerPropertyMap() {
Table("CustomerProperty");
CompositeId()
.KeyReference(x => x.Customer, MapData<Customer>.KeyColumn)
.KeyProperty(x => x.Key);
Map(x => x.Value);
}
}
This works and generates proper NHibernate mappings. I've exported them
using the built-in capabilities of FluentNHibernate.
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" dynamic-update="true"
name="Bazinga.Domain.CustomerProperty, Bazinga.Domain,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=108b91ac50cc98b9"
table="CustomerProperty">
<composite-id>
<key-many-to-one name="Customer"
class="Bazinga.Domain.Customer, Bazinga.Domain,
Version=0.0.0.0, Culture=neutral,
PublicKeyToken=108b91ac50cc98b9">
<column name="CustomerId" />
</key-many-to-one>
<key-property name="Key" type="System.String, mscorlib,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<column name="Key" />
</key-property>
</composite-id>
<property name="Value" type="System.String, mscorlib,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<column name="Value" />
</property>
</class>
</hibernate-mapping>
This mapping, however, generates a sql query that does not visually please
me. (I can be pretty pedantic.) NHibernate Profiles shows me that the
following query executes.
SELECT properties0_.CustomerId as CustomerId1_,
properties0_.[Key] as Key2_1_,
properties0_.CustomerId as CustomerId13_0_,
properties0_.[Key] as Key2_13_0_,
properties0_.[Value] as Value3_13_0_
FROM CustomerProperty properties0_
WHERE properties0_.CustomerId = 1337 /* @p0 */
There are duplicate references to the CustomerId and the Key column. How
can I remove these and only return a result of three columns (CustomerId,
Key, Value)?
jQuery .hover() in content
jQuery .hover() in content
i have tried to display the value in title on hover, i faced the problem
when i try to hover on a anchor tag in title it displayed some thing like
this <a href="http://blabla.com/1">one</a> so that i have used the
following code to overcome this..
$('.table1 td, .table2 td').find("a, div, label")
.hover(function() {
$(this).prop('title', $(this).html());
});
Now, what i need means, when i hover other than a, div, label am not able
to get any content of td in hover, i need help.. anyone??
i have tried to display the value in title on hover, i faced the problem
when i try to hover on a anchor tag in title it displayed some thing like
this <a href="http://blabla.com/1">one</a> so that i have used the
following code to overcome this..
$('.table1 td, .table2 td').find("a, div, label")
.hover(function() {
$(this).prop('title', $(this).html());
});
Now, what i need means, when i hover other than a, div, label am not able
to get any content of td in hover, i need help.. anyone??
after upload my site on go daddy this error show pls tell me how to solve it
after upload my site on go daddy this error show pls tell me how to solve it
After uploading my site on go daddy I'm getting the following error error:
Link to database cannot be established: SQLSTATE[HY000] [2002] Can't
connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
(2)
Can someone tell me how to solve it step by step please?
After uploading my site on go daddy I'm getting the following error error:
Link to database cannot be established: SQLSTATE[HY000] [2002] Can't
connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
(2)
Can someone tell me how to solve it step by step please?
How to uninstall OpenERP-7 module in ubuntu 12.04 ?
How to uninstall OpenERP-7 module in ubuntu 12.04 ?
I am using OpenERP 7 with Ubuntu 12.04. I have been trying to install Aero
Reports module for creating OpenERP reports. I faced some "XML issues "
during installation.
Now when I try to remove the module it says "Integrity Error
The operation cannot be completed, probably due to the following: -
deletion: you may be trying to delete a record while other records still
reference it" .Plz help me to fix this issue
Hopes for suggestion
I am using OpenERP 7 with Ubuntu 12.04. I have been trying to install Aero
Reports module for creating OpenERP reports. I faced some "XML issues "
during installation.
Now when I try to remove the module it says "Integrity Error
The operation cannot be completed, probably due to the following: -
deletion: you may be trying to delete a record while other records still
reference it" .Plz help me to fix this issue
Hopes for suggestion
Wednesday, 18 September 2013
dynamic memory allocation and memory leak
dynamic memory allocation and memory leak
Does free releases the memory in the below, and how can I verify that
memory is released ?
int *p = malloc(sizeof(int));
int *q = p;
free(q);
How to access MCB structure for a dynamically allocated memory ?
Does free releases the memory in the below, and how can I verify that
memory is released ?
int *p = malloc(sizeof(int));
int *q = p;
free(q);
How to access MCB structure for a dynamically allocated memory ?
Call a javascript function after ajax success
Call a javascript function after ajax success
I am using the below test code to call a javascript function from ajax
method after the success block and pass the success value to a javascript
funtion.It's working fine. Now i want to get javascript return message
from ajax call. It always return null.
function testAjax() {
$.ajax({
url:"getvalue.php",
success:function(data) {
var retval= change_format(data);
alert(retvl);//always return null
I can't get the result
}
});
}
function change_format(data)
{
do something.....
value = "Some Data"; having some data
return value;
}
I am using the below test code to call a javascript function from ajax
method after the success block and pass the success value to a javascript
funtion.It's working fine. Now i want to get javascript return message
from ajax call. It always return null.
function testAjax() {
$.ajax({
url:"getvalue.php",
success:function(data) {
var retval= change_format(data);
alert(retvl);//always return null
I can't get the result
}
});
}
function change_format(data)
{
do something.....
value = "Some Data"; having some data
return value;
}
How do I fix this memory leak in C++?
How do I fix this memory leak in C++?
I'm stuck on a program that is due for a class. I have to complete the
project with the correct output and without any memory leaks. Below is the
.h and .cpp for both LocationStack and LocationStackNode. I currently am
getting a memory leak on LocationStackNode and wondered if anyone could
help me with how I should write the destructor. Valgrind specifically
reports the memory leak when allocating new memory in
LocationStack::push(). I am also not allowed to modify the .h file at all.
stack-proj1.h:
class LocationStack {
public:
LocationStack(void);
~LocationStack();
void push(const Location &loc);
void pop(void);
const Location &getTop(void) const;
bool isEmpty(void) const;
bool isOn(const Location &loc) const;
friend ostream &operator<<(ostream &os, const LocationStack &s);
private:
const LocationStack &operator=(const LocationStack &)
{ assert(false); }
LocationStack(const LocationStack &) { assert(false); }
LocationStackNode *top;
};
class LocationStackNode {
public:
LocationStackNode(const Location &loc, LocationStackNode *next = NULL);
~LocationStackNode();
const Location &getLocation() const;
LocationStackNode *getNextNode() const;
void setNextNode(LocationStackNode *next);
private:
LocationStackNode() { assert(false); }
LocationStackNode(const LocationStackNode &) { assert(false); }
LocationStackNode &operator=(const LocationStackNode &)
{ assert(false); }
Location location;
LocationStackNode *nextNode;
};
stack-proj1.cpp
LocationStack::LocationStack(void){
top = NULL;
}
LocationStack::~LocationStack(){
delete top;
top = NULL;
}
void LocationStack::push(const Location &loc){
top = new LocationStackNode(loc, top);
}
void LocationStack::pop(void){
if(top->getNextNode()){
LocationStackNode *newNode;
newNode = top->getNextNode();
top = newNode;
}
else{
top = NULL;
}
}
const Location& LocationStack::getTop(void) const{
return top->getLocation();
}
bool LocationStack::isEmpty(void) const{
bool isEmpty = false;
if(!top){
isEmpty = true;
}
return isEmpty;
}
bool LocationStack::isOn(const Location &loc) const{
bool isOn = false;
int stackSize = 0;
if(!this->isEmpty()){
LocationStackNode *newNode = top;
LocationStackNode *newNode2 = top;
while(newNode2->getNextNode()){
newNode2 = newNode2->getNextNode();
stackSize++;
}
for(int n = 0; n <= stackSize; n++)/*while(newNode->getNextNode())*/{
if(newNode->getLocation() == loc){
isOn = true;
}
newNode = newNode->getNextNode();
}
}
return isOn;
}
ostream &operator<<(ostream &os, const LocationStack &s){
LocationStackNode *back = s.top;
LocationStackNode *next = s.top->getNextNode();
LocationStackNode *newNode = s.top;
newNode->setNextNode(NULL);
while(next){
newNode = next;
next = newNode->getNextNode();
newNode->setNextNode(back);
back = newNode;
}
while(newNode->getNextNode()){
os << newNode->getLocation() << endl;
newNode = newNode->getNextNode();
}
os << newNode->getLocation() << endl;
return os;
}
LocationStackNode::LocationStackNode(const Location &loc,
LocationStackNode *next){
location = loc;
nextNode = next;
}
LocationStackNode::~LocationStackNode(){
delete nextNode;
}
const Location& LocationStackNode::getLocation() const{
return location;
}
LocationStackNode* LocationStackNode::getNextNode() const{
return nextNode;
}
void LocationStackNode::setNextNode(LocationStackNode *next){
nextNode = next;
}
This is how Nodes are populated:
LocationStack stacks;
stacks.push(Location l); //Location is another class itself
Everything added to the stack uses the push() function of LocationStack.
Sorry there's so much code here. I've been trying to figure this out for a
while and I'm really not sure what the issue is. I just want to make sure
everything is here just in case there's another issue. If you're willing
to look through this for me, I will be so grateful. I just need to finish
this project so I can start on the next one. Thanks in advance for any
help!
I'm stuck on a program that is due for a class. I have to complete the
project with the correct output and without any memory leaks. Below is the
.h and .cpp for both LocationStack and LocationStackNode. I currently am
getting a memory leak on LocationStackNode and wondered if anyone could
help me with how I should write the destructor. Valgrind specifically
reports the memory leak when allocating new memory in
LocationStack::push(). I am also not allowed to modify the .h file at all.
stack-proj1.h:
class LocationStack {
public:
LocationStack(void);
~LocationStack();
void push(const Location &loc);
void pop(void);
const Location &getTop(void) const;
bool isEmpty(void) const;
bool isOn(const Location &loc) const;
friend ostream &operator<<(ostream &os, const LocationStack &s);
private:
const LocationStack &operator=(const LocationStack &)
{ assert(false); }
LocationStack(const LocationStack &) { assert(false); }
LocationStackNode *top;
};
class LocationStackNode {
public:
LocationStackNode(const Location &loc, LocationStackNode *next = NULL);
~LocationStackNode();
const Location &getLocation() const;
LocationStackNode *getNextNode() const;
void setNextNode(LocationStackNode *next);
private:
LocationStackNode() { assert(false); }
LocationStackNode(const LocationStackNode &) { assert(false); }
LocationStackNode &operator=(const LocationStackNode &)
{ assert(false); }
Location location;
LocationStackNode *nextNode;
};
stack-proj1.cpp
LocationStack::LocationStack(void){
top = NULL;
}
LocationStack::~LocationStack(){
delete top;
top = NULL;
}
void LocationStack::push(const Location &loc){
top = new LocationStackNode(loc, top);
}
void LocationStack::pop(void){
if(top->getNextNode()){
LocationStackNode *newNode;
newNode = top->getNextNode();
top = newNode;
}
else{
top = NULL;
}
}
const Location& LocationStack::getTop(void) const{
return top->getLocation();
}
bool LocationStack::isEmpty(void) const{
bool isEmpty = false;
if(!top){
isEmpty = true;
}
return isEmpty;
}
bool LocationStack::isOn(const Location &loc) const{
bool isOn = false;
int stackSize = 0;
if(!this->isEmpty()){
LocationStackNode *newNode = top;
LocationStackNode *newNode2 = top;
while(newNode2->getNextNode()){
newNode2 = newNode2->getNextNode();
stackSize++;
}
for(int n = 0; n <= stackSize; n++)/*while(newNode->getNextNode())*/{
if(newNode->getLocation() == loc){
isOn = true;
}
newNode = newNode->getNextNode();
}
}
return isOn;
}
ostream &operator<<(ostream &os, const LocationStack &s){
LocationStackNode *back = s.top;
LocationStackNode *next = s.top->getNextNode();
LocationStackNode *newNode = s.top;
newNode->setNextNode(NULL);
while(next){
newNode = next;
next = newNode->getNextNode();
newNode->setNextNode(back);
back = newNode;
}
while(newNode->getNextNode()){
os << newNode->getLocation() << endl;
newNode = newNode->getNextNode();
}
os << newNode->getLocation() << endl;
return os;
}
LocationStackNode::LocationStackNode(const Location &loc,
LocationStackNode *next){
location = loc;
nextNode = next;
}
LocationStackNode::~LocationStackNode(){
delete nextNode;
}
const Location& LocationStackNode::getLocation() const{
return location;
}
LocationStackNode* LocationStackNode::getNextNode() const{
return nextNode;
}
void LocationStackNode::setNextNode(LocationStackNode *next){
nextNode = next;
}
This is how Nodes are populated:
LocationStack stacks;
stacks.push(Location l); //Location is another class itself
Everything added to the stack uses the push() function of LocationStack.
Sorry there's so much code here. I've been trying to figure this out for a
while and I'm really not sure what the issue is. I just want to make sure
everything is here just in case there's another issue. If you're willing
to look through this for me, I will be so grateful. I just need to finish
this project so I can start on the next one. Thanks in advance for any
help!
cannot get my datatables drill down to work
cannot get my datatables drill down to work
$(document).ready(function () {
var anOpen = [];
var oTable = $('#table_id').dataTable();
$('#table_id tbody').on('click', 'tr', function (e) {
var nTr = this.parentNode;
var i = $.inArray(nTr, anOpen);
console.log("clicked|" + i);
if (i == -1) {
var nDetailsRow = oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr),
'details');
$('div.innerDetails', nDetailsRow).slideDown();
anOpen.push(nTr);
console.log("open");
}
else {
oTable.fnClose( nTr );
anOpen.splice( i, 1 );
console.log("closed");
}
});
function fnFormatDetails(oTable, nTr) {
var oData = oTable.fnGetData(nTr);
var sOut =
'<div class="innerDetails">' +
'<table cellpadding="5" cellspacing="0" border="0"
style="padding-left:50px;">' +
'<tr><td>Rendering engine:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Browser:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Platform:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Version:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Grade:</td><td>' + 'hi' + '</td></tr>' +
'</table>' +
'</div>';
return sOut;
}
Just gave a section of it, When i click on the row it does trigger the if
(i==-1) and then when i click again it triggers the else and works back
and forth the problem is that i cannot get anything to display. The table
just sits and new opens another table below it like it should. No errors
in the console just the proper console logs.
$(document).ready(function () {
var anOpen = [];
var oTable = $('#table_id').dataTable();
$('#table_id tbody').on('click', 'tr', function (e) {
var nTr = this.parentNode;
var i = $.inArray(nTr, anOpen);
console.log("clicked|" + i);
if (i == -1) {
var nDetailsRow = oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr),
'details');
$('div.innerDetails', nDetailsRow).slideDown();
anOpen.push(nTr);
console.log("open");
}
else {
oTable.fnClose( nTr );
anOpen.splice( i, 1 );
console.log("closed");
}
});
function fnFormatDetails(oTable, nTr) {
var oData = oTable.fnGetData(nTr);
var sOut =
'<div class="innerDetails">' +
'<table cellpadding="5" cellspacing="0" border="0"
style="padding-left:50px;">' +
'<tr><td>Rendering engine:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Browser:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Platform:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Version:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Grade:</td><td>' + 'hi' + '</td></tr>' +
'</table>' +
'</div>';
return sOut;
}
Just gave a section of it, When i click on the row it does trigger the if
(i==-1) and then when i click again it triggers the else and works back
and forth the problem is that i cannot get anything to display. The table
just sits and new opens another table below it like it should. No errors
in the console just the proper console logs.
Subscribe to:
Posts (Atom)