Saturday, November 18, 2017

The CIA's Pokemon Go App is Doing What the Patriot Act Can't


The CIA's Pokemon Go App is Doing What the Patriot Act Can't

The maker of the app? Niantic Labs. Never heard of them? That’s because until last year they were an internal start-up of none other than Google, the NSA-linked Big Brother company. Even now Google remains one of Niantic’s major backers. Niantic was founded by John Hanke, who also founded Keyhole, Inc., the mapping company which was created with seed money from In-Q-Tel, the CIA’s venture capital arm, and which was eventually rolled into Google Maps.


Apparently, many pokestops  are clustered around many embassies.

from July 13, 2016 (old news but new to me)

https://www.corbettreport.com/the-cias-pokemon-go-app-is-doing-what-the-patriot-act-cant/

Wednesday, November 15, 2017

C# Integer division try...catch vs casting vs if divisor not zero speed test, which is quicker?

Below is a performance analysis of C# .NET integer division comparing; 
  1. try...catch (DivideByZeroException)
  2. casting numerator (the number on top) to double
  3. if denominator (the number on bottom) not equal to zero
The console application code loops 1 million times and run using .NET 4.0 Framework (works on XP+) and timings (ticks) are indicated in the comments. The 2nd number in using .NET 4.6 Framework (Vista+). There is no significant improvement switching frameworks.

Answer: 

Casting (double)ttlcnt beats try...catch by 1 order O(1) of magnitude. 

But the winner is the if divisor not zero statement  beating casting by 6,000 nanoseconds.

FYI: Ticks are 100 nanoseconds long. There are 10,000,000 (10M) per second.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace CastVSCatch
{
    class Program
    {
        static void Main(string[] args)
        {
           
            int million = 1000000; 
            int ttlcnt = 228394393;
            int pct = 0;
            var sw = Stopwatch.StartNew();

            for (int i = 0; i < million; i++)
            {

                //pct = (int)(100 * ((double)ttlcnt / i));  //~16,800 ticks //17,020 ticks in NETt4.6

                //try
                //{
                //    pct = 100 * (ttlcnt / i); //~=151,359  ticks   //147,531  in NET4.6
                //}
                //catch (DivideByZeroException)
                //{
                //    pct = 0;
                //}

                if (i != 0)
                    pct = 100 * (ttlcnt / i); //~=10,816 ticks 
                else
                    pct = 0;

                //if (i == 0)
                //    pct = 0;
                //else
                //    pct = 100 * (ttlcnt / i); //~=11,162 ticks 

            }

            sw.Stop(); 

            Console.WriteLine("pct=" + pct.ToString()+" in ticks="+sw.ElapsedTicks);

            if (Debugger.IsAttached)
                Console.ReadKey(); 
        }
    }
}
>

Monday, November 13, 2017

Parallel Searcher make your own Windows Grep app

Here's a non-block UI thread c# WPF full Visual Studio solution that works and demonstrates the use of a background worker effectively, Parallel Searcher. 

This project is a great demonstration of the use of the BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running. When you want a responsive UI and you are faced with long delays associated with such operations, the BackgroundWorker class provides a convenient solution.

Parallel Searcher is like grep for windows and is a fun project to play with and easy to modify. The author Randy makes this code available license free.

Searched over 5,000 files in a couple of seconds!

Highlights of Code

  1. Parallel.ForEach - allows you to easily do the same thing to every list item
  2. Interlocked.Increment - allows you to add to a number, thread-safe
  3. Sample usage of Tuples - pack several variables into a single object
  4. ObservableCollection - allows you to continually add to a Grid ItemsSource in WPF
  5. Progress Bar - shows file status loading asynchronously
  6. Background worker - waiting for long task to finish and not block the GUI


More at Randy's site - https://actualrandy.wordpress.com/tag/observablecollection/