Monday, 30 September 2013

Any reference ,$f(x)=x*e^x-2$? [on hold]

Any reference ,$f(x)=x*e^x-2$? [on hold]

$f(x)=x*e^{x}-2$
$f(0)=-2$
$f(1)=e-2$
$x_{1}=x_{0}-\frac{f(x)}{f^{'}(x)}$
A better book to refer for this.

How to configure Single-Server Private Network in Xenserver without using VLAN?

How to configure Single-Server Private Network in Xenserver without using
VLAN?

I would like to create a Single Server private Network on a Xenserver
which will be used for communication between the host and the VMs. I am
able to achive this by creating a vlan and configuring the pif.
But when looking at the XenCenter, there is an explicit option to create
such a network without the VLAN stuff. Where would I configure it using xe
or Xencenter commands? I can see it in network-list, ifconfig and brctl,
but where would I set the local IPs?

Android selector draw doesn't overlap

Android selector draw doesn't overlap

My problem is when my checkableLinearLayout is checked my draw from the
selector can´t overlap the unchecked image.
My checkableLinearLayout
public class CheckableLinearLayout extends LinearLayout implements
Checkable {
private boolean mChecked;
private static final String TAG = CheckableLinearLayout.class
.getCanonicalName();
private static final int[] CHECKED_STATE_SET = {
android.R.attr.state_checked };
public CheckableLinearLayout(final Context context) {
super(context);
setClickable(true);
setLongClickable(true);
}
public CheckableLinearLayout(final Context context, final AttributeSet
attrs) {
super(context, attrs);
setClickable(true);
setLongClickable(true);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public CheckableLinearLayout(final Context context,
final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
setClickable(true);
setLongClickable(true);
}
@Override
public void setChecked(final boolean checked) {
mChecked = checked;
refreshDrawableState();
}
@Override
protected int[] onCreateDrawableState(final int extraSpace) {
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isChecked())
mergeDrawableStates(drawableState, CHECKED_STATE_SET);
return drawableState;
}
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
final Drawable drawable = getBackground();
if (drawable != null) {
final int[] myDrawableState = getDrawableState();
drawable.setState(myDrawableState);
invalidate();
}
}
@Override
public boolean performClick() {
Toast.makeText(getContext(), "click", Toast.LENGTH_SHORT).show();
if (isChecked()) {
toggle();
return false;
} else
return super.performClick();
}
@Override
public boolean performLongClick() {
toggle();
Toast.makeText(getContext(), "long click", Toast.LENGTH_SHORT).show();
return super.performLongClick();
}
@Override
public boolean isChecked() {
return mChecked;
}
@Override
public void toggle() {
setChecked(!mChecked);
}
@Override
public Parcelable onSaveInstanceState() {
// Force our ancestor class to save its state
final Parcelable superState = super.onSaveInstanceState();
final SavedState savedState = new SavedState(superState);
savedState.checked = isChecked();
return savedState;
}
@Override
public void onRestoreInstanceState(final Parcelable state) {
final SavedState savedState = (SavedState) state;
super.onRestoreInstanceState(savedState.getSuperState());
setChecked(savedState.checked);
requestLayout();
}
// /////////////
// SavedState //
// /////////////
private static class SavedState extends BaseSavedState {
boolean checked;
@SuppressWarnings("unused")
public static final Parcelable.Creator<SavedState> CREATOR;
static {
CREATOR = new Parcelable.Creator<SavedState>() {
@Override
public SavedState createFromParcel(final Parcel in) {
return new SavedState(in);
}
@Override
public SavedState[] newArray(final int size) {
return new SavedState[size];
}
};
}
SavedState(final Parcelable superState) {
super(superState);
}
private SavedState(final Parcel in) {
super(in);
checked = (Boolean) in.readValue(null);
}
@Override
public void writeToParcel(final Parcel out, final int flags) {
super.writeToParcel(out, flags);
out.writeValue(checked);
}
@Override
public String toString() {
return TAG + ".SavedState{"
+ Integer.toHexString(System.identityHashCode(this))
+ " checked=" + checked + "}";
}
}
}
My layout.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/topics_preview_main_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/favorites_header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="2dp"
android:orientation="vertical" >
<TextView
android:id="@+id/favorites_header_title"
style="@style/CardText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:background="@drawable/card"
android:gravity="left"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:text="@string/favorites_header" />
<ui.CheckableLinearLayout
android:id="@+id/favorites_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:background="@drawable/card_selector_w_shadow"
android:clickable="true"
android:longClickable="true"
android:orientation="vertical"
android:paddingBottom="16dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<TextView
android:id="@+id/favorites_title"
style="@style/CardTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="title" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="4dp"
android:background="@color/C_Favorites_Pink" />
<LinearLayout
android:id="@+id/favorites_description_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="4dp" >
<TextView
android:id="@+id/favorites_description"
style="@style/CardText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:ellipsize="end"
android:maxLines="4"
android:text="Lorem ipsum ..." />
</LinearLayout>
</ui.CheckableLinearLayout>
</LinearLayout>
My drawable -> this draw will call the selector
<?xml version="1.0" encoding="utf-8"?>
<item>
<shape
android:dither="true"
android:shape="rectangle" >
<corners android:radius="2dp" />
<solid android:color="#ccc" />
</shape>
</item>
<item android:bottom="2dp">
<shape
android:dither="true"
android:shape="rectangle" >
<corners android:radius="2dp" />
<solid android:color="@android:color/white" />
<padding
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp" />
</shape>
</item>
<item android:drawable="@drawable/drawable_states"/>
My selector xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/checked_background"
android:state_checked="true"/>
This is whats happening:

This is what i pretend:

Continue slideshow with Unslider

Continue slideshow with Unslider

I'm using Unslider at the moment and I'm wondering if there is any way to
make the slideshow continue to the right when switching from the last
slide to the first one. At the moment it goes through all the slides from
right to left when jumping to the first one from the last.
If that isn't possible, is it possible to make it go backwards from the
last one instead? Like this:
1 - 2 - 3 - 4 // 4 - 3 - 2 - 1 // 1 - 2 - 3...
Really appreciate answers! Thanks!

Sunday, 29 September 2013

Onchange 1st date picker, 2nd datepicker will change

Onchange 1st date picker, 2nd datepicker will change

in my form, i have 2 datepicker (eg : date1, date2). Date1 is approval
deadline and date2 is confirmation daedline. Approval deadline should be
equal or more than confirmation deadline.
So. I want if user change date2, date1 will automatically change
accordingly (same as input for date2). But whenever date1 is change, it
will effect itself only (only date1 change). Hopefully you can understand
this situation.
I think that this can be done using jquery, but i'am new in jquery, i hope
that you guys can help me. Thanks.

Global variable not staying set, maybe caused by fork()

Global variable not staying set, maybe caused by fork()

I'm trying to write a very very simple unix shell in C, and I have the
basics of what I need working, except support for a history command. I
have a global 2D char array that holds the history of all entered
commands. Commands are added before the fork() system call, and I was
originally printing out the value of the history global array after
strings were added, and they were printing out correctly, so I'm not sure
why it doesn't print out when the command "history" is used at the shell.
Thank to anyone who takes a look.
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "myhistory.h"
int BUFFER_SIZE = 1024;
char history[100][80];
int command_index = 0;
int main(int argc, char *argv[]){
int status = 0;
int num_args;
pid_t pid;
while(1){
char *buffer_input, *full_input;
char command[BUFFER_SIZE];
char *args[BUFFER_SIZE];
printf("myshell> ");
buffer_input = fgets(command, 1024, stdin);
full_input = malloc(strlen(buffer_input)+1);
strcpy(full_input, buffer_input);
if (command_index >= 100) {
command_index = 0;
}
strncpy(history[command_index], full_input, strlen(full_input) + 1);
command_index += 1;
parse_input(command, args, BUFFER_SIZE, &num_args);
//check exit and special command conditions
if (num_args==0)
continue;
if (!strcmp(command, "quit" )){
exit(0);
}
if(!strcmp(command, "history")){
int i;
fprintf(stderr,"%d\n",(int)pid);
for(i = 0; i < command_index; i++){
fprintf(stdout, "%d: %s\n",i+1,history[command_index]);
}
continue;
}
errno = 0;
pid = fork();
if(errno != 0){
perror("Error in fork()");
}
if (pid) {
pid = wait(&status);
} else {
if( execvp(args[0], args)) {
perror("executing command failed");
exit(1);
}
}
}
return 0;
}
void parse_input(char *input, char** args,
int args_size, int *nargs){
char *buffer[BUFFER_SIZE];
buffer[0] = input;
int i = 0;
while((buffer[i] = strtok(buffer[i], " \n\t")) != NULL){
i++;
}
for(i = 0; buffer[i] != NULL; i++){
args[i] = buffer[i];
}
*nargs = i;
args[i] = NULL;
}

Call to constant pointer-to-member function not being inlined

Call to constant pointer-to-member function not being inlined

Now, I know there are no guarantees for inlining, but...
Given the following:
struct Base {
virtual int f() = 0;
};
struct Derived : public Base {
virtual int f() final override {
return 42;
}
};
extern Base* b;
We have that:
int main() {
return static_cast<Derived*>(b)->f();
}
Compiles down to:
main:
movl $42, %eax
ret
Yet...
int main() {
return (static_cast<Derived*>(b)->*(&Derived::f))();
}
Compiles down to:
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $16, %esp
movl b, %eax
movl (%eax), %edx
movl %eax, (%esp)
call *(%edx)
leave
ret
Which is really saddening.
Why is that call to PMF not being inlined? The PMF is a constant expression!