cat brain.log | less

Getting it down on `paper`

WordPress Plugins – Playground

I just installed wp-syntax and wp-terminal and want to see a demo.

wp-syntax

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
 /**
  * Since every project has an acquire and insert, and most of those
  * projects have the same mechanisms of acquisition and insertion,
  * we create this class to handle these mundane operations.
  *
  * @file BaseProject.php
  * @date 2009-07-28 15:00 HST
  * @author <nobody>
  * @version 1.0.0
  *
  * @modifications
  * 1.0.0 - 2009-07-28 - Created
  */
 
 
class BaseProject {
  var $DB_NAME;
  var $TABLE_NAME;
  var $MAX_RECORDS = 32767;
  var $DEBUG = false;
 
  function BaseProject($db=DB_NAME,$table=TABLE_NAME) {
    $this->DB_NAME = $db;
    $this->TABLE_NAME = $table;
    return $this;
  }
 
 
  function getAcquireUrl($ts=null) {
    $this->enotice("getAcquireUrl: Abstract function.");
    exit(2);
  }
 
 
  function getRecords($fpath,&$records,$start=0,$limit=null) {
    if( !is_array($records) ) {
      $records = array();
    }
    $this->enotice("getRecords: Abstract function.");
    exit(2);
  }
 
 
  function getHeader() {
    if( isset($this->header) ) { 
      return $this->header;
    }
    if( isset($GLOBALS["header"]) ) {
      return $GLOBALS["header"];
    }
    $this->enotice("getHeader: Abstract function.");
    exit(2);
  }
 
  function getOutputFile($ts=null) {
    $ts = (is_null($ts)) ? time() : $ts;
    return sprintf(
      "%s/%s/%s/%s_%s.dat",
      $this->getDataDirectory(),
      gmdate("Y",$ts), gmdate("Ymd",$ts),$this->TABLE_NAME, gmdate("YmdHis",$ts)
    );
  }
 
  function getDataDirectory() {
    return DATASTORE_DATA_PRIMARY.'/'.$this->DB_NAME.'/'.$this->TABLE_NAME;
  }
 
  function getStateFile($op) {
    return sprintf("%s.%s.state",$this->TABLE_NAME,$op);
  }
 
  function getInsertStateFile() {
    return $this->getStateFile('insert');
  }
 
  function getAcquireStateFile() {
    return $this->getStateFile('acquire');
  }
 
 
  function acquire($url=null,$ts=null) {
    $ts = (is_null($ts)) ? time() : $ts;
    if( is_null($url) ) {
      $url = $this->getAcquireUrl($ts);
    }
    if( !$url ) {
      $this->enotice("Url not valid: $url");
      return false;
    }
    $opath = $this->getOutputFile($ts);
    if( $this->DEBUG ) {
      echo("DEBUG: Filesystem::mkdir(".dirname($opath).");\n");
    } else {
      Filesystem::mkdir(dirname($opath));
    }
 
    $cmd = sprintf(
      "wget -qq %s -O %s",
      escapeshellarg($url),
      escapeshellarg($opath)
    );
    $this->notice($cmd);
    if( $this->DEBUG ) {
      echo("DEBUG: system($cmd,retVal);\n");
      echo("DEBUG: setLastAcquireTime($ts);\n");
      $retVal = 0;
    } else {
      system($cmd,$retVal);
      $this->setLastAcquireTime($ts);
    }
    return ($retVal==0);
  } // END: function acquire($url=null)
 
 
 
  function insert() {
    $this->notice("Startup");
    $t0 = time();
 
    $header = $this->getHeader();
    if( !$header ) {
      $this->enotice("Couldn't get header.");
      return false;
    }
 
    $archiver = new Archiver($this->DB_NAME,$this->TABLE_NAME);
    if( !$archiver ) {
      $this->enotice("Archiver not found!");
      exit(3);
    }
    if( $archiver->isLocked() ) {
      $this->notice("Archive is locked, that is all...");
      return true;
    }
 
    $fpaths = $this->listFiles($this->getLastInsertTime());
    $nFiles = count($fpaths);
    if( $nFiles < 1 ) {
      $this->notice("Nothing to do...");
      return true;
    }
 
    $fileCounter = 0;
    $records = array();
    foreach( $fpaths as $fpath ) {
      $this->notice("Processing: ".basename($fpath));
      set_time_limit(3600);
      $fileCounter += 1;
 
 
      $records = $this->getRecords($fpath,$records);
      if( count($records) > $this->MAX_RECORDS || $fileCounter >= $nFiles ) {
        $this->notice("Archiving...");
        if( $this->DEBUG ) {
          echo("DEBUG: archiver->replace(records,header);\n");
          echo("DEBUG: \n");
          echo(Arrays::formatMatrixAscii(array_slice($records,0,5))."\n\n");
        } else {
          if( !$archiver->replace($records,$header) ) {
            $this->enotice("Couldn't archive!");
            return false;
          }
        }
        $this->notice("ok.");
        $records = array();
      }
    if( $this->DEBUG ) {
      echo("DEBUG: setLastInsertTime($t0);\n");
    } else {
      $this->setLastInsertTime($t0);
    }
    $this->notice("Shutdown");
    return true;
  }
 
 
  function listFiles($t0=null,$limit=null) {
    $dl = new DirectoryListing($this->getDataDirectory());
    $dl->setRecursive(true);
    $dl->setIncludeFiles(true);
    $dl->setIncludeDirectories(false);
    $dl->setUseFullPath(true);
    if( !is_null($limit) ){
      $dl->setLimit($limit);
    }
 
    $files = $dl->getListing();
    if( $files===false ) {
      $this->enotice("getListing returned false: ".$this->getDataDirectory());
      return false;
    }
    sort($files);
 
    if( is_null($t0) ) {
      return $files;
    }
 
    $keepers = array();
    foreach($files as $fpath) {
      if( filemtime($fpath) > $t0 ) {
        $keepers[] = $fpath;
      }
    }
    return $keepers;
  } // END: function listFiles($t0=null)
 
 
  function setLastAcquireTime($ts) {
    return Filesystem::file_put_contents($this->getAcquireStateFile(),$ts);
  } // END: function setLastAcquireTime($ts)
 
 
  function getLastAcquireTime() {
    $fpath = $this->getAcquireStateFile();
    if( !file_exists($fpath) ) {
      return false;
    }
    return intVal(file_get_contents($fpath));
  } // END: function getLastAcquireTime()
 
 
  function setLastInsertTime($ts) {
    return Filesystem::file_put_contents($this->getInsertStateFile(),$ts);
  } // END: function setLastInsertTime($ts)
 
 
 
  function getLastInsertTime() {
    $fpath = $this->getInsertStateFile();
    if( !file_exists($fpath) ) {
      return false;
    }
    return intVal(file_get_contents($fpath));
  } // END: function getLastInsertTime()
 
 
  function enotice($msg) {
    return $this->notice($msg,true);
  }
 
 
  function notice($msg,$isError=false) {
    if( $isError ) {
      error_log(
        sprintf("%s - %s",gmstrftime("%Y-%m-%d %H:%M:%S"),rtrim($msg))
      );
    } else {
      printf("%s - %s%s",gmstrftime("%Y-%m-%d %H:%M:%S"),rtrim($msg),PHP_EOL);
    }
    return true;
  }
} // END: class BaseProject

wp-terminal

Did not work as advertised.

Using these plugins with < and > present in the code is a pain!

 

Comments

No comments so far.

(comments are closed)