Wednesday, September 13, 2017

iPhone vs Android

When I first moved from Windows (ThinkPad) to Mac (Pro) in 2009, it was a life changing experience. I’ve been a huge fan of Steve Jobs ever since, and am on my third Mac (Air) now.

But it’s been almost two months now since I moved from my Nexus 5 to an iPhone SE; and even though the SE is a newer phone and has better hardware than the N5, it’s nearly been a disappointing experience.

No universal return button, no automatic favourites in calls, and constant network issues are just a few of the issues that come to mind.

Maybe iPhones were better earlier, and have suffered from Jobs’ absence. The Mac product lineup definitely has (the Air is a Jobs design).

But as of today, Android (vanilla) seems better in both usability and performance.

Monday, July 24, 2017

Delete Account Link on Facebook

Doesn't seem to be displayed on the site anymore.

The link is:
www.facebook.com/help/delete_account

Sunday, February 26, 2017

Get Unique Line Counts on Linux

cat Duplicates.txt | sort | uniq -c > Counts.txt

Friday, February 17, 2017

Drupal Contact Form - Missing or Disappearing Emails


Linux sendmail sometimes drops emails mysteriously without any error message or log of the written email.

/var/log/maillog will show an entries such as:
Unauthenticated email from xyz.com is not accepted due to [DMARC]

The way to fix this is to have the domain name of the current server in the from field, and the actual from address in the reply-to field.

This can easily be done with Drupal 7 using the contact_reply_to module. Drupal 8 does not require the module.

Monday, February 13, 2017

Drupal's Confusing Online Readme Text Files

Module pages usually say:
"The most complete and up to date documentation is included with the module, in the README.txt file."

But the online README.txt files linked to there usually include documentation for unreleased updates. This can cause considerable confusion / unnecessary trouble-shooting when newly installing modules.

Always use the README files included with the module, not the ones online.

Performance of Facebook promotions

Regarding the promoted post Quotes - Warren Buffett and Benjamin Graham.
Here are the top 10 duplicate shares on the post:

Lucious White - 28 shares
Ako Nai - 17 shares
Stephen Schreiber - 17 shares
Nathan Musikchild Ray - 9 shares
Farakhan Norris - 6 shares
Beau Forester - 5 shares
Dennis Vinci - 5 shares
Bob Holden - 4 shares
James Thomas Downey - 4 shares
T Donebullshidden Knight - 4 shares

These accounts have been observed sharing and liking other promoted posts too.

The total list of displayed shares is only 382, even though the displayed count is 1363.
Understandably, this is due to private shares.

But only 244 of the shares are by unique people.

[Support email #2]

As you can see, the high bounce rates are only for Facebook clicks.
The bounce rates for users from Google, Bing, Yahoo etc are much lower.

In any case, my concern is not the high bounce rate in itself.
That could be content and context specific.

My real concern is the large number of confirmed duplicate shares by
certain users. These duplicate shares have me worried about the authenticity of the
likes and clicks as well.

Monday, January 30, 2017

Drupal DDoS Prevention Code

// The following code will ensure that there are no more than 30 non-cached requests in 60 seconds.
// Please adjust the first two variables below in a manner optimal to your server config.

// Note that this only protects heavier non cached pages.
// A powerful enough attack can even overload your server with requests for cached pages.

function hook_init()
{
    $MinTime = 60;
    $MaxAttmpts = 30;

    $MyAppDDoSCheckUrl = variable_get('MyAppDDoSCheckUrl');
    $TimeCheckNow = time();

    if ($MyAppDDoSCheckUrl == '')
    {
        variable_set('MyAppDDoSCheckUrl',$TimeCheckNow.',1');
        return;
    }

    $SerDDosVars = explode(',',$MyAppDDoSCheckUrl);
    $TimeLast = intval($SerDDosVars[0]);
    $ReqAttmt = intval($SerDDosVars[1]);
   
    if ((($TimeCheckNow - $TimeLast) < $MinTime) && ($ReqAttmt > $MaxAttmpts))
    {
        header('HTTP/1.1 503 Server busy, try again later');
        die('The server is currently overloaded. Please try again in a couple of minutes. Thank you!');
    }
    else if (($TimeCheckNow - $TimeLast) < $MinTime)
    {
        $ReqAttmt++;
        variable_set('MyAppDDoSCheckUrl',$TimeLast.','.$ReqAttmt);
    }
    else
    {
        variable_del('MyAppDDoSCheckUrl');
    }
}

Toggle #input_group on fields in Drupal 7x

Here's the code for iterating through all fields in a form and setting $element['#input_group'] = TRUE;
 
 
function hook_form_alter(&$form, $form_state, $form_id) 
{
 if ($form_id == 'nodetype1_node_form') 
 {
  iterateForm($form, 'setIgt');
 }
}

// Generic iterate function. Can be used with any callback.
function iterateForm(&$form, callable $callback) 
{
 foreach (element_children($form) as $key) 
 {
  $element = &$form[$key];
  $children = element_children($element);
  if (empty($children)) 
  {
   call_user_func_array($callback, array(&$element, &$key));
  }
  else 
  {
   iterateForm($element, $callback);
  }
 }
}

// Custom callback
function setIgt(&$element, &$key) 
{
 if ($element['#type'] == 'textfield')
  $element['#input_group'] = TRUE;
}

Thursday, October 27, 2016

Shortest Code For Generating Prime Numbers

<?php


for ($i = 1; $i < 1000; $i++)
{
    $print = TRUE;
  
    // Optimized till square roots
    for ($j = 2; ($j*$j) <= $i; $j++)
    {
        $print = FALSE;

        if ($i % $j == 0)
            break;
      
        $print = TRUE;
    }

    if ($print)
        print $i.',';
}


?>

Wednesday, October 26, 2016

The Essence of Computer Programming

Computers are basically for the automation of repetitive work.
So programming computers is essentially the art of automation of repetitive work using loops.

Thus, the most essential thing one needs to understand to program computers is how to write loops.
That covers everything essential.

PS: Recursion is assumed here to just be a more advanced form of a loop, which is just a more elegant solution for certain types of problems.

C Code for Numerology 9999

Got a strange request from a friend:

Generate all 4 digit numbers whose recursive sums evaluate to nine, and whose non-zero digits are in ascending order.

Anyway, here's the code.

First run as usual :-) Apart from a few syntax corrections.
No logical errors.

