Saturday, 28 September 2013

declaring a variable within conditional expressions (ternary operator)

declaring a variable within conditional expressions (ternary operator)

Is it possible to declare the variable within a conditional expression?
for example: The code below return a syntax error (because I've declared
the variable x within the conditional expression?).
var a = document.getElementById("userData");
var d = a.value;
function() {
(d.length>15)?(
alert("your input was too long")):(
var x = parseInt(d).toString(2),
a.value=x
);
}
obviously this can be fixed by simply adding var x; outside the statement,
but is it possible for variables to be declared here?

Why files creatied with Java FileOutputStream on Android are visible on my pc throught USB after few ubs reconnectonions (+up to few...

Why files creatied with Java FileOutputStream on Android are visible on my
pc throught USB after few ubs reconnectonions (+up to few...

I have code like this: File file = new
File(Environment.getExternalStorageDirectory(), fileName);
FileOutputStream os = null; try { os = new FileOutputStream(file); } catch
(FileNotFoundException e) { System.err.println("Error while creating
FileOutputStream"); e.printStackTrace(); }
os.write("something".getBytes());
and when i create file on my HTC desire x i have to disconnect usb, wait
few minutes, connect it again to see it in windows explorer. Why it's like
that? And how can i prevent it?

Buses scheduling - relational database or nosql

Buses scheduling - relational database or nosql

I'm trying to store buses schedules into database and I'm wondering which
database model is suitable for my case.
I have bus operators, each operator has several routes, each route has
several turns, each turn has stops, etc. Turns are generated from
something called "turn master" where the scheduling is defined (frequency,
stops, etc.) within next N days.
I expect to deliver a very fast searching for bus when user tries to
search a bus from city to city on given date.
I'm using MySQL, the number of stops reach around 100.000 records and the
searching speed is fast but I'm not sure if it's still fast when data gets
really big (thousand operators, each operator has hundreses turns, each
turn has around 10 stops, turns are generated for around next 30 days).
Basically, performing a search is to look for stop (city/town/place, time)
and check if it matches user search criteria.
So, my question is: Is relational database is best in this case? Or using
some kind of NoSQL will be better when the data get really bigs?
Thanks in advance,

Friday, 27 September 2013

Xcode5 build failed

Xcode5 build failed

I am a newbie and sorry about my english!- -!
I update my Xcdoe4.* to Xcode5,After that I cretate a helloworld project.
I launche Xcode and click "create a new Xcode project" and then select
"Single View Application" and click "next".After type product name,I click
"next" again and then "create". and I get this
I click the rectangle button left-top in the window to run the app,the
Xcode tell me "Build failed",and now i get this
very sorry about my english,Is anyone can help

Hartl Chapter Error Before 9.1.3

Hartl Chapter Error Before 9.1.3

I'm going through Mr. Hartl's Tutorial and trying to copy it exactly, even
kinda using his completed github code as a guide, but I'm stuck with the
following after running the "bundle exec rspec spec/":

Failures:
1) Authentication signin with valid information
Failure/Error: before { sign_in user }
ActionView::MissingTemplate:
Missing template sessions/create, application/create with
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder,
:raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/home/nemo/rails_projects/sample_app/app/views"
# ./spec/support/utilities.rb:19:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:32:in `block (4
levels) in <top (required)>'
2) Authentication signin with valid information
Failure/Error: before { sign_in user }
ActionView::MissingTemplate:
Missing template sessions/create, application/create with
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder,
:raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/home/nemo/rails_projects/sample_app/app/views"
# ./spec/support/utilities.rb:19:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:32:in `block (4
levels) in <top (required)>'
3) Authentication signin with valid information
Failure/Error: before { sign_in user }
ActionView::MissingTemplate:
Missing template sessions/create, application/create with
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder,
:raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/home/nemo/rails_projects/sample_app/app/views"
# ./spec/support/utilities.rb:19:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:32:in `block (4
levels) in <top (required)>'
4) Authentication signin with valid information
Failure/Error: before { sign_in user }
ActionView::MissingTemplate:
Missing template sessions/create, application/create with
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder,
:raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/home/nemo/rails_projects/sample_app/app/views"
# ./spec/support/utilities.rb:19:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:32:in `block (4
levels) in <top (required)>'
5) Authentication signin with valid information
Failure/Error: before { sign_in user }
ActionView::MissingTemplate:
Missing template sessions/create, application/create with
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder,
:raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/home/nemo/rails_projects/sample_app/app/views"
# ./spec/support/utilities.rb:19:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:32:in `block (4
levels) in <top (required)>'
6) Authentication signin with valid information followed by signout
Failure/Error: before { sign_in user }
ActionView::MissingTemplate:
Missing template sessions/create, application/create with
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder,
:raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/home/nemo/rails_projects/sample_app/app/views"
# ./spec/support/utilities.rb:19:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:32:in `block (4
levels) in <top (required)>'
7) User pages profile page signup with valid information after saving
the user
Failure/Error: before { visit user_path(user) }
AbstractController::ActionNotFound:
The action 'index' could not be found for UsersController
# ./spec/requests/user_pages_spec.rb:16:in `block (3 levels) in <top
(required)>'
8) User pages profile page signup with valid information after saving
the user
Failure/Error: before { visit user_path(user) }
AbstractController::ActionNotFound:
The action 'index' could not be found for UsersController
# ./spec/requests/user_pages_spec.rb:16:in `block (3 levels) in <top
(required)>'
9) User pages profile page signup with valid information after saving
the user
Failure/Error: before { visit user_path(user) }
AbstractController::ActionNotFound:
The action 'index' could not be found for UsersController
# ./spec/requests/user_pages_spec.rb:16:in `block (3 levels) in <top
(required)>'
10) User pages profile page with invalid information
Failure/Error: before { click_button "Save changes" }
Capybara::ElementNotFound:
Unable to find button "Save changes"
# ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top
(required)>'
11) User pages profile page page
Failure/Error: it { should have_content("Update your profile") }
expected #has_content?("Update your profile") to return true, got
false
# ./spec/requests/user_pages_spec.rb:70:in `block (4 levels) in <top
(required)>'
12) User pages profile page page
Failure/Error: it { should have_title("Edit user") }
expected #has_title?("Edit user") to return true, got false
# ./spec/requests/user_pages_spec.rb:71:in `block (4 levels) in <top
(required)>'
13) User pages profile page page
Failure/Error: it { should have_link('change', href:
'http://gravatar.com/emails') }
expected #has_link?("change",
{:href=>"http://gravatar.com/emails"}) to return true, got false
# ./spec/requests/user_pages_spec.rb:72:in `block (4 levels) in <top
(required)>'
Finished in 1.83 seconds
53 examples, 13 failures

