Posts

Running Background Tasks From SSH

Most online sources will tell you that you need a tool such as Screen to be able to run background tasks from an SSH session. But the simplest way is to simply configure an a Cron job. The process will continue to run even after the SSH session is disconnected. The process can also be monitored later with PS (pipe through grep to find it), and even terminated with Kill if necessary.

PHP Custom timeout for file_get_contents

$CustStreamContext = stream_context_create (     array     (         'http'=> array         (                     'timeout' => 0.5,  //0.5 seconds             )     ) );         $Cont = @file_get_contents("https://www", false, $CustStreamContext);

Drupal Node Revisions Cleanup

<? $nodes = db_select('node', 'n')     ->fields('n', array('nid','vid'))     ->condition('n.type','common_stock', '<>')     ->execute(); foreach ($nodes as $node) {     $revisions = db_select('node_revision', 'n')         ->fields('n', array('vid'))         ->condition('n.nid',$node->nid)         ->condition('n.vid',$node->vid, '<')         ->execute();     $count = 0;     foreach ($revisions as $rev)     {         // Uncomment below line to actually delete         // node_revision_delete($rev->vid);           $count++;     } if ($count>0)     echo '<a target="_blank...

Drupal unpublish node programmatically

<? $nids = explode(',','62013,61859,61863,61865,61867,61871,61886,63158,62026,62030,186894,62065,62066,62075,62077,147834,62944,62107,62109,62110,62113,62114,62117,62593,62595,147333,62625,62725,62730,62731,62737,62738,147694,62744,62746,62747,62749,62752,62882,62931,62936,62939,63142,63329,63330,179870,147716,63537,63545,63990,63779,63778,64096,64097,64098,147160,64105,147159,138323,142181,146031,210600,235951,141272,142298,186895,146032,146997,147529,145236,145813,274097,281698,296945,299231'); foreach ($nids as $nid) { $node = node_load($nid); if (isset($node->status)) { $node->status = 0; node_save($node); } } ?>

Connecting to the LAN using USB

The USB port on most routers is not actually for connecting computers. It’s for making storage devices (such as USB drives) accessible over the network. Many modern computers (such as the new Macs) do not have an Ethernet port. So the only way for them to connect to a network is either over the wireless, or using a USB-to-Ethernet adapter. But note that for the Mac to recognize the network connection over USB, the USB adapter has to be plugged in with a live Ethernet connection. If the Ethernet is turned on after the adapter is plugged in, the Mac won’t recognize the connection.

The Product vs Services Conundrum

Image
Have you read Peter Thiel's Zero to One? In simple terms: One to Two players are those who are focused on increasing revenue in an existing market. Zero to One players are those who creating a totally new market or new product. They will not have any competitors. Think of a startup like Facebook or WhatsApp. They have no customers, or competitors. That’s a zero to one startup. A completely new domain. Thiel was a founder of PayPal and the first investor of Facebook. Both zero to one startups. You will find the following model in a lot of startups: They will have a product division for long-term growth. But they will have a services division for meeting short term expenses. But the services division will always get more focus because it delivers revenue essential for survival. In my former employer's case, they were doing both with the same code. They were implementing the code at each client location for revenue. But they were also trying to build the code bas...

Drupal 7 Create Node With Specific NID using PHP

$node = new stdClass(); $node->type = "page"; // Sets some defaults. Invokes hook_prepare() and hook_node_prepare(). node_object_prepare($node); // Or e.g. 'en' if locale is enabled. $node->language = LANGUAGE_NONE; $node->uid = 234; // Status is 1 or 0; published or not. $node->status = 1; // Promote is 1 or 0; promoted to front page or not. $node->promote = 0; // Comment is 0, 1, 2; 0 = disabled, 1 = read only, or 2 = read/write. $node->comment = 0; $node->nid =123; $node->title = 'title 123'; $node->is_new = true; $node = node_submit($node); // Prepare node for saving node_save($node);