Copy All Pdf Files In Sub-Directories To Another Directory

July 26, 2017

Had a ton of pdf files in numerous sub-directories. The goal was to collect them into a single directory

$ DEST="directory where you want to collect your pdf files"

$ find . -type f -name \*.pdf -exec cp \{\} $DEST \;

Continue reading →

Loading File Into Node Repl

July 25, 2017

So the day after writing a post about working in multiple languages I find myself in front of Node writing in JavaScript. Nothing big to start.

I was writing things in a file and then executing them with node file.js when I decided it was time to work inside the Node repl.

For this the question became how do you load your file and have access to the functions and variables.

The answer:

$ node
> .load file.js
. ... messages

Nicely, after editing the file you can reload it by executing the same again.

Continue reading →

Programming Languages ADD

July 24, 2017

It is common to assume in the programming world that any competent programmer should be able to learn a new programming language in a few days and be productive within a week or so. Many will brag about their knowledge of multiple languages and how they did this in that and that in this.

The whole concept of a full-stack developer speaks to this same idea. These roles require people to know everything from the front-end (JavaScript, CSS, a framework, etc) to the middle-ware (Python, JavaScript, a framework, etc) to the database (SQL).

I've found this myself. In fact, my last project required me to move between Bash, Java, Python and Clojure daily and sometimes throughout the day.

I wonder though if some sort of specialization might be better. In my last project I wished to focus exclusively on Clojure but that didn't work out.

Here is something to consider. Look at a symphony. Each musician is a specialist on one instrument. Sure, many if not all will know how to play the piano. Some will double on other instruments. Many will know how to play each somewhat but each ultimately is a specialist on a single instrument.

Would this work in the programming world? It would be nice especially if you are a specialist.

Continue reading →

Csv Headers

July 23, 2017

To show the headers for each csv file in a directory.


# Echo the header lines for all the cvs files in the current directory

for filename in *.csv;
  # echo $filename;
  line=$(head -n 1 $filename);
  echo $line;

Continue reading →

Bash With An Empty Environment

July 22, 2017

When writing bash scripts that look for environment variables it is a good idea to check that these environment variables exist at the top of the script. For this you do things like the following.

if [[ -z $LOG ]]; then
  echo "Missing LOG environment variable"

Now once you've created your environment variable how can you test your script for the case where the environment variable doesn't exist? For this you can open another bash shell with no environment variables. An empty environment if you will. To do this try the following.

$ env -i bash --norc --noprofile

With this you can test your script and make sure it exits when the required environment variables don't exist.

Continue reading →

Mac Cleaner

July 21, 2017

Ran out of space on the MacBook and found this free Mac cleaner application that worked well.

AppCleaner from FreeMacSoft

Works well.

Continue reading →

Python 3

July 20, 2017


On a Mac here is an easy method to get Python 3 installed.

$ brew install python3

After this step you'll have your original Python 2.7 version as python and your new Python 3 version as python3.

Virtual Environments

I've been in the habit of creating a virtual environment in a directory called env under each project I'm working on. With 2.7 I was using virtualenv. With Python 3 installed this would be a conflict. Nicely, Python3 has it's own method for creating virtual environments through python itself. Simply pass -m venv followed by the name of the virtual environment and you are good to go.

$ python3 -m venv env

Even more nice is the results where after activating your environment you'll find that the mappings for pip3 and python3 are pip and python.

$ source env/bin/activate
(env) $ pip --version
pip 9.0.1 from /Users/brad/tmp/env/lib/python3.6/site-packages (python 3.6)
(env) $ python --version
Python 3.6.1

Continue reading →

Ethereum Wallet To Local Geth Instance

July 19, 2017

The following are some notes on getting an Ethereum Wallet running on OSX to talk to an previously running geth instance.

If you start your experimenting with Ethereum on a Mac you'll most likely begin by downloading the Ethereum Wallet. This application will install geth locally and automatically start an instance of it and know how to communicate with it automatically. In addition there is a menu option to switch between running geth against the public chain as well as the –testnet chain.

At some point if you are developing an application or more of a command-line person you'll start running geth manually from the command line to keep your chain up to date or to rebuild it. At this point you may want to know how to start the Ethereum wallet to connect with an existing geth session rather than complain when you start the wallet and it notices a previous geth instance and then refuses to start.

Here are the details for OSX. The idea is similar for other operating systems. In short you want to pass the geth.ipc filename and location to the Wallet so it can communicate with the existing geth session.

$ /Applications/Ethereum\\ Wallet --rpc $HOME/Library/Ethereum/testnet/geth.ipc

