Posts

Batch Convert PNG to JPG from Mac Terminal - SIPS

  mkdir jpegs sips -s format jpeg *.* --out jpegs  

Export single table MySQL

Using OUTFILE will output a table to CSV but gives an access denied error for non root users. SELECT * FROM orders WHERE foo = 'bar' INTO OUTFILE '/var/lib/mysql-files/orders.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' ;   A quicker way than granting access etc is to simply dump the table from ssh into an sql file, and convert the data oneself using vi and regex.  mysqldump db_name table_name > table_name . sql

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.