Listening to Kids

Listen to kids. Their ideas are not clogged up by years of boxed-in thinking.

I just realized this last night when trying to screw a shelf to a wall bracket and was getting frustrated. My 9 year old, Sam, said, “Dad, let me take a look. I might have an idea.” That was all it took. I hadn’t even realized I could do anything but keep slogging forward in constant failure. I took 5 seconds to think and came up with a solution.

In the future I’ll be asking for a fresh childlike perspective sooner.

And to think, I almost snapped at him for talking while I was struggling. 😦

Gutter Glogger, Pavlovs, Meetups and Family Game Night

  1. Gutter cleaning pole – “The Gutter Glogger – The  taller gutter de-clogger” Prototype – painting extension pole with paintbrush clamp.  Garden trowel, stick, garden hose.
  2. Develop Brain Storming Curriculum to be used in a mentoring or one-on-one environment (think tutoring or home schooling).
    Brainstorming meetups – small groups get together to create idea lists.  Individual members can request help with specific topics.
  3. Trunk Club for Men AND boys – father’s and sons.  Dad and son have matching outfits.
  4. SAAS Contract Boilerplate Generator – get rid of crappy outdated technical contract language.
  5. Bi-Weekly Income Planner vs. monthly or 1st/15th bills.  26 pay periods vs 12 or 24.
  6. Homemade dessert education network.  Works to educate restauranteurs to stop serving crappy assembly line desserts from their food service vendor.
    Homemade Dessert
  7. Write an ebook about the moral obligation we have to those around us regarding money and not enabling theft.
  8. Bedtime Pavlovs – some sort of automatic ritual device – bells, lights, that helps kids not connect bedtime to daylight.
  9. Family Organizing.  No one is doing family calendars / organization well.  Sharing is too complicated, notifications need to be scoped to avoid members.  Families grow up – have a plan for account splitting,
  10. Plan a family game night.  Learn more card games. Board Games.  Create a fun calendar. Vote on activities to do on designated “fun nights”
  11. Hold a family meeting to set vision, mission and values for the family.

Cardboard Signs, Machine Learning, Business Tourism and Mom

  1. Stop and talk to someone holding a cardboard sign asking for help. Find a way to permanently help them.
  2. Meet as many interesting people and as many money people as possible.  Make connections between groups – expect nothing in return.
  3. Website for ideas  “idaexchange.com” (available as of this writing) – ideas are currency.  Trade them – pay an idea to get an idea.  Machine Learning used to ensure quality.
  4. Make a better linked in – more personal, more results oriented rather than clubbish. Focus on legitimate relationship links and accomplishments.
  5. Recency is relevancy – interaction (including commerce) metrics, in a temporal context (I have the domain name… let’s talk)
  6. Make a better facebook.  More privacy, more ads, no sharing.  User is not a product.
  7. Make homemade BBQ sauce
  8. Write a book full of amusing things my kids say
  9. Business tourism – what is it like to spend a day with an employee from a major corporation? Google, Facebook, Microsoft, Apple, etc.
  10. Talk mom into writing about her childhood and life – sell it on Amazon.

Recent Relevance – New Site Launch

I’ve been doing a lot of thinking and reading recently about personal improvement and helping those around me.   I’ve been reading James Altucher’s book “The Choose Yourself Guide to Wealth” in which he advocates making a daily list of 10 ideas.

He suggests giving the ideas away for free, an “all boats lift in a rising tide” mentality.  I’ve been making multiple lists a day – some of them are too private to share (things like “how can I help Uncle Crime fight a lawsuit”) but the ones I can share will get posted.

I believe ideas are only relevant for a short period of time so the site is named  accordingly:

http://recentrelevance.com/

More thoughts on education

“I wish that our current educational approaches put much more emphasis on following one’s curiosity and asking ‘Why?’, rather than on memorization of facts and rote reproduction of processes. We can hardly blame students for not being curious when our educational system doesn’t generally reward that. So, sadly, it is surprising when a student asks ‘Why?'”

Steven Clarke

JSON Streaming Output

I recently put together a simple little bit of code to handle streaming large amounts of JSON formatted data to the browser.

In order for you to see any benefit from this, you will need to have the following scenario.

You have a response you’re sending back with some meta information about the response – maybe a response code, or error messages or a single record.

You also have a number of rows to send back as a member of the main JSON object.

These rows don’t all need to be the same object, but you can only have a single variable that you stream.

This allows you to fetch and send a single database row at a time instead of building up a huge response object in memory on the server.

It builds up a response that looks like this (the data in “rows” is streamed one line at a time):