If you are running geth against the public network you'll use $HOME/Library/Ethereum/geth.ipc

Continue reading →

Ethereum Installing Geth On Centos

July 18, 2017

The notes over on when talking about installing geth on a Linux box give instructions using apt-get. Here I have a Centos box and needed an alternative method.

If found that building from source worked just fine using the following steps.


$  sudo yum install golang
$  sudo yum install gmp-devel
$  git clone
$  cd go-ethereum/
$  make geth
$  ls -al  build/bin/geth


$ ./go-ethereum/build/bin/geth

Note: You can move the executable out from the build/bin directory to anywhere you find convenient.

Continue reading →

Ethereum Upgrade Geth

July 17, 2017

If you are running geth on OSX and you need to upgrade to the latest version here are the simple steps to follow:

$ brew update
$ brew upgrade ethereum

For Example

blucas.home:~/Library/Ethereum$ brew upgrade ethereum
==> Upgrading 1 outdated package, with result:
ethereum/ethereum/ethereum 1.6.7
==> Upgrading ethereum/ethereum/ethereum 
blucas.home:~/Library/Ethereum$ geth version
Version: 1.6.7-stable
Git Commit: ab5646c532292b51e319f290afccf6a44f874372
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.8.3
Operating System: darwin

Continue reading →

Ethereum Testnet Faucet

July 16, 2017

While developing for Ethereum and using the testnet you'll need Ether to get things done. You can mine for it of course but there are sites called faucets that will send you Eth for free.

I found the following one today and used it a few times to get my balance in shape to do some testing.

B9Lap Academy

Throttled Testnet Faucet

Ethereum Block Explorer (Testnet/Ropsten)

To very the transaction after you use the faucet visit the Block Explorer at the following link.

Continue reading →

Ethereum Reset Local Blockchain Geth

July 15, 2017

Returning to some Ethereum work I wanted to reset my old local blockchain by deleting it an starting from scratch. Here are notes to describe what to do.

Ethereum Installation Directory

On OSX Ethereum installs in $HOME/Library/Ethereum. The public data is in geth while the testnet directory contains the testnet data.

Remove blockchain and state databases


|-- geth
|   |-- LOCK
|   |-- chaindata
|   |-- ethash
|   |-- nodekey
|   `-- nodes
|-- history
|-- keystore
`-- testnet
    |-- geth
    |   |-- LOCK
    |   |-- chaindata
    |   |-- ethash
    |   |-- nodekey
    |   `-- nodes
    |-- history
    `-- keystore

8 directories, 5 files

Remove the public blockchain data


$ geth removedb

Continue reading →

Programming Competitions

July 14, 2017

The other week I saw this post about programming competitions and how they supposedly correlate negatively to job performance. This was according to Peter Norvig.

I found this interesting because as most will know the typical work of a programmer is very different from a programming competition.

After looking around a bit I found a Hacker News post for the same blog page with some interesting comments.

The one that got me thinking was the one that postulated that interviewing was similar to programming competitions. If you think about it a bit, the similarity's are there in that you are in competition with others and there is a final decision being made about the winner. Also, there typically one or more questions (or challenges) that you must accomplish. These challenges are also typically very similar to ones you'll find in competitions.

This means that though your job won't necessarily involve skills from compeition problem solving your ability to get a job does. With this sites like Hacker Rank will be a useful prerequisite to interviewing for the near future.

Continue reading →


July 13, 2017

An old Perl script for replacing a string within multiple files.

# Replaces a string within multiple files
# specified on the command line

$mv = '/bin/mv';

$op = shift || die("Usage: $0 perlexpr [filenames]\n");
print "$op\n";
print "@ARGV\n";

if (!@ARGV) {
  @ARGV = <STDIN>;

foreach $file (@ARGV) {
  if (!-f $file) { print "Skipping non-regular file: $file\n"; next; }
  if (-B $file) { print "Skipping binary file: $file\n"; next; }

  $outfile = "/tmp/$file.$$";

  open(FILE, $file) || die("Couldn't open $file: $!\n&quot;");
  undef $/;
  $_ = <FILE>;

  if (eval $op) {
    open(OFILE, "> $outfile") || die("Couldn't open $outfile: $!\n");
    print OFILE;

    system($mv, '-f', $file, "$file.bak");
    system($mv, '-f', $outfile, $file);

    print "File changed: $file\n";
  else {
    print "No change to file: $file\n";


Continue reading →


July 12, 2017

Show the amount of disk space the larger directories under your home directory are taking.


pushd $HOME

du -sk * | sort -nr | head


Continue reading →