klenwell information services : SpecialCocktailNapkin

Revision [780]

This is an old revision of SpecialCocktailNapkin made by KlenwellAdmin on 2008-02-20 09:05:17.
 

online cocktail napkin

links and notes for later organization
CocktailNapkin2007 2007 Cocktail Napkin

Tivo for Radio: excellent tutorial streamripper (windows or linux)
OS Flash Dev: MTASC flashdevelop.org game dev
CakePhp config: multiple apps on single site admin subdomain
SSL on Debian Apache2: ilovett.com debian-administration.org
Goodbye Cruel Word: Hello, lyx!
Fun with apache logs: set-up parsing archiving logs scp man

find files by size or data
# basic (source: http://www.howtogeek.com/howto/ubuntu/delete-files-older-than-x-days-on-linux/)
$ find /path/to/files* -mtime +5 -ls

# delete
$ find /path/to/files* -mtime +5 -exec rm {} \;

# files only (http://www.unix.com/shell-programming-scripting/32816-need-remove-files-older-than-30-days-except-directories.html)
$ find /path/to/files -type f -mtime +90 -exec rm {} \;

# dirs only (http://lowfatlinux.com/linux-find.html)
$ find /path/to/files -type d -ok rmdir {} \;

# find files by size (http://lowfatlinux.com/linux-find.html)
$ find /path/to/files -size +100k -ls

# find files older than 8 hours (http://www.unix.com/shell-programming-scripting/32816-need-remove-files-older-than-30-days-except-directories.html)
$ touch -t `date --date='12 hours ago' +%Y%m%d%H%M` time_marker
$ find . -type f -newer time_marker -ls

# find files by size and age
$ find /path/to/files -type f -mtime +1 -size +5k -ls

# remove files older than 4 hours and larger than 5 kb
$ touch -t `date --date='4 hours ago' +%Y%m%d%H%M` time_marker
$ find /path/to/files -type f -newer time_marker -ls


Scratchpad
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>javascript canvas</title>

<!-- JS: timer -->
<script type="text/javascript">
var tx0 = new Date();
function jstx() { return ( ( new Date() ) - tx0 ) / 1000; } 
function l() { if (eval('typeof(console)=="undefined"')) return; var arg=arguments, msg='';  for(i=0; i<arg.length; i++) { msg+=arg[i]+' '; } console.log('[log]', msg); }
function p(message) { document.write(message); }
</script>

<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="formState.js"></script>

<!-- JS: dev -->
<script type="text/javascript">
</script>
<!-- External Script -->

<!-- JS: dev -->
<script type="text/javascript">

