klenwell information services : SpecialCocktailNapkin

Revision [1115]

This is an old revision of SpecialCocktailNapkin made by KlenwellAdmin on 2010-02-26 08:46:44.
 

online cocktail napkin

links and notes for later organization
CocktailNapkin2009 2009 Napkin
CocktailNapkin2008 2008 Napkin
CocktailNapkin2007 2007 Napkin
WordsIReallyLike
ThumbDrive
CocktailQuestions Questions for Strangers

Against the Gun is Civilization Argument:
The thesis is a canard.  Guns do not promote civilization.  Civilization is the result of functioning social institutions (foremost, the state itself), cooperative behavior, and, as Oliver Wendell Holmes Jr. said, taxes.

Flaws:
1. "Reason or force, that's it." False dichotomy: in the sense that the force referred to is a very particular kind of force: lethal force.  In civilized societies, this is a threat most people never (never!) face.  Even when they do, a gun helps only in very narrow circumstances and does not "civilize" the situation.  It glides over the much more complicated concept of contracts.  Are these methods of reason or force?  What do we do when they are broken?

2. "A mugger, even an armed one, can only make a successful living in a society where the state has granted him a force monopoly."  No civilized society has ever granted him that monopoly.  The state reserves that monopoly for itself.  That is part of what makes it civilized.  The mugger is trying to break that monopoly, to the detriment of civilization.

3. "When I carry a gun, I don't do so because I am looking for a fight, but because I'm looking to be left alone. The gun at my side means that I cannot be forced, only persuaded."  This is narcissistic to the point of pathology.  If you did this in any public place where I encountered you, you would be the threat.  It is a provocative act that does not further the cause of civilization.


