Posts

Delete Account Link on Facebook

Doesn't seem to be displayed on the site anymore. The link is: www.facebook.com/help/delete_account

Get Unique Line Counts on Linux

From terminal: cat Duplicates.txt | sort | uniq -c > Counts.txt Within vi: :%sort         // sort the results as required by "uniq" :%!uniq -c   // use the *nix "uniq" tool to prepend counts :%sort!        // sort in reverse order

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.

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.

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]);        ...

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 ; }

Shortest Code For Generating Prime Numbers

Image
<?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.','; } ?> <? // Here's a little trick I learnt from a friend almost 30 years ago // Counting Prime numbers $StartTime = time(); $PrimeCount=0; for ($i=1; $i<200000; $i++) { $IsPrime = true; for ($j=2; ($j*$j)<=$i; $j++) { if (($i % $j) == 0) $IsPrime=false; } if ($IsPrime) $PrimeCount++; } $TimeTaken = (time() - $StartTime); echo 'Counted '.$PrimeCount.' prime numbers in '.$TimeTaken.' seconds.'.PHP_EOL; // Ga...