Search Results

Search found 2 results on 1 pages for 'techgeeky'.

Page 1/1 | 1 

  • Algorithm for redirecting the traffic

    - by TechGeeky
    I was going through the interview questions and found out the below question which I am not able to answer it. Can anyone provide some sort of algorithm for this problem how can I solve it? There are a cluster of stateless servers all serving the same pages. The servers are hosting 5 web pages- p1.html, p2.html, p3.html, p4.html and p5.html p1.html just redirects users to the other 4 pages Requests to p1.html should result in 10% of users being redirected to p2.html, 5% of users redirected to p3.html, 20% of users redirected to p4.html, and 65% of users redirected to p5.html. Users do not need to stick to the page they are first redirected to. They could end up on a different page with every request to p1.html Write a function/pseudocode that would be invoked with every request to p1.html and redirect the correct percentage of users to the correct page. Any suggestions will be of great help.

    Read the article

  • Draw Circle on the Map once the application gets loaded

    - by TechGeeky
    Background:- In my application what is happening currently- Whenever I am opening the application, In the top half of the android screen, it draws a Map and in the bottom half of the android screen it show's a list view. And then as soon as the location gets changed, it draw's a Circle with the current location as the center of the circle and show's an image at the current location(center of circle). Everything is working fine till here- Problem Statement:- What I want is when the user opens my application, circle should get draw immediately on the Google Map (this is currently not happening, it draw's circle only on the location changed), without waiting for the location to get changed and without any image on the center of circle and then if the location get's changed, take the current location as the center of circle and draw the circle with an image at the center of circle. And this is my below code which fulfills the scenario that I mentioned in my Background- How can I make this code to work the way I wanted to? hope I am clear enough in my question. Any suggestions will be appreciated. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mapView = (MapView) findViewById(R.id.mapView); listView = (ListView) findViewById(R.id.mylist); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new GPSLocationListener(mapView); locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 35000, 10, locationListener); mapView.setStreetView(true); mapView.setBuiltInZoomControls(true); mapController = mapView.getController(); mapController.setZoom(14); } Location Update class where I am sending the request to Overlay to draw the circle private class GPSLocationListener implements LocationListener { MapOverlay mapOverlay; public GPSLocationListener(MapView mapView) { } @Override public void onLocationChanged(Location location) { if (location != null) { GeoPoint point = new GeoPoint( (int) (location.getLatitude() * 1E6), (int) (location.getLongitude() * 1E6)); mapController.animateTo(point); mapController.setZoom(15); if (mapOverlay == null) { mapOverlay = new MapOverlay(this,android.R.drawable.star_on); List<Overlay> listOfOverlays = mapView.getOverlays(); listOfOverlays.add(mapOverlay); } mapOverlay.setPointToDraw(point); mapView.invalidate(); } } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } } Class in which circle is getting drawn. class MapOverlay extends Overlay { private GeoPoint pointToDraw; int[] imageNames=new int[6]; private Point mScreenPoints; private Bitmap mBitmap; private Paint mCirclePaint; public MapOverlay(GPSLocationListener gpsLocationListener, int currentUser) { imageNames[0]=currentUser; mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mCirclePaint.setColor(0x30000000); mCirclePaint.setStyle(Style.FILL_AND_STROKE); mBitmap = BitmapFactory.decodeResource(getResources(),imageNames[0]); mScreenPoints = new Point(); } public void setPointToDraw(GeoPoint point) { pointToDraw = point; } public GeoPoint getPointToDraw() { return pointToDraw; } @Override public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); if (pointToDraw == null) { return true; } mScreenPoints = mapView.getProjection().toPixels(pointToDraw, mScreenPoints); int totalCircle=5; int radius=40; int centerimagesize=35; for (int i = 1; i <= totalCircle; i ++) { canvas.drawCircle(mScreenPoints.x,mScreenPoints.y, i*radius, mCirclePaint); } canvas.drawBitmap(mBitmap, (mScreenPoints.x-(centerimagesize/2)),(mScreenPoints.y-(centerimagesize/2)), null); super.draw(canvas,mapView,shadow); return true; } }

    Read the article

1