Pattern Request Page: jquery json ajax request with cakephp
ycombo
fly bomber (it's supafly)
classic olympic fail
gdata python question on google groups
curious
copying DB in php
    function _switch_database($new_db) {
        $Dbo = ConnectionManager::getDataSource("default");
        $old_db = $Dbo->config['database'];
        $Dbo->reconnect(array('database'=>$new_db));
        return $old_db;
    }
   
    function _copy_database($db, $new_db) {
        $Dbo = ConnectionManager::getDataSource("default");
       
        # get tables
        $sql_show_tables_ = 'SHOW TABLES IN %s';
        $extract_pattern = sprintf('{n}.TABLE_NAMES.Tables_in_%s', $db);
        $ShowTables = $Dbo->query(sprintf($sql_show_tables_, $db));
        $TableList = Set::extract($ShowTables, $extract_pattern);
       
        # create new database
        $sql = sprintf('CREATE DATABASE %s', $new_db);
        $Dbo->query($sql);
       
        # copy tables
        $sql1_t = 'CREATE TABLE %s.%s LIKE %s.%s';
        $sql2_t = 'INSERT INTO %s.%s SELECT * FROM %s.%s';
        foreach ( $TableList as $table ) {
            $sql1 = sprintf($sql1_t, $new_db, $table, $db, $table);
            $sql2 = sprintf($sql2_t, $new_db, $table, $db, $table);
            $Dbo->query($sql1);
            $Dbo->query($sql2);
        }
       
        # test table lists
        $ShowTables = $Dbo->query(sprintf($sql_show_tables_, $db));
        $TableList1 = Set::extract($ShowTables, "{n}.TABLE_NAMES.Tables_in_$db");
       
        $ShowTables = $Dbo->query(sprintf($sql_show_tables_, $new_db));
        $TableList2 = Set::extract($ShowTables, "{n}.TABLE_NAMES.Tables_in_$new_db");
       
        if ( array_diff($TableList1, $TableList2) ) {
            trigger_error('table lists in new db dows not match old', E_USER_WARNING);
            return 0;
        }
        $this->Log_[] = "all tables in $db copied to $new_db";
       
        # test query: count all records and compare
        $old_db_count = 0;
        $new_db_count = 0;
        foreach ( $TableList as $table ) {
            $sql_ = 'SELECT COUNT(*) as count_ FROM %s.%s';
            $OldDb = $Dbo->query(sprintf($sql_, $db, $table));
            $NewDb = $Dbo->query(sprintf($sql_, $new_db, $table));
            $old_db_count += $OldDb[0][0]['count_'];
            $new_db_count += $NewDb[0][0]['count_'];
        }
        $rand_table = $TableList[array_rand($TableList)];
       
       
        if ( $old_db_count != $new_db_count ) {
            $mt_ = 'record count for new db (%s) and old db (%s) does not match';
            trigger_error(sprintf($mt_, $new_db_count, $old_db_count), E_USER_WARNING);
            return 0;
        }
        else {
            $mt_ = 'record count for new db (%s) and old db (%s)';
            $this->Log_[] = sprintf($mt_, $new_db_count, $old_db_count);
            return 1;
        }
    }


php encoding tests
requires http://hsivonen.iki.fi/php-utf8/php-utf8.tar.gz
<?php
    require('utf8.inc');

    $char = 'Ü';
    $h_char = htmlentities($char);
    $utf8 = htmlspecialchars($char, ENT_QUOTES, 'UTF-8');
    $h_utf8 = htmlentities($utf8);
    $uni_char = utf8ToUnicode($char);
    $data = array(
        '$char' => $char,
        '$h_char - htmlentities($char)' => $h_char,
        '$utf8 - htmlspecialchars($char,ENT_QUOTES,\'UTF-8\')' =>
            $utf8,
        'htmlspecialchars(\'Ü\',ENT_QUOTES,\'UTF-8\')' =>
            htmlspecialchars('Ü', ENT_QUOTES, 'UTF-8'),
        '$h_utf8 - htmlentities($utf8)' =>
            $h_utf8,
        'strlen($char)' => strlen($char),
        'strlen($h_char)' => strlen($h_char),
        'strlen($utf8)' => strlen($utf8),
        'strlen($h_utf8)' => strlen($h_utf8),
        'ord($char)' => ord($char),
        'ord($utf8)' => ord($utf8),
        'utf8ToUnicode($char)' => $uni_char,
        'dechex(ord($char))' => dechex(ord($char)),
        'sprintf(\'&amp;#x%s;\', dechex(ord($char)))' =>
            sprintf('&#x%s;', dechex(ord($char))),
        'sprintf(\'&amp;#x%s;\', ord($char))' =>
            sprintf('&#x%s;', ord($char)),
        'sprintf(\'&amp;#%s;\', $uni_char[0])' =>
            sprintf('&#%s;', $uni_char[0]),
        'sprintf("&#x%s;", dechex($uni_char[0]))' =>
            sprintf("&#x%s;", dechex($uni_char[0])),
        'iconv("UTF-8","ISO-8859-1//TRANSLIT",$char)' =>
             iconv("UTF-8","ISO-8859-1//TRANSLIT",$char),
    );
   
    $xhtml = <<<XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>sandbox</title></head>
<body>
<pre>
%s
</pre>    
</body>
</html>
XHTML;

    $charset = 'UTF-8'; #'ISO-8859-1';
    header( 'Content-type: text/html; charset='.$charset );
    printf($xhtml, print_r($data,1));
    var_dump($char);
    var_dump($h_char);
    var_dump($utf8);
    var_dump($h_utf8);


jquery quiz
== jQuiz: jQuirks ==
A short quiz on jQuery behavior.

===1. What will these lines of code produce?===
<code><pre>
var Test1El1 = $('div#Test1El1');
var Test1El2 = $('div').attr('id', 'Test1El2');
var Test1El3 = $('<div id="Test1El3" />');
console.log(Test1El1);
console.log(Test1El2);
console.log(Test1El3);
</pre></code>

===2. What will be the output of the code below?===
<code><pre>
var Test2El1 = $('<div id="Test2El1" />');
$(document.body).append(Test2El1);
var elid = Test2El1Test2El1.attr('id');
var Test2El2 = $(elid);
console.log(Test2El1);
console.log(elid);
console.log(Test2El2);
</pre></code>

===3. True or False===
<code><pre>
var id_ = 'test3id';
$('<div id="' + id_ + '" />').appendTo(document.body);
var Test3El1 = document.getElementById(id_);
var Test3El2 = $('#'+id_);
console.log(Test3El1.id == Test3El2.id);
</pre></code>

===4. True or False===
<code><pre>
var Test4El1 = $('<div id="Test4El" />').appendTo(document.body);
var Test4El2 = $(Test4El1);
console.log(Test4El1 == Test4El2);
console.log(Test4El1.attr('id') == Test4El2.attr('id'));
</pre></code>

===Given a document with the following table code, answer the next 2 questions:===
<code><pre>
<table id="Test5Table">
  <tr id="Test5Tr1"><td>cell1</td><td>cell2</td></tr>
  <tr id="Test5Tr2"><td>cell1</td><td>cell2</td></tr>
</table>

var Test5Table = $('<table id="Test5Table"><tr id="tr1"><td>cell1</td><td>cell2</td></tr><tr id="tr2"><td>cell1</td><td>cell2</td></tr></table>');
$(document.body).append(Test5Table);
</pre></code>

====5. What will the value of TableRows[0] be below?====
<code><pre>
var Test5Table = $('table#Test5Table');
var TableRows = Test5Table.find('tr');
console.log(TableRows[0].attr('id'));
</pre></code>

====6. What will the value of RowIds[0] be below?====
<code><pre>
var Test5Table = $('table#Test5Table');
var TableRows = Test5Table.find('tr');
var RowIds = [];
TableRows.each( function(i, El) {
  RowIds.push(El.attr('id'));
});
console.log(RowIds[0]);
</pre></code>

===7. What will the value of FindEl be below?===
<code><pre>
// build and add element to our document
var elid = 'formbid-0.field';
var NewDiv = $('<div id="'+elid+'" />').text(elid);
$(document.body).append(NewDiv);

var jqid = NewDiv.attr('id');
var FindEl = $(document.body).find('#'+jqid);    // note # sign
console.log(jqid, FindEl);
</pre></code>

<div style="display:none;">Answer:
<code><pre>
jesc = jqid.replace('.', '\\.');
var FindEl = $(document.body).find('#'+jesc);
console.log(jesc, FindEl);
</pre></code>
</div>


music on-demand
this + http://www.dizzler.com/ + http://getfirebug.com/net.html

some cakephp code
	function render($action=NULL, $layout=NULL, $file=NULL) {
	    if ( $action == null ) {
	        $action = $this->view_action;
	    }
	    $output = parent::render($action, $layout, $file);
	    return $output;
	}

	function index()
	{
	    $m = 'null';
	    if ( isset($this->params['pass'][0]) ) {
	        $m = $this->params['pass'][0];
	    }
	    #debug($this->params);
	    #debug($m);
	    
	    if ( method_exists($this, $m) ) {
	        $this->view_action = sprintf('/journal/%s', $m);
	        return $this->$m();
	    }
	    else {
	        $this->set('error', 'page_not_found');
	    }
	}




CategorySpecial