Exploring BlueMix

I just got a trial BlueMix account from IBM.  I will begin to play with it.  I like to map out such efforts in a special shell solution which I call sbshell.  Generally, I iterate between the shell and editor to begin to create a functional library.  In many cases, shell will not be part of the final solution, but it gives me a good place to start and allows me to quickly turn incidents and problems into working prototypes.

 

john@purple:/var/www/html$ sb.init
Reload web...
Reload site5...
Reload web...
Reload svg...
> sb.vi bluemix  

This creates an initial set of bash library files named ‘bluemix’, the first is local to my user, and the second is global. Both libraries are sourced into the environment after each save. I will then create a bluemix function that will run successfully, but will just ssh into my remote instance by default. In it I will store everything that I know about bluemix and begin to add functionality. It is like a scratchpad that becomes a launchpad.

#!/bin/bash

-() { return; }
---() { return; }

bluemix() {

--- bluemix
  - Image ID:c3432649-385b-4b7a-909d-80ba79d5e84b
  - flavor ID:1
  
ssh linux1@148.100.5.125
}

The build just finished a new instance that I created, so I grabbed a bit of information that might be useful later and set up my ssh keys.

john@purple:~/.ssh$ bluemix
Last login: Wed Jul 19 14:48:00 2017 from 173.175.254.4
==============================================================================
Welcome to LinuxONE Community Cloud!

This server is for authorized users only. All activity is logged and monitored. 
Individuals using this server must abide to the Terms and Conditions listed here: 
https://developer.ibm.com/linuxone/linuxone-community-cloud-terms-conditions/. 
Your access will be revoked for any non-compliance.
=============================================================================
[linux1@bleugren ~]$ 

So now I have a pretty basic Jailshell to begin working from and some rough documentation of what I did. If come back and structure the
lines that start with ‘-‘ a bit better, then I can overload the – function to act in certain ways, the following line could be caused to execute a curl against the api, if I were to be allowed access to imageId. What is nice is that I don’t have to fully define that functionality right now.

- bluemix.imageId c3432649-385b-4b7a-909d-80ba79d5e84b

This way of thinking and coding is to supplement work in other languages, such as Nodejs or python and make Enterprise level connections which can be, for instance, scripted in conjunction with an ansible hostlist.

Enterprise DevOps (like System Administration) is often done it tiny burst between meetings or incidents, and I may work on something one day and not look at it again for two weeks.  These conventions may seem trivial, but over time I am able to keep track of many different projects.

[ note: I recommend getting a free trial of bluemix, it was easy to configure and get to a point where docker was installed and available. ]

 

Functional Scripting tricks

As I code and work more and more in this field of Information Technology that is now begin called DevOps, I begin to develop certain tricks that I form into a style.

Here are a few to play with:

- () { return; }

Now you can use the ‘-‘ at the beginning of a line as way
to leave comments. You should probably use this for structured comments that you might want to grab via reflection.

color() {
# The next line is functionally a comment too.
- alp color white red green blue
# If you overload the '-' function, then
# the color comment will become a function call
 if [ -n $1 ]; then
     case $1 in
       white)  FG='00m' ;;
       red)    FG='31m' ;;
       green)  FG='32m' ;; 
       blue)   FG='34m' ;;
      esac;
      printf "\033[$FG";
  fi
}

You can experiment around with what symbols you can overload in this way. So far, I found:

, . - + @

In what my structured comment line, I begin with the word ‘alp’. I will now define what ‘alp’ does.

# alp creates a function for each option defined
alp ()
{
- alp $1 $2
T=/tmp/$$
echo "$1.$2() { $1 $2; }" > $T
source $T
rm $T
}
alp color red
alp color blue
alp color white
alp color green

Now you have four new functions, one for each color.

declare -f color.red
color.red ()
{
    color red
}

So this is how I play with bash. It is very similar to how one might approach golang, python, or other functional languages.

Dealing with the “Silicon Valley” tabs versus spaces argument

The whole issue, of tabs versus spaces, which was dealt with on “Silicon Valley” last week, is easily resolved. No need to lose your super-genius girlfriend. In the show, she is shown hitting the space bar over and over when she could just hit tab a few times.

Of course the issue is that tabs can be interpreted visually in very different ways. Microsoft Word seems to want you to reset your tab stops for each line, or some other foolishness that I can’t quite wrap my brain around.

The answer is that you can use whatever you want, and can use .vimrc to change tabs to spaces if necessary. Since I am not working on the Linux Kernel, and often work with YAML, I have expandtab and tabstop set to 2. This allows me to nest loops with 2 spaces and never create a YAML file with tabs (which throws an error).