{
    "success":true,
    "rows":
    [
        {"id":1,"random_data":"a6b1e15cc6523e87cb8d5a6a0ea39dbc61842b23"},
        {"id":2,"random_data":"12ae19125e2182294433e835ee8dc7e403154fdd"}
    ]
}


<?
// COPYRIGHT 2015 by TIM GALLGHER (treehousetim@gmail.com)
// https://treehousetim.com/2015/04/08/new-json-streaming-output-code/
//The MIT License (MIT)
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// Example:
// create your response
// this can be as complex as you want, but it must have single array of records to be effective.
// it sends in 3 stages.
// stage 1: send the entire response object except for the rows
// stage 2: send the rows, streaming one row at a time
// stage 3: send the closing JSON syntax
// if you bundle all your data into a single row, this approach will not yield any benefit
// the primary point of this file
include( 'streamBrowserJSON.php' );
$response = new stdClass();
$response->success = true;
$response->rows = array();
// start example
outStreamJSON::getInstance()
->createTemplate( $response, 'rows' )
// adds ")]}',\n" by default, or pass in a value of your own
->csrfHeader()
// only one line handler is used at a time.
// pass a standard callback that can be used with call_user_func
->addLineHandler( 'createRow' )
// the syntax if you're using
//->addLineHandler( array( $this, 'getRow' ) )
->addOutput()
->render();
// an example row handling function
function createRow()
{
static $cnt = 0;
if( $cnt++ > 10000 )
{
return false;
}
// create a bunch of example data
return (object)array( 'id' => $cnt, 'random_data' => sha1( rand() ) . sha1( rand() ) . sha1( rand() ) . sha1( rand() ) . sha1( rand() ) . sha1( rand() ) . sha1( rand() ) . sha1(rand() ) . sha1(rand() ) );
}

view raw

example.php

hosted with ❤ by GitHub


<?
// COPYRIGHT 2015 by TIM GALLGHER (treehousetim@gmail.com)
// https://treehousetim.com/2015/04/08/new-json-streaming-output-code/
//The MIT License (MIT)
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// the output class – allows for outputting to mutiple streams at once – i.e. file logging and browser
class outStreamJSONOutput
{
public $stream;
protected $filename;
public function __construct( $filename = null )
{
if ( $filename == null )
{
$filename = 'php://output';
}
$this->stream = new SplFileObject( $filename, 'w' );
$this->filename = $filename;
}
//——————————————————————————
public function out( $out )
{
$this->stream->fwrite( $out );
}
//——————————————————————————
public function encodeRow( $data )
{
static $first = true;
$line = ($first?'':',') . json_encode( $data );
$this->out( $line );
$first = false;
}
}
// the main class
class outStreamJSON
{
protected $_templateTop;
protected $_templateBottom;
protected $_csrfHeader = '';
protected $_outputs = array();
protected $_lineCb;
public static function getInstance()
{
return new outStreamJSON();
}
//——————————————————————————
public function csrfHeader( $header = ")]}',\n" )
{
$this->_csrfHeader = $header;
return $this;
}
//——————————————————————————
public function createTemplate( $obj, $arrName )
{
unset( $obj->{$arrName} );
$obj->{$arrName} = array();
$template = json_encode( $obj );
$splitter = '"' . $arrName . '":[';
$parts = explode( $splitter, $template );
$parts[0] .= $splitter;
$this->_templateTop = $parts[0];
$this->_templateBottom = $parts[1];
return $this;
}
//————————————————————————
public function addOutput( $filename = null )
{
$this->_outputs[] = new outStreamJSONOutput( $filename );
return $this;
}
//——————————————————————————
public function addLineHandler( $cb )
{
$this->_lineCb = $cb;
return $this;
}
//————————————————————————
public function render()
{
foreach( $this->_outputs as $output )
{
$output->out( $this->_csrfHeader . $this->_templateTop );
}
while( $line = call_user_func( $this->_lineCb ) )
{
foreach( $this->_outputs as $output )
{
$output->encodeRow( $line );
}
}
foreach( $this->_outputs as $output )
{
$output->out( $this->_templateBottom );
}
}
}

Combining CSV Files and Verifying Line Count

Situation:
1500 .csv files bogging down an import system due to the number of files.

Solution:
Combine files into 1 file.

Problem #1:
All files have a header row with field names.

Solution #1:
Combine all the files while stripping off the

find . -name "*.csv" | xargs -n 1 tail -n +2 > big.csv

Problem #2:
I’m not sure if I have all the lines I should.

Solution #2:
Verify number of lines in the file and compare to row count from a database.

sed -n '$=' big.csv

Problem #3:
This removed the header row that I need at the very top of the file.

Solution #3:
Create file (header.csv) with a single line containing the field names that we stripped off earlier.
Then take header and big and combing them into our final csv file:

cat header.csv big.csv > final.csv