The Insightful Troll

Rants and ruminations.

Beautiful Things Make Us Happier

| Comments

In collaboration with creative agency Sagmeister & Walsh, Kurzgesagt explores what beauty is and how it makes people happier. This Atlantic piece is a good companion piece that summarizes some of the research done about beauty’s connection to happiness.

The usual markers of happiness are colloquially known as the “Big Seven”: wealth (especially compared to those around you), family relationships, career, friends, health, freedom, and personal values, as outlined by London School of Economics professor Richard Layard in Happiness: Lessons from a New Science. According to the Goldberg study, however, what makess people happiest isn’t even in the Big Seven. Instead, happiness is most easily attained by living in an aesthetically beautiful city. The things people were constantly surrounded by — lovely architecture, history, green spaces, cobblestone streets — had the greatest effect on their happiness. The cumulative positive effects of daily beauty worked subtly but strongly.

See also Richard Feynman on Beauty.

On the Parkland Students

| Comments

Barack Obama, writing for Time magazine’s “Most Influential People of 2018” on Parkland, Florida students Cameron Kasky, Jaclyn Corin, David Hogg, Emma González, and Alex Wind:

America’s response to mass shootings has long followed a predictable pattern. We mourn. Offer thoughts and prayers. Speculate about the motives. And then — even as no developed country endures a homicide rate like ours, a difference explained largely by pervasive accessibility to guns; even as the majority of gun owners support commonsense reforms — the political debate spirals into acrimony and paralysis.

This time, something different is happening. This time, our children are calling us to account.

The Parkland, Fla., students don’t have the kind of lobbyists or big budgets for attack ads that their opponents do. Most of them can’t even vote yet.

But they have the power so often inherent in youth: to see the world anew; to reject the old constraints, outdated conventions and cowardice too often dressed up as wisdom.

The power to insist that America can be better.

Shortening URLs

| Comments

How to design a system that takes big URLs like “https://www.geeksforgeeks.org/count-sum-of-digits-in-numbers-from-1-to-n/%E2%80%9D 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 url. 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…

John Oliver on Bitcoin

| Comments

Watch this video as John Oliver explains BitCoin - everything you don’t understand about money combined with everything you don’t understand about computers.


I think blockchain will be a winner in all of this. Blockchain is a distributed, secure record store. Bitcoin as a currency will bomb. But the world is going to need a better explanation than this:

The way I like to think of it is a blockchain is a highly processed thing. Sort of like a chicken McNugget. And if you wanted to hack it, it would be like turning a chicken McNugget into a chicken. Now someday someone will be able to do that, but for now its going to be tough.

'Becoming' by Michelle Obama

| Comments

On November 23, Michelle Obama will release ‘Becoming’, a memoir by our former First Lady of the United States. I am surprised that they didn’t pick Amy Sherald’s portrait as the image for the book cover.

From the Amazon product description:

In her memoir, a work of deep reflection and mesmerizing storytelling, Michelle Obama invites readers into her world, chronicling the experiences that have shaped her—from her childhood on the South Side of Chicago to her years as an executive balancing the demands of motherhood and work, to her time spent at the world’s most famous address. With unerring honesty and lively wit, she describes her triumphs and her disappointments, both public and private, telling her full story as she has lived it—in her own words and on her own terms. Warm, wise, and revelatory, Becoming is the deeply personal reckoning of a woman of soul and substance who has steadily defied expectations—and whose story inspires us to do the same.

You you can preorder it here.

Solo - a Star Wars Story

| Comments

Disney has promised a new Star Wars story every year for the next 9 years, and so far they have hit it out of the park. Over the Super Bowl weekend - they realeased the new trailer for ‘Solo, a Star Wars Story.’



Falcon Heavy Launch

| Comments

My mind is still reeling from the SpaceX launch of Falcon Heavy yesterday. I can’t tell you why exactly, but when the two side boosters landed safely back on Earth at nearly the same instant, as in a beautifully choreographed ballet, I nearly lost it. Dawn of a new era indeed.