set tabstop=2 softtabstop=0 expandtab shiftwidth=2
— from .vimrc
 

 http://tedlogan.com/techblog3.html

Realtime OOP PHP SVG coding

Today I am devoted a bit of time to object oriented laser cutter controls. Although the 3d printer is wildly useful, I find that the things that I can create with it are simply too small and too fragile. The laser cutter, on the other hand, allows me to create large and stable objects. By creating jigsaw pieces, large boxes can be made. The pathing is tricky because the width of the laser must to taken into account. Each segment must be moved slightly in various directions in order to create a tight fit.

toolpath

Above is the finished product, ready to go to the Dallas Makerspace for test cutting.  I will only cut the green line, because it takes into account the width of the laser.  Below is a screen capture which shows how I work.  I run with a 5 second page refresh so that I can keep my fingers working on the code instead of mousing over to my browser.  Below is a snipped from the heat of the battle.  I just hardcoded in my path, as you see that I wasn’t quite finished defining my polygon below.   Next I will need a better separation of data and code, but I had to just get a prototype up and running first.  This way I know what is possible and reasonable and can now refactor in more flexibility.

Screenshot from 2016-05-30 11:13:12

http://secretbeachsolutions.com/svg

https://github.com/johnrigler/svg

box

Now I see the next calculation that I need to make. The male and female pieces fit snugly together, but now I need to adjust the side lengths and how deep the joining sections go. One problem solved, and on to the next.

Introducing sbstats (DevOps performance tracking)

For many years now, I have been capturing vmstat output and displaying it in a graphical LAMP solution.  It can load quickly into various graphing images that can be easily pulled down to your computer to annotate, or attached directly into emails.

sbstats

The page above shows many servers, one after another, in an easy-to-view stream.  Each line of graphs represents one week, so that one can quickly learn “the story” of how a server has been performing over time.  Memory leaks and i/o waits are especially easy to spot.  But the interface is also flexible enough to handle other data, provided that it is saved in the correct format.

sbstats2

sbstats4

 

Minecraft circle creator

I am spending some time revisiting and documenting some of my favorite php solutions.  They are all very light-weight and flexible.  This first one is a minecraft circle generator. You are supposed to pull up a circle size and then use it as a template in minecraft.  As you build levels upon levels, you will create large domes.

minecrafthttp://rigler.org/minecraft/

Here is an example of just starting out on the side of a hill.

ingame

The law is like a programming language

Programing languages are made up of little functions, one might pop up a box that says: “Do you really want to quit?” and will have little “Yes” or “No” buttons. You really would imagine that this would lead the program to end, but depending on how the function is written, it might not necessarily do that. It might assume that the programmer is going to make the thing end some other way. In fact, it could be made to fire up the printer. That would be really strange, but it could easily be done.

Now imagine that the total body of laws is like a computer language and that the little piece of the program (function) that asks if you want to quit is like a new piece of legislation. It could be used in unexpected, and even nonsensical, ways if judged and lawyers concluded that it could. Imagine if some law accidentally gave a legal advantage to people who periodically blew a bugle when publicly speaking. Thousands of bugles would be sold and used, no questions asked.

So if we can begin to see the law as amoral (neither moral or immoral), then we can best make use of it. This is especially true for laws regarding religion. As the conservative Supreme Court and state governments roll out more laws protecting religious freedom, expect more and more groups making odd claims to being religious. The problem is that if they build their case correctly, like a computer program that acts strange but doesn’t crash, then they “will” legally be religious. Strange days are sure to come.

Hacker Challenge/online SVG creation tool

Hacker Challenge:

I have created a little online tool that creates SVG images that can be sent to the laser printer. It is built on top of bash and so can do stuff in a pretty clear way that you can’t quite do with other tools that I have found. The example below shows off nested loops, variable assignment, and function creation. Because it is generally considered a HUGE security hole to allow shell access from cgi, I have tried to make this as secure as possible. I have even gone so far as it isolate it (for now) into its own domain and site. I have used restricted shell and allow access to a directory that only has ‘bc’ and ‘sed’ in it (which I show in the example). Can anyone point out how the nefarious hacker could foil this? Also, feel free to play with it and try to print from it. It seems like now you have to save into inkpad and create a xps file, but I printed this image out the other day. I will stop working on this site and branch off another one for development since most websites don’t change as the hacker tried to get in. Also, the real-time graphics only work in firefox, probably a minor coding error to get them to work in IE. (Someone already asked about javascript, I think that might be a way to do it, perhaps with a buffer overflow).
Go to the challenge