The Insightful Troll

Rants and Ruminations.

Google Fined €4.3 Billion Euro

From the European Commission press release:

The European Commission has fined Google €4.34 billion for breaching EU antitrust rules. Since 2011, Google has imposed illegal restrictions on Android device manufacturers and mobile network operators to cement its dominant position in general internet search

...

In particular, Google:

* has required manufacturers to pre-install the Google Search app and browser app (Chrome), as a condition for licensing Google's app store (the Play Store);

* made payments to certain large manufacturers and mobile network operators on condition that they exclusively pre-installed the Google Search app on their devices; and

* has prevented manufacturers wishing to pre-install Google apps from selling even a single smart mobile device running on alternative versions of Android that were not approved by Google (so-called "Android forks")

Good for the EU to stand up to Google.

This is the same thing that Microsoft pulled in the US with using its monopoly power to require Internet Explorer in every PC the 90s. That got them charged as a abusive monopoly.

Funny how history repeats itself…

What Does Putin Have on Trump?

As Josh Marshall, writes at TPM:

There is no reasonable explanation for the simple facts we see other than that Russia has some kind of hold over President Trump.

I would really like to know is what Putin has on him. I have no doubt that he has the so called pee tape - but judging from past history, that might not sink him with his supporters.

Its about the money. I think Putin and the Russian oligarchs has given him so much financial support and loans, and they can pull them back at any time. His and his family’s entire wealth is probably tied up with the Russians. Eric Trump admitted it in an interview with James Dodson:

"So when I got in the cart with Eric," Dodson says, "as we were setting off, I said, 'Eric, who’s funding? I know no banks — because of the recession, the Great Recession — have touched a golf course. You know, no one’s funding any kind of golf construction. It’s dead in the water the last four or five years.' And this is what he said. He said, 'Well, we don’t rely on American banks. We have all the funding we need out of Russia.' I said, 'Really?' And he said, 'Oh, yeah. We’ve got some guys that really, really love golf, and they’re really invested in our programs. We just go there all the time.' Now that was [a little more than] three years ago, so it was pretty interesting."

Whatever it is, lets hope Muller gets to the bottom of it.

She Was Right


Hillary Clinton’s remarks during a 2016 debate on Donald Trump being a “puppet” of Vladimir Putin have proven depressingly spot-on:

  • Trump won’t admit Russians have engadged in cyber attacks against United States of America
  • Encouraged espionage against our people
  • Break up NATO
  • Continue to get help from him

All of this is now irrefutable with Trump’s performance on Friday in Helsinki, Finland. The question now before us is what do we do with a President that is not putting America first?For anything to happen - we will have to wait and see if the Republicans will finally grow a spine.

Smells Like Collusion

The most over looked part of todays new Mueller indictment.

43. Between in or around June 2016 and October 2016, the Conspirators used Guccifer 2.0 to release documents through WordPress that they had stolen from the DCCC and DNC. The Conspirators, posing as Guccifer 2.0, also shared stolen documents with certain individuals.

a. On or about August 15, 2016, the Conspirators, posing as Guccifer 2.0, received a request for stolen documents from a candidate for the U.S. Congress. The Conspirators responded using the Guccifer 2.0 persona and sent the candidate stolen documents related to the candidate?s opponent.

Read that quote again – received a request for stolen documents from a candidate for the U.S. Congress – that is collusion if I ever heard of it. We don’t know who the U.S. Congress member is, but I would expect a list of indictments citing Americans in short order.

Rich Are More Lucky Then Smart

Paul Solman reports that at pbs.org reports that maybe, just maybe, being wealthy is just a matter of being lucky.

Yes, it’s the good old “bell curve”: the “normal distribution.” Most human traits are arrayed along it. But wealth, the authors write, follows something called a power law, also sometimes called the “80/20 rule,” with a vast majority of poor people and a very small number of billionaires. The richest eight men having wealth equal to something like 3+ billion of the world’s poorest would be an extreme but telling example.

But think about it, the authors suggest. If smarts and talents and even effort are so normally distributed and wealth is so abnormally distributed, what’s missing to explain the disparity?

