Brad Lucas

Programming, Clojure and other interests

Ethereum Get Eth Balance Script

July 27, 2017

The site Etherscan allows you retrieve information on accounts and transactions. There is an interface to the Reposten testnet as well. While doing some work on a project I was monitoring the page to view an account balance and ended up creating a script to do the monitoring programmatically.

The repo listed at the bottom of the page contains the python script which simply parses the page and returns the balance.

The main routine after figuring out which chain the user wants to look at and which account is the get_balance routine. It parses the page and finds the balance in the first table's first row, second cell.

def get_balance(url):
    html = requests.get(url, headers={'User-agent': 'Mozilla/5.0'}).text
    soup = BeautifulSoup(html, "html.parser")
    table = soup.find("table", {"class" : "table"})
    value = table.findAll('td')[1].text.split(' ')[0].strip()
    return value


Continue reading →

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:


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.


Continue reading →

Csv Headers

July 23, 2017

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

#!/bin/bash

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

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

Continue reading →