<?php


for ($i = 9; $i < 10000; $i++)
{
    if (isAsc($i))
    {
        if (isSumNine($i))
        {
            if ($i < 10)
                print '000'.$i.PHP_EOL;
            else if ($i < 100)
                print '00'.$i.PHP_EOL;
            else if ($i < 1000)
                print '0'.$i.PHP_EOL;
            else
                print $i.PHP_EOL;
        }
    }
}


function isSumNine($num)
{
    $temp = $num;
    $sum = 0;

    while ($temp > 0)
    {
        $sum += $temp % 10;
        $temp = floor($temp / 10);
    }

    if ($sum > 9)
        return isSumNine($sum);
    else
        return ($sum == 9);

}


function isAsc($num)
{

    $temp = $num;
    $digit1 = 0;
    $digit2 = 10;

    while ($temp > 0)
    {
        $digit1 = $temp % 10;
        $temp = floor($temp / 10);

        if ($digit1 > $digit2)
            return false;

        if ($digit1 > 0)
            $digit2 = $digit1;
    }

    return true;
}

?>
The code can be easily converted to any C based language, by removing the $ signs and adding Int and Bool type declarations for that language.

Easiest Way To Run Code on Mac OSX

Most links will tell you to install XCode so that you can use GCC to run C / C++ code.

You don't need to. The easiest way is to use the existing PHP program on your Mac OSX.

Monday, September 26, 2016

The Software Industry and Computer Programmers

A google employee once wrote an article in which he said something like:

"Often we would interview a programmer who had an incredible amount of knowledge on a wide range of subjects, but couldn't program Hello World in any language."

It's really amazing how many people in the software industry simply know nothing about programming computers.

We're talking about core technical people such as Product Managers - not people in unrelated departments such as marketing - who have big plans and strong opinions on everything related to technology, but lack basic technical skills.

To put it in perspective, imagine an entire department of road planning where no one really knows to drive.

Sunday, September 4, 2016

Tradeadexchange virus on Android - Only Solution

None of the other solutions online seem to work.

The only solution seems to be:

1. Clear all browser caches completely (both in settings and in app info, to be sure)
2. Reset modem
3. Reset router (if different from the modem)

ALL AT THE SAME TIME.

The virus settles in the browser, and the modem + router.
If any of the three is not clean, the virus seems to infect all three.

There's no need to uninstall the browser or reset the phone.

Monday, February 22, 2016

The 12 best interactive Google Doodles

1. Les Paul's 96th Birthday


2. Robert Moog's 78th Birthday


3. 30th Anniversary of PAC-MAN


4. Alan Turing's 100th Birthday


5. Google Instant Launch


6. Hurdles 2012


7. Basketball 2012


8. Jules Verne's 183rd Birthday


9. Eadweard J. Muybridge's 182nd Birthday


10. Art Clokey's 90th Birthday


11. 25th Anniversary of the Buckyball


11. Total Lunar Eclipse. Live imagery provided by Slooh.


12. John Lennon's 70th Birthday


And two animated ones:

1. Mother's Day 2012


2. Martha Graham's 117th Birthday