Sure hard work, risk taking and talent have a lot to do with it. But plenty of people have those. In a paper A. Pluchino, A. E. Biondo, and A. Rapisarda they set forth a mathematical proof for - simply being lucky. While I don’t have enough of a mathematical rigerous background to argue with them, I tend to think it is the environment you grow up in that has the highest impact.

The Fifth Hyperfactorial


Close. But not exactly - one day isn’t exactly 86400000 milliseconds, it’s actually a few milliseconds more. To be percise its 8.64+7

John Carmack on Steve Jobs

An interesting post by Doom and Quake developer John Carmack.

My first impression of “Keynote Steve” was him berating the poor stage hands over “This Home Depot shit” that was rolling out the display stand with the new Mac, very much not to his satisfaction. His complaints had a valid point, and he improved the quality of the presentation by caring about details, but I wouldn’t have wanted to work for him in that capacity.

One time, my wife, then fiancée, and I were meeting with Steve at Apple, and he wanted me to do a keynote that happened to be scheduled on the same day as our wedding. With a big smile and full of charm, he suggested that we postpone it. We declined, but he kept pressing. Eventually my wife countered with a suggestion that if he really wanted “her” John so much, he should loan John Lassiter to her media company for a day of consulting. Steve went from full charm to ice cold really damn quick. I didn’t do that keynote.

Its always striking how much of a jerk Steve Jobs was. Sure he founded Apple and helped create all the gadgets we love, but is being a jerk really necessary trait for success?

Shortening URLs

How to design a system that takes big URLs like https://www.geeksforgeeks.org/count-sum-of-digits-in-numbers-from-1-to-n and converts them into a short 6 character URL. It is given that URLs are stored in database and every URL has an associated integer id.

One important thing to note is, the long URL should also be uniquely identifiable from short URLs. So we need a Bijective Function.

One Simple Solution could be Hashing. Use a hash function to convert long string to short string. In hashing, that may be collisions (2 long URLs map to same short URL) and we need a unique short URL for every long URL so that we can access long URL back.

A Better Solution is to use the integer id stored in database and convert the integer to character string that is at most 6 characters long. This problem can basically seen as a base conversion problem where we have a 10 digit input number and we want to convert it into a 6 character long string.

Below is one important observation about possible characters in URL.

A URL character can be one of the following:

  1. A lower case alphabet [‘a’ to ‘z’], total 26 characters
  2. An upper case alphabet [‘A’ to ‘Z’], total 26 characters
  3. A digit [‘0’ to ‘9’], total 10 characters

There are total 26 + 26 + 10 = 62 possible characters.

So the task is to convert a decimal number to base 62 number.

To get the original long URL, we need to get URL id in database. The id can be obtained using base 62 to decimal conversion.

Here is some code in ruby that implements a Base62 encoder and decoder:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Base62
  CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".chars
  BASE = 62

  def self.encode(value)
    s = []
    while value >= BASE
      value, rem = value.divmod(BASE)
      s << CHARS[rem]
    end
    s << CHARS[value]
    s.reverse.join("")
  end

  def self.decode(str)
    str = str.split('').reverse
    total = 0
    str.each_with_index do |v,k|
      total += (CHARS.index(v) * (BASE ** k))
    end
    total
  end
end

And here is an example:

1
2
3
4
5
6
irb(main):001:0> n=12345
=> 12345
irb(main):002:0> shorturl = Base62::encode(n)
=> "3d7"
irb(main):003:0> t = Base62::decode(shorturl)
=> 12345

Stay tuned for a simple personal URL manager coming shortly…

GPS Distance

I recently had to calculate the distance between a large number of co-ordinates. I could have used one of the many Ruby Gems that are available but due to business limitations had to develop the code myself. After some research I came across the haversine formula.

The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes. It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the sides and angles of spherical triangles.