Of course, the boosters were supposed to land at the same time. They broke away from the main stage at the same time and were controlled by identical computer systems in their descent; it’s a simple matter of physics to solve for the time it takes two uniform objects to travel from point A to point B. But as Richard Feynman said about the beauty of a flower, knowing the science makes moments like this more wondrous.

Upgrading Rsync on MacOS X

| Comments

For some reason Apple ships an ancient version of rsync on MacOS X. I recently had to upgrade my version and it took me a while to figure it out. Here are the steps I came up with.

First, update Homebrew:

1
brew update

Add the new package source homebrew/dupes

1
brew tap homebrew/dupes

And finally, install rsync

1
brew install rsync

Whats that? You don’t brew? Go here

Purchasing a Gun

| Comments

I want any young men who by a gun to be treated like young women who seek an abortion. Think about it: a mandatory 48-hours waiting period, written permission from a parent or judge, a note from a doctor proving that he understands what he is about to do, time spent watching a video on individual and mass murders, traveling hundreds of miles at his own expense to the nearest gun shop, walking through protestors holding photo of loved ones killed by guns, and protestors who call him a murderer.

Gloria Steinhem

Is an Armed Society Free?

| Comments

Arendt offers two points that are salient to our thinking about guns: for one, they insert a hierarchy of some kind, but fundamental nonetheless, and thereby undermine equality. But furthermore, guns pose a monumental challenge to freedom, and particular, the liberty that is the hallmark of any democracy worthy of the name — that is, freedom of speech. Guns do communicate, after all, but in a way that is contrary to free speech aspirations: for, guns chasten speech.

This becomes clear if only you pry a little more deeply into the N.R.A.’s logic behind an armed society. An armed society is polite, by their thinking, precisely because guns would compel everyone to tamp down eccentric behavior, and refrain from actions that might seem threatening. The suggestion is that guns liberally interspersed throughout society would cause us all to walk gingerly — not make any sudden, unexpected moves — and watch what we say, how we act, whom we might offend.

Normalization of Gun Violence

| Comments

The regularity of mass killings breeds familiarity. The rhythms of grief and outrage that accompany them become — for those not directly affected by tragedy — ritualised and then blend into the background noise. That normalisation makes it ever less likely that America’s political system will groan into action to take steps to reduce their frequency or deadliness. Those who live in America, or visit it, might do best to regard them the way one regards air pollution in China: an endemic local health hazard which, for deep-rooted cultural, social, economic and political reasons, the country is incapable of addressing. This may, however, be a bit unfair. China seems to be making progress on pollution.

It is incredible that this was posted years ago and still nothing has changed. Not one damn thing.

Trump Is a Racist

| Comments

The President of the United States is an angry, resentful white supremacist. That’s been a nagging suspician to me ever since he started campaigning. But this week he moved it from a feeling to a fact. Today I woke up in an America where the president of the United States would not denounce Nazism.

Fucking Nazism !

If any good comes of this terrible week, it’s that more and more people are now seeing it, and are outraged by it.

GPS Distance

| Comments

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

| Comments

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.

Mossberg: The Disappearing Computer

| Comments

From his last column for Recode and The Verge:

This is my last weekly column for The Verge and Recode — the last weekly column I plan to write anywhere. I’ve been doing these almost every week since 1991, starting at the Wall Street Journal, and during that time, I’ve been fortunate enough to get to know the makers of the tech revolution, and to ruminate — and sometimes to fulminate — about their creations.

Now, as I prepare to retire at the end of that very long and world-changing stretch, it seems appropriate to ponder the sweep of consumer technology in that period, and what we can expect next.

I have been reading the various columns and stories by Walter Mossberg since my college days. Was on of the first people to really report and make sense of the computing revolution to the average person. Will be missed by many.

Good luck on whatever’s next, Walt.