spec/requests/authentication_pages_spec.rb:
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_content('Sign in') }
it { should have_title('Sign in') }
end
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_title('Sign in') }
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
describe "after visiting another page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
it { should have_title(user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Settings', href: edit_user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
describe "followed by signout" do
before { click_link "Sign out" }
it { should have_link('Sign in') }
end
end
end
end
spec/requests/user_pages_spec.rb
require 'spec_helper'
describe "User pages" do
subject { page }
describe "signup page" do
before { visit signup_path }
it { should have_content('Sign up') }
it { should have_title(full_title('Sign up')) }
end
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_content(user.name) }
it { should have_title(user.name) }
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "after submission" do
before { click_button submit }
it { should have_title('Sign up') }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user@example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by(email: 'user@example.com') }
it { should have_link('Sign out') }
it { should have_title(user.name) }
it { should have_selector('div.alert.alert-success', text:
'Welcome') }
end
end
end
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before { visit edit_user_path(user) }
end
describe "page" do
it { should have_content("Update your profile") }
it { should have_title("Edit user") }
it { should have_link('change', href: 'http://gravatar.com/emails') }
end
describe "with invalid information" do
before { click_button "Save changes" }
it { should have_content('error') }
end
end
end

write a code in a separate threads

write a code in a separate threads

Hello how can i write this code in a separate threads because i have an
intensive operations in my main thread.so i have to use an Async Activity
and delegate the network intensive operation to 'doInBackground'
method.but i don't know how to edit it
public void setImage(ImageView aView, URL aURL) {
try {
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
// Bufferisation pour le t&#65533;l&#65533;chargement
BufferedInputStream bis = new BufferedInputStream(is, 8192);
// Cr&#65533;ation de l'image depuis le flux des
donn&#65533;es entrant
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
// Fixe l'image sur le composant ImageView
aView.setImageBitmap(bm);
} catch (IOException e) {
aView.setImageDrawable(mNoImage);
Log.e("DVP Gallery", "Erreur t&#65533;l&#65533;chargement
image URL : " + aURL.toString());
e.printStackTrace();
}
}
please help me thanks

Which is the best approach to send large UDP packets in sequence

Which is the best approach to send large UDP packets in sequence

I have an android application that needs to send data through the protocol
UDP every 100 milliseconds. Each UDP packet has 15000 bytes average.
packets are sent in broadcast
Every 100 milliseconds lines below are run through a loop.
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length,
broadcast, 9876);
clientSocket.send(sendPacket);
Application starts working fine, but after about 1 minute frequency of
received packets decreases until the packets do not arrive over the
destination.
The theoretical limit (on Windows) for the maximum size of a UDP packet is
65507 bytes
I know the media MTU of a network is 1500 bytes and when I send a packet
bigger it is broken into several fragments and if a fragment does not
reach the destination the whole package is lost.
I do not understand why at first 1 minute the packets are sent correctly
and after a while the packets do not arrive more. So I wonder what would
be the best approach to solve this problem?