Where I’m at …

  • Permaculture

    I finally received my Permaculture Design Certificate. I did 150 hours of course work, read the entire manual of 500 pages of small print, and listened to the entire 80 hours of Bill Mollison’s version of the class from 30 years ago, … before doing my final design and passing the class.

    PDC Certificate
    Now, I’m a professional Permaculture Designer, if I choose to be one. Note: 06/01/2018 is Jan 6, 2018 for those who are more familiar with US date formats.

    Permaculture Quick Start

    Permaculture? Is it swales? What on earth is a swale?

    Swales are a dry-climate, tree-growing system. Permaculture may use swales, but that is a small, small part of permaculture.

    Permaculture is often described as “Permanent Agriculture.” However, Permaculture is better described as “Permanent Culture.” That includes:

    1. Earth care
    2. People care
    3. Returning surplus

    Permaculture transcends politics, religion, and country. You can throw a prepper, a tree hugger, a Muslim, a Buddhist, a capitalist, and a communist into the same permaculture class and have them all walk away determined to use the knowledge they gained in their individual pursuits. In fact, I’ve seen that happen.

    (more…)

  • Solidity

    Need Solidity based smart contracts for the Ethereum blockchain? Then you’re at the right place. Solidity based smart contracts are the next disruptive technology for the 21st century.

    By now, everyone has heard of Bitcoin. The longstanding second most popular cryptocurrency is Ethereum. However, the difference between Bitcoin and Ethereum is like the difference between paper dollars and gold. Paper dollars have no value, except good faith. Gold has uses in industry and science in addition to being tradable as money.

    Ethereum is like gold. You can trade Ethereum as a cryptocurrency, and many do. However, you can also use the Ethereum blockchain to create unstoppable, uncensorable, massively distributed applications. The Ethereum blockchain can host applications and data, making it the next big disruptive technology.

    Imagine if you could have got in on the ground level of social media, search engines or even the Internet. The next huge disruptive tech is sitting out there. It is the Ethereum blockchain.

    Solidity based smart contracts allow for the development of publicly verifiable information. You can place keys on the blockchain proving authenticity of everything from land titles to certifications and diplomas. Using blockchain apps made with solidity, you can set publicly verifiable contracts up, or set payments or information to be released at some future date.

  • The Lowly Comment

    The first rule taught in software development is, “Comment your code with a reason or purpose for its existence.” This is to say, “Why does this variable, method, or class exist?”

    Here’s why.

    Heavily used code always suffers from purpose creep. Purpose creep leads to expensive bugs. For example, I once found a bug in code used by hundreds of corporate customers that consisted of a variable being used for two purposes. Most of the time, the variable value was the same value for both purposes. However, after selling the software for many millions of dollars to 100’s of clients that expected to never change their integrations with our code, we had a problem that required new installations and new integrations.

    Talk about a preventable problem. One comment explaining the purpose of one variable could have saved the company millions of dollars worth of angry customers.

    To prevent purpose creep within a class, method, or variable, stick with the purpose described in the comment, or change the comment. It’s very easy for a maintainer of old code to assume the purpose of a well named variable, but not realize the actual purpose is similar, but not the same as he thinks it is.

    The first rule of programming that is thrown out the door in the workplace is, “Comment your code.” Even at the better companies I’ve worked for, almost no one comments their code. Some developers live in a fantasy world where class names, method names and variable names give all the architectural details needed to understand millions of lines of code. I once ran into a 45,000 line class with no comments. I even worked for a company that forbade comments, and you could get called in for a talk with your manager if you made the mistake of leaving a comment in your code–very Dilbertesque.

    Every codebase has blocks of code that are so important that they are called constantly. And when an edge case is found, those blocks of code get a conditional thrown in to handle that edge case. Then another edge case is found and a new parameter is passed in to handle that edge case. Another developer under tight deadlines realizes the code is perfect except, it needs to handle his case where ….

    As a result, almost every important method and class suffers quickly from purpose creep. By this I mean that if you found someone that actually understands the class or method in question, it will take minutes and sometimes hours for them to describe what is going on in the class or method.

    Soon, the most important code in your application is too fragile to change. Ten or twenty edge cases that no one remembers have infiltrated your most important code. And worse yet, there are no comments explaining what can brake if even a minor change happens to your code. Then a maintainer of the code gets stuck working nights and weekends making changes to once simple software.

    Detailed commenting of important code helps prevent fragile code. Have a concise explanation of purpose of your code. If the comments are getting hard to follow, then it is time to refactor the code into easily described chunks. Maybe move those edge cases out into their own methods or classes.

    Comments containing clear purpose statements can prevent working late nights, lost customers, and even save your company millions of dollars. There’s a lot to be said about the lowly comment.

  • Replacing Java’s finalize() Method

    If you’ve reached Java 9 or above, you’ll notice at some point that the Java’s Object.finalize() method is deprecated. A quick look at the JavaDocs doesn’t give any easy solutions for a quick replacement. (Good luck with PhantomReferences, btw.)

    So here’s a drop-in replacement that should have been documented, but I haven’t seen anyone mention this on Stack or anywhere else. Use a cleaner. If what you’re doing is simply destroying references, or something else similar, put the following code in your Java class constructor and copy the guts of finalize() into it. Then delete your old finalize() method.

    Now you’re Java 9 compliant.

    What you’re doing with this code change is creating a Runnable that is called when the Cleaner detects that your Object is in need of cleanup.

    If you want to get really fancy, create only one cleaner and reference that one cleaner to register your objects during construction. That’s probably what you’ll do in any app that has a lot of objects that need cleaning up.

    Here’s some code to make it a bit more clear how to use a Java Cleaner to replace a finalize() method.

    First the CleanersExample class:

    Next the Main class to use the CleanersExample class:

    The output will look something like this.

    Current instance count is 1
    Current instance count is 2
    Hi!
    Hi!
    Current instance count is 1
    Current instance count is 0
    All done!

  • Programming Puzzles and Challenges

    One of the funnest ways to learn new languages and sharpen your coding skills is to do coding challenges and puzzles. There are even competitions arranged around solving computer programming challenges and puzzles. Also, don’t be surprised if some of the problems listed show up in job interviews. This is a common way to filter out good programmers from not-so-good programmers when interviewing.

    Here’s a list of nice code challenge sites. If you have a favorite I don’t have listed, please contact me and let me know.

    Code challenges and puzzles

    Rosalind (bioinformatics problems)
    http://rosalind.info/problems/list-view/

    Project Euler
    https://projecteuler.net/

    Code Golf
    https://codegolf.stackexchange.com/questions

    Rosetta Code
    https://rosettacode.org/wiki/Category:Programming_Tasks

    Coderbyte
    https://www.coderbyte.com/challenges

    HackerRank
    https://www.hackerrank.com/dashboard

    CodeChef
    https://www.codechef.com/problems/school

    LeetCode
    https://leetcode.com/problemset/all/

    SPOJ
    https://www.spoj.com/problems/classical/

    **** CodinGame ****
    https://www.codingame.com/faq
    https://www.codingame.com/start

    codeabbey
    http://www.codeabbey.com/index/task_list

    r/dailyprogrammer
    https://www.reddit.com/r/dailyprogrammer/

    Ruby Quiz
    http://rubyquiz.com/

    code_by_math
    https://www.codebymath.com/index.php/welcome/challenges

    Codeforces
    http://codeforces.com/problemset

    Timus Online Judge
    http://acm.timus.ru/problemset.aspx

    L-99 (Lisp-like languages … like Clojure)
    http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html

    4Clojure (Clojure)
    http://www.4clojure.com/problems

    I Deserve
    https://www.ideserve.co.in/

    code jam
    https://code.google.com/codejam/past-contests

    Peking University POJ
    http://poj.org/problemlist

    HIT Online Judge
    http://acm.hit.edu.cn/problemset

  • Lunches for Work

    I’ve got into the bad habit of eating out for lunch when I’m working. Eating out at lunch is pretty expensive. No big deal, until you have a new car payment to worry about. I’ve decided to break myself of the habit, now that I’m once again car poor. (Never like those payments.)

    My first step was buying myself a thermal lunchbox and some of those thin freezer packs to keep frozen and cold lunches cold until lunchtime. Now the hard part.

    What do I buy or make that keeps me from getting food fatigue? Cup-of-noodles is good for once every other week. Leftovers sounds like a good idea, unless you have a house full of teenagers. Then, you don’t have leftovers.

    Food fatigue will **ALWAYS** result in a relapse into eating out for lunch. I need variety, and only have a passing interest in “healthy” lunches. It had better taste good, or I’ll opt for the milkshake and fries.

    I tried googling lunch ideas for work lunches, but google thinks I have two hours to prep my lunch every day, so I can spend 10 minutes eating it. I need extremely simple ideas that I have time for.

    So here are realistic ideas that I can pick from. I’ll add to it as I come up with more.

    Sandwich and chips
    * PB&J … mmmm, I like
    * cold cuts with cheese and lettuce/tomato
    * tuna … nice with pickle relish

    TV Dinners & pot pies

    Noodles

    Pop-top canned soups with crackers

    Hard boiled eggs w/ a sprinkling of pepper and salt

    Frozen burritos or chimichangas

    Make a fancy salad with eggs or chicken

    Make a fancy meal on the weekend and reserve two lunches from it
    * homemade chili with lots of cheese on top
    * steak and potatoes
    * potato bar
    * homemade soup
    * grilled chicken and rice
    * some new recipe

    Have some ideas, throw them my way in the comments section. If I use it for my own lunches, I’ll add it to my list.

  • ReactJS Class Attributes

    React classes have a few quirks that aren’t obvious to developers that are new to React (and maybe the JavaScript universe).

    Classes and Attributes

    ReactJS classes are actually ES6 classes with Babel syntactic sugar thrown in. For example, coming from other languages, you might expect class attributes to use the form

    or

    However, that doesn’t work. In ES6 classes, you cannot add attributes directly to the class. They are actually added after the class is defined–very ugly and painful to look at.

    Babel compiles/transpiles React classes, though. So, you get the ability to add class attributes using either of the following syntaxes.

    or

    The first you access using this, as in this.somevar and the second you access using a the class name,  as in MyClass.somevar.

    Don’t Forget ‘this’

    Since we mentioned this, don’t forget about binding this to your methods before using it. (Bindings in JavaScript are always such a joy.)

    If you create your methods in your ReactJS classes using the arrow method, then you have the class’s this, already.

    However, if you create your methods using the following approach, then this may not be the this you are looking for. (It won’t be the class’s this when you call it.)

    In previous case, bind the class’s this to the method explicitly in the constructor of the class with the following code.

     

  • Clojure Cursive: Write, Run, Deploy

    Some quick notes on writing, running and deploying Clojure apps.

    When using Cursive for IntelliJ, a default Leiningen project is easiest for development. However, using the ‘app’ template in Leiningen sets up a default runnable app that can be packaged quickly into an uber JAR.

    I suggest doing most of the application development with a default project, and then use an ‘app’ project for the deployment.

    The default template for ‘app’ is as follows.

    To run a default app, use the lein run command from the command line. To create runnable JAR from the app template, use the command lein uberjar. You can then run the standalone JAR created in the ‘target/uberjar’ directory of the project.

    Using the REPL with App Templates

    When using the REPL in Cursive from an app template, you might have to set up the run configuration and then register the project.clj with the run configuration. Even once you have stumbled through that process, you may find that you have to change the name space to match you core.clj file’s namespace. And finally, you’ll likely need to load the -main function into the namespace. At that point you should finally be able to run (-main) from the REPL.

    That’s why I do most of my regular development from inside a default lein project instead of the app template.

  • React Component Contexts

    Sometimes when creating a SPA with React, you realize you need some global variables. The easiest way to make values available at all levels of a complex ReactJS application is to use a Context. The following is an example of creating a React SPA with a single global context that shares values at all levels of the component tree. I give two examples of using the context. One is a class based React Component and the other is a function based React Component.

    Two React Components using one global context.
    Two React Components using one global context.

    I used npx  to run createreactapp . Then I added contexts and components folders and the following files to my React src folder.

    (more…)

  • Klaytn Links

    Author’s Note: Lot’s has happened. Klaytn is now Kaia. It got renamed. All the links are old, but I’m going to keep this page around for historical info.

    As the Klaytn blockchain community grows, it gets harder and harder for me to keep track of interesting Klaytn related links. I am putting a few in this post, just so I can remember to look at them later.

    Klaytn Home Page

    This is mostly marketing spin and doesn’t get updated much. I check it occasionally hoping for news and updates, but usually am disappointed.

    Klaytnscope

    Watch the Klaytn blockchain grow in real time. Also, search the Klaytn blockchain for block numbers, account addresses,  transaction hashes, token names, and token symbols.

    Klaytn Wallet

    A wallet for Klaytn with enough disclaimers to make me feel completely unsafe using it, so I don’t. Using on a testnet without any real money involved should be fine for development and testing purposes.

    Klaytn IDE

    IDEs are a developer thing. Klaytn uses the Solidity language, like Ethereum does, for developing Blockchain apps.

    Klaytn Docs

    Even though Klaytn comes from South Korea, they kindly provide an English version of their Klaytn devolopers documentation.

    Klaytn Staking Guide

    This is a YouTube video, and getting a bit old, so follow at your own risk.

    Klaytn Videos on YouTube

    Lots of news, opinions, info on Klaytn. Unfortunately, most of it is in Korean. Look around and you’ll find videos in English, though.

    KLAY/USDT on Gate.io

    Great place to check the current price of Klaytn.