You can read the full details on the maths here. For those who just want the code here is the implemenation I came up with:

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
module GPS
  class Distance
    RAD_PER_DEG = Math::PI / 180
    GREAT_CIRCLE_RADIUS_MILES = 3956
    GREAT_CIRCLE_RADIUS_KILOMETERS = 6371 # some algorithms use 6367
    GREAT_CIRCLE_RADIUS_FEET = GREAT_CIRCLE_RADIUS_MILES * 5280
    GREAT_CIRCLE_RADIUS_METERS = GREAT_CIRCLE_RADIUS_KILOMETERS * 1000
    GREAT_CIRCLE_RADIUS_NAUTICAL_MILES = GREAT_CIRCLE_RADIUS_MILES / 1.15078

    attr_accessor :great_circle_distance
    attr_accessor :point1
    attr_accessor :point2

    def initialize(great_circle_distance = 0)
      @great_circle_distance = great_circle_distance
      @point1 = [0,0]
      @point2 = [0,0]
    end

    def to_miles
      calculate
      @great_circle_distance * GREAT_CIRCLE_RADIUS_MILES
    end
    alias_method :to_mi, :to_miles

    def to_kilometers
      calculate
      @great_circle_distance * GREAT_CIRCLE_RADIUS_KILOMETERS
    end
    alias_method :to_km, :to_kilometers

    def to_meters
      calculate
      @great_circle_distance * GREAT_CIRCLE_RADIUS_METERS
    end
    alias_method :to_m, :to_meters

    def to_feet
      calculate
      @great_circle_distance * GREAT_CIRCLE_RADIUS_FEET
    end
    alias_method :to_ft, :to_feet

    def to_nautical_miles
      calculate
      @great_circle_distance * GREAT_CIRCLE_RADIUS_NAUTICAL_MILES
    end
    alias_method :to_nm, :to_nautical_miles

    private

    # Radians per degree
    def rpd(num)
      num * RAD_PER_DEG
    end

    def calculate
      # Accept two arrays of points in addition to four coordinates
      if point1.is_a?(Array) && point2.is_a?(Array)
        lat2, lon2 = point2
        lat1, lon1 = point1
      elsif
        raise ArgumentError
      end
      dlon = lon2 - lon1
      dlat = lat2 - lat1
      a = (Math.sin(rpd(dlat)/2))**2 + Math.cos(rpd(lat1)) * Math.cos((rpd(lat2))) * (Math.sin(rpd(dlon)/2))**2
      @great_circle_distance = 2 * Math.atan2( Math.sqrt(a), Math.sqrt(1-a))
    end
  end
end

Here is a quick script on how to use it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
irb(main):001:0> d = GPS::Distance.new
=> #<GPS::Distance:0x007fb93b036050 @great_circle_distance=0, @point1=[0, 0], @point2=[0, 0]>
irb(main):002:0> d.point1 = [40.7457395,-73.991623]
=> [40.7457395, -73.991623]
irb(main):003:0> d.point2 = [40.9176771,-74.2082467]
=> [40.9176771, -74.2082467]
irb(main):004:0> d.to_meters
=> 26413.70207758391
irb(main):005:0> d.to_kilometers
=> 26.413702077583906
irb(main):006:0> d.to_miles
=> 16.40128793265138
irb(main):007:0> d.to_feet
=> 86598.80028439929
irb(main):008:0>

Hope this helps. If you have any questions, or comments feel free to leave a message or contact me directly.

Senators Propose Bug Bounties

Reminds me of this Dilbert cartoon I read years ago (accept I would code me a Tesla):

 - Dilbert by Scott Adams

From CNN:

U.S. senators want people to hack the Department of Homeland Security. On Thursday, Senators Maggie Hassan, a Democrat and Republican Rob Portman introduced the Hack DHS Act to establish a federal bug bounty program in the DHS... It would be modeled off the Department of Defense efforts, including Hack the Pentagon, the first program of its kind in the federal government. Launched a year ago, Hack the Pentagon paved the way for more recent bug bounty events including Hack the Army and Hack the Air Force...

The Hack the DHS Act establishes a framework for bug bounties, including establishing "mission-critical" systems that aren't allowed to be hacked, and making sure researchers who find bugs in DHS don't get prosecuted under the Computer Fraud and Abuse Act. "It's better to find vulnerabilities through someone you have engaged with and vetted," said Jeff Greene, the director of government affairs and policy at security firm Symantec. "In an era of constrained budgets, it's a cost-effective way of identifying vulnerabilities"... If passed, it would be among the first non-military bug bounty programs in the public sector.