var EditorApp = Class.create({
	
  version : '0.1', 
  pre     : 'ned_',
  c       : ' : ',
	
  initialize: function(textarea_id) 
  {
	this.id = this.pre + 'parent_' + textarea_id;   // obj id
	this.fid = this.id + '_undoable';     // form id
	this.tid = textarea_id;
	this.class = this.pre + 'block';
	this.T = $(this.tid);
	this.metabar = {};
	this._update_dom();
	this._add_observers();
  },  
  
  
  _update_dom: function() 
  {
	// get textarea parent and grandparent
	this.Tp = this.T.getOffsetParent(this.T);
	
	// create a parent dom element and form append textarea
	this.E = new Element('div', { 'id': this.id, 'class': this.class });    
	this.F = new Element('form', { 'id': this.fid });
	this.F.appendChild(this.T);
	this.E.appendChild(this.F);
	this.Tp.appendChild(this.E);
	
	// append toolbar
	this.addToolbar();
	this.E.appendChild(this.toolbar);
	
	// get dom obj
	l(this.id, ' EditorApp created');
  },
  
  
  _add_observers: function()
  {
	// buffer
	this.T.Buffer = new TextBuffer(20);
	    
	// add event listener
	new Form.Element.Observer(
	  this.T.id,
	  2,  // seconds
	  function(el, value){
	    el.Buffer.update(value);
	  }
	)

	this.T.observe('change', function(event)
	{
	  l('observing changes on', this.T.id, 'for buffer');
	  El = Event.element(event);
	  
	});
  },

  
  addToolbar: function()
  {
	l('building toolbar');
	BX = [];
	// array: [0]id, [1]label, [2]target id, [3]callback
	BX[0] = [this.pre + 'bold', '&lt;b&gt;', this.T.id, this.emboldenText];
	BX[1] = [this.pre + 'ital', '&lt;i&gt;', this.T.id, this.testEvent];
	BX[2] = [this.pre + 'undo', 'undo', this.T.id, this.undoEvent];
	
	this.toolbar = new Element('div', { 'id': this.pre + 'toolbar' });
	for ( var n=0; n<BX.length; n++ )
	{
	    var new_bx = this.cxButton(BX[n][0], BX[n][1], BX[n][2], BX[n][3]);
	    this.toolbar.appendChild(new_bx);
	}
  },
  
  cxButton: function(id, label, target, onclick_callback)
  {
	l('cxButton:',id,'|',label,'|',target);
	Bx = new ToolButton(id, label, target, onclick_callback);
	return Bx.E;
  },
  
  emboldenText: function(event)
  {
	el = Event.element(event);  // element
	t = $(el.target);           // target
	v = t.value;                // target value
	ins = '';                   // insert    
	nv = v;                     // new value
	
	ST = EditorApp.getSelectedText(t);    
	if ( ST[0] != false ) ins = '<strong>' + ST[0] + '</strong>';
	nv = v.substring(0, ST[1]) + ins + v.substr(ST[2]);
	t.value = nv;
	l('event',event,': calling emboldenText on',t,'| insert: "',ins,'"'); 
	
	EditorApp.selectRange($(t), ST[1] + ins.length, ST[1] + ins.length);   
  },
	    
  testEvent: function(event)
  {
	s = ' | ';
	el = Event.element(event);
	l('testEvent:','event=',event,s,'calling element=',el,s,'target=',el.target);          
  }
  
});

/*
  returns an array holding:
  [0]: selected text
  [1]: start pos
  [2]: end pos
*/
EditorApp.getSelectedText = function(el)
{
  l("getting selected text from " + el.id + " : " + el.toString());
  selected = [false, 0, 0];
	
  // get start/end
  var s1 = 0; var s2 = 0;
  if ( typeof document.selection != 'undefined' )
  {
	var r = document.selection.createRange();
	s1 = r.start;
	s2 = r.end;
  }
  else if ( typeof el.selectionStart != 'undefined' )
  {
	s1 = el.selectionStart;
	s2 = el.selectionEnd;
  }
  else
  {
	l('getSelectedText handle not found');
	return selected;
  }

  while ( s2 > s1 && el.value.charAt(s2-1) == ' ' )
  {
	s2--;
  }
  
  l('selecting',s1,',',s2,'in',el.id);
  if ( s2 - s1 < 1 ) return selected;
  
  sel_text = el.value.substring(s1, s2);
  l('selected text:', sel_text);
  return [sel_text, s1, s2];
}


EditorApp.selectRange = function(el, p1, p2)
{
  if(el.setSelectionRange) 
  {
	el.focus();
	el.setSelectionRange(p1,p2);
  }
  else if(el.createTextRange)
  {
	range=el.createTextRange();
	range.collapse(true);
	range.moveEnd('character',p2);
	range.moveStart('character',p1);
	range.select();
  } 
}



/*
  Each button is an object and should have an action and a target.  The target
  is another object (or the button itself) upon which the action acts.  The
  action is a callback function which is called when button is clicked.
*/
var ToolButton = Class.create({    
	
  initialize: function(id, label, target_id, click_callback) 
  {
	l('constructing ToolButton: ' + id);
	
	// create button element (as a)
	AttList = { 'id': id, 'onmouseover': 'javascript:this.style.cursor="pointer";' };
	this.E = new Element('a', AttList).update(label);
	
	// add attributes    
	this.E.id = id;
	this.E.label = label;
	this.E.target = target_id;
	this.E.action = click_callback;

	// add event listener 
	this.E.observe('click', function(event)
	{
	    calling_el = Event.element(event);
	    click_callback(event);
	    $(calling_el.target).focus();
	});         
  }
});


var TextBuffer = Class.create({
  
  initialize: function(target_id, maxlen)
  {
	this.id = target_id;
	this.maxlen = ( maxlen != undefined ) ? maxlen : 20;
	this.E = $(target_id);
	this.BUFFER = [];
	this.ptr = -1;
  },
  
  
  // update buffer (alias of push)
  update: function(textarea_value)
  {
	this.push(textarea_value);
  },

  
  // push buffer
  push: function(str)
  {
	var buf_len = this.BUFFER.push(str);
	var overflow = buf_len - this.maxlen;
	while ( overflow > 0 ) 
	{
	  overflow--;
	  this.BUFFER.shift();
	  buf_len--;
	}
	this.ptr = this.BUFFER.length - 1;
	l("pushing '", str, "' on buffer and setting ptr to", this.ptr);
  },
  
  // undo buffer
  undo: function()
  {
	this.ptr--;
	if ( this.ptr < 0 ) this.ptr = 0;
	var content = this.BUFFER[this.ptr];
	l('undo: returning content "', content, "' at ptr", this.ptr);
	return content;
  },
  
  // redo buffer
  redo: function()
  {
	this.ptr++;
	if ( this.ptr >= this.BUFFER.length  ) this.ptr = this.BUFFER.length - 1;
	var content = this.BUFFER[this.ptr];
	l('redo: returning content "', content, "' at ptr", this.ptr);
	return content;
  }  
});


/*

*/
var DomHandler = Class.create({    
	
  initialize: function() 
  {
	l('constructing DomHandler ' + id);
  }
});

</script>
<!-- External Script -->


<style type="text/css">
body { margin:0; padding:0; font-family:sans-serif; color:#ccf; }
h1 { margin:0 0 10px; padding:1em;  border-bottom:1px solid #ccf; background: #f3f3ff; }
#footer {
 clear:both; margin-top:12px; padding:4px; font: 11px verdana,sans-serif;  border:1px solid #ccf; border-width:1px 0; background: #f3f3ff; text-align:center;
}

/* Editor */
.ned_block { width:300px; margin:0 auto; border:1px solid #ccc; }
.ned_block form, .ned_block textarea { margin:0; }
.ned_block textarea { width:300px; overflow-x:auto; margin:0; }
#ned_toolbar { text-align:center; margin:0; padding:3px; background:#f6f6f6; }
#ned_toolbar a { margin:0px 6px; }
#ned_toolbar a:hover { margin:0px 6px; color:#66d; }

</style>

</head>
<body>

<h1 id="page_title">prototyper</h1>

<div id="canvas">
<textarea id="proto" rows="10" cols="40">this is a textarea in the new prototype js html editor.  Enjoy!</textarea>
</div>
<script type="text/javascript">var Editor = new EditorApp('proto');</script>

<!-- Footer -->
<script type="text/javascript">p('<div id="footer">js timer: ' +  jstx() + ' s</div>'); l('script complete');</script>

</body>
</html>


cron test
#!/bin/bash

# Simple bash script to test cron
# COMMAND: $ ~/cron/test.sh
# CRON.D:    * * * * 1-5  tatwell  ~/cron/test.sh >> ~/cron/test_result.txt 2&>1

#Test Commands
TEST_DATE="date -R"
TEST_PHP="php -v"
TEST_PHP5="php5 -v"
TEST_LYNX="lynx -version"
TEST_WGET="wget -v"
TEST_FIND="find --version"
TEST_TOUCH="touch --version"

#Other Settings
HR="\n----------------------------\n"

echo -e "\n\n** Starting Cron Test **\n"

echo -e "DATE:\n"
$TEST_DATE
echo -e $HR

# Php Tests
echo -e "PHP:\n"
$TEST_PHP
echo -e $HR
echo -e "PHP5:\n"
$TEST_PHP5
echo -e $HR

echo -e "FIND:\n"
$TEST_FIND
echo -e $HR

echo -e "TOUCH:\n"
$TEST_TOUCH
echo -e $HR

echo -e "LYNX:\n"
$TEST_LYNX
echo -e $HR

echo -e "WGET:\n"
$TEST_WGET -V

echo -e "\n** Cron Test Complete **\n\n"



CategorySpecial