Thursday, 3 October 2013

I don't know how to use a fuction of the Scanner classs

I don't know how to use a fuction of the Scanner classs

so I have to do a Flask Machine assignment and I have a small problem with
the scanner class. I created a method in which I want to add the bottle
types(A B or C) to an arraylist. So I don't really know how many bottles I
will enter. The thing is I want my scanning to stop once I encounter a
,,0". I know I have to use a while loop but using it like this doesn't
work because by the time I want to add the bottle to the list, it jumps to
the next scanned bottle.
While(input.next()!="0"){
list.add(input.next());
count++;
}

Wednesday, 2 October 2013

Activity com.example.mediastore.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView

Activity com.example.mediastore.LoginActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView

I have a loginActivity that will redirect me to userViewActivity, but I
got these errors:
10-03 00:50:11.628: E/WindowManager(1820): Activity
com.example.mediastore.LoginActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView{b558aee8 V.E.....
R.....ID 0,0-456,144} that was originally added here
10-03 00:50:11.628: E/WindowManager(1820): android.view.WindowLeaked:
Activity com.example.mediastore.LoginActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView{b558aee8 V.E.....
R.....ID 0,0-456,144} that was originally added here
10-03 00:50:11.628: E/WindowManager(1820): at
android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
10-03 00:50:11.628: E/WindowManager(1820): at
android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
10-03 00:50:11.628: E/WindowManager(1820): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
10-03 00:50:11.628: E/WindowManager(1820): at
android.app.Dialog.show(Dialog.java:281)
10-03 00:50:11.628: E/WindowManager(1820): at
com.example.mediastore.LoginActivity$userLogin.onPreExecute(LoginActivity.java:80)
10-03 00:50:11.628: E/WindowManager(1820): at
android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
10-03 00:50:11.628: E/WindowManager(1820): at
android.os.AsyncTask.execute(AsyncTask.java:534)
10-03 00:50:11.628: E/WindowManager(1820): at
com.example.mediastore.LoginActivity$1.onClick(LoginActivity.java:63)
10-03 00:50:11.628: E/WindowManager(1820): at
android.view.View.performClick(View.java:4202)
10-03 00:50:11.628: E/WindowManager(1820): at
android.view.View$PerformClick.run(View.java:17340)
10-03 00:50:11.628: E/WindowManager(1820): at
android.os.Handler.handleCallback(Handler.java:725)
10-03 00:50:11.628: E/WindowManager(1820): at
android.os.Handler.dispatchMessage(Handler.java:92)
10-03 00:50:11.628: E/WindowManager(1820): at
android.os.Looper.loop(Looper.java:137)
10-03 00:50:11.628: E/WindowManager(1820): at
android.app.ActivityThread.main(ActivityThread.java:5039)
10-03 00:50:11.628: E/WindowManager(1820): at
java.lang.reflect.Method.invokeNative(Native Method)
10-03 00:50:11.628: E/WindowManager(1820): at
java.lang.reflect.Method.invoke(Method.java:511)
10-03 00:50:11.628: E/WindowManager(1820): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-03 00:50:11.628: E/WindowManager(1820): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-03 00:50:11.628: E/WindowManager(1820): at
dalvik.system.NativeStart.main(Native Method)
and here is the loginActivity:
package com.example.mediastore;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import com.example.mediastore.JSONParser;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.InputFilter.LengthFilter;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends Activity {
Button login;
EditText inputusername;
EditText inputpassword;
private static String url_users =
"http://10.0.2.2/mediastore/android/usersLogin.php";
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static final String TAG_SUCCESS = "success";
@Override
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
login = (Button) findViewById(R.id.loginbtn);
inputusername = (EditText) findViewById(R.id.username);
inputpassword = (EditText) findViewById(R.id.password);
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(v == login) {
login.setBackgroundDrawable(getResources().getDrawable(R.drawable.button2));
}
String u = inputusername.getText().toString();
String p = inputpassword.getText().toString();
if(u.equals("")||p.equals(""))
Toast.makeText(getApplicationContext(), "Please fill
these two fields", Toast.LENGTH_SHORT).show();
else
new userLogin().execute();
}
});
}
class userLogin extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Logging user..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Creating product
* */
@SuppressLint("ShowToast")
protected String doInBackground(String... args) {
String username = inputusername.getText().toString();
String password = inputpassword.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_users,
"POST", params);
// check log cat fro response
Log.d("Login Response", json.toString());
// check for success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully created product
Intent i = new Intent(getApplicationContext(),
UserViewActivity.class);
startActivity(i);
// closing this screen
finish();
} else {
// failed to create product
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
}
}
}
I'am not familiar too much with android, can you help me to find a
solution for this problem please?

C# - Gradient over picture in picturebox

C# - Gradient over picture in picturebox

I have developed an application in VB.NET that I'm now moving over to C#.
Everything is going smooth so far, but I'm facing one problem.
I have a pictureBox that has a picture in it. Over this picture box I want
a gradient to be that goes from transparent at top down to the color
"control" to blend in with the forms background color. I have allready
done this in VB.net which works, but when im trying to do this in C# the
gradient seems to be drawn, but behind the picture.
Here is what i have tried:
private void PictureBox1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Color top = Color.Transparent;
Color bottom = Color.FromKnownColor(KnownColor.Control);
GradientPictureBox(top, bottom, ref PictureBox1, e);
}
public void GradientPictureBox(Color topColor, Color bottomColor, ref
PictureBox PictureBox1, System.Windows.Forms.PaintEventArgs e)
{
LinearGradientMode direction = LinearGradientMode.Vertical;
LinearGradientBrush brush = new
LinearGradientBrush(PictureBox1.DisplayRectangle, topColor,
bottomColor, direction);
e.Graphics.FillRectangle(brush, PictureBox1.DisplayRectangle);
brush.Dispose();
}
However this does in fact seem to work, but again it paints the gradient
behind the picture. In VB.net it painted it on top of the picture without
any extra code..
Do i need to add anything extra?
If it matters im coding in C# 2010 express.

How to implement smooth seeking in video with AVPlayer?

How to implement smooth seeking in video with AVPlayer?

When I seek to time with AVPlayer and a slider I get choppy results.
Seeking backwards stutters and lags a lot but seeking forwards is smooth.
[player seekToTime:CMTimeMakeWithSeconds(targetSeekTime, NSEC_PER_SEC)
toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
Built-in camera app has much smoother seeking. Maybe there is a setting?

legend placement issue in D3 Bar chart

legend placement issue in D3 Bar chart

I have a stacked bar chart. I want to place the legend, just above the
chart area ends and in centre like this
I have created a Fiddle HereLegend Fiddle
But I am facing issue in locating the legend at correct dimension. I know
some issue in
.attr("transform", function(d, i) { return "translate(-180," + i * 20 +
")"; });
Could you please help in placing legend at right location. Thanks Gunjan

Tuesday, 1 October 2013

A little confusion about compactness and connectedness

A little confusion about compactness and connectedness

This question may be a bit simple or even naive for some people but it
indeed confuses me for a long time. Thank you all if you provide any
explanation.
I know concepts: compactness means any open cover have finite subcover,
which is equivalent to bounded close; connectedness means there's no
disjoint decomposition by two nonempty open sets. However, I have no idea
how they play roles in particular cases. I read many theorems that require
compact and connected topology but there's no any mention in their proofs.
The situation occurs frequently, as far as I concern, in differential
geometry and multivariable calculus (vector fields). Could anyone explain
to me how they involve in mathematics? A few examples are better welcomed.

wpf mvvm datagrid loses sort when context recreated

wpf mvvm datagrid loses sort when context recreated

I have a wpf application built with MVVM light that uses entity framework
as the model.
Background:
My view model has a context that I use to populate a datagrid in the view.
I have a "navigation service" I built that changes what view/viewmodels
are displayed. As part of this navigation service I trigger an event that
the viewmodel uses to refresh the record of the datagrid in the viewmodel
before the requested view is displayed to the user.
Problem:
If the user has sorted the datagrid by clicking on a column heading, that
sorting is lost when I refresh the records. I want to maintain the
datagrid sroting when I drop and recreate the context.
Example:
here is the stripped down version of my refresh records function in the
view model:
Context = Nothing
Context = _ModelService.NewContext
InStockCollection = Await
_TrackingService.GetTracking_Stock_AllAsync(Context)
InStockCollectionViewSource.Source = InStockCollection
here is the declaration of the datagird in the paired view:
<DataGrid x:Name="StockDataGrid"
Grid.Column="1" Grid.Row="4" Grid.ColumnSpan="3"
ItemsSource="{Binding
InStockCollectionViewSource.View,
IsAsync=True}"
CanUserAddRows="False"
CanUserDeleteRows="False"
SelectionMode="Single"
SelectedItem="{Binding SelectedInStock,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
VirtualizingStackPanel.IsVirtualizing="True"
RowHeight="49">
QUESTION:
How can I capture the current sorted value of the datagird in the view
model (i am confortable adding sorting descriptioins to the
collectionviewsource in the code, I just cant figure out how to tell what
sort is currently applied)
OR
Or how can I maintain the sort of the datagrid when the context of the
collectionviewsource is dropped and recreated.
thanks in advance

VPS apache config - Invalid command 'PassengerDefaultRuby' after adding latest passenger gem

VPS apache config - Invalid command 'PassengerDefaultRuby' after adding
latest passenger gem

used to have this list of rubies in my vps:
ruby-1.9.2-p320 [ i686 ]
=* ruby-1.9.3-p194 [ i686 ]
ruby-1.9.3-p374 [ i686 ]
ruby-1.9.3-p392 [ i686 ]
today I installed a new app on this vps on ruby 2.0, so I added 2.0 to rvm:
ruby-1.9.2-p320 [ i686 ]
ruby-1.9.3-p194 [ i686 ]
ruby-1.9.3-p374 [ i686 ]
ruby-1.9.3-p392 [ i686 ]
=* ruby-2.0.0-p247 [ i686 ]
installed passenger and passenger-apache-module, instructions says to add
these lines:
LoadModule passenger_module
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.19
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby
to /etc/apache2/apache2.conf and restart apache, after restart I got this
error:
Syntax error on line 242 of /etc/apache2/apache2.conf:
Invalid command 'PassengerDefaultRuby', perhaps misspelled or defined by a
module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
...fail!
and one more problem, when I open my app at http://nccm.md I got:
Could not find rake-10.1.0 in any of the sources (Bundler::GemNotFound)
from gem list command I can see this gem is installed in ruby 2.0
environment, but the app looks for it in
usr/local/rvm/gems/ruby-1.9.3-p194@global and not in
ruby-2.0.0-p247@global. Why is that? Thank you for any help.

How can I add a cultural game mechanic to Pathfinder=?iso-8859-1?Q?=3F_=96_rpg.stackexchange.com?=

How can I add a cultural game mechanic to Pathfinder? – rpg.stackexchange.com

I was reading this article on how most people play all races exactly the
same. The author hinted at replacing races in Pathfinder with a culture
mechanic, but didn't really go into the details. I …