Using Curl In Bash For Endpoint Rest Testing


Sometimes I am shelled into an environment or server that I cannot revers proxy through and I can’t run programs like Postman or Advanced Rest Client, which are great programs. I use the following aliases inside my .bashrc files in every server I set up because of how useful they are. This way we can test if a server has access to a particular endpoint or we can see the response of an endpoint called from the server.

# curl aliases
alias get='curl -X GET'
alias geti='curl -i -X GET'
alias post='curl -X POST'
alias posti='curl -i -X POST'
alias put='curl -X PUT'
alias puti='curl -i -X PUT'
alias delete='curl -X DELETE'
alias deletei='curl -i -X DELETE'

Single Line Program to Access a Docker Container


I have several docker images I have pulled down and running in several containers on my server. As images update I destroy the old containers, remove the old images, and bring up the new images in a new container. Instead of running the following as root:

docker ps
CONTAINER ID        IMAGE                             COMMAND                CREATED             STATUS              PORTS                              NAMES
9ff50d7099b1        zaphinath/apirecisphere:latest    "/nodejs/bin/npm sta   46 hours ago        Up 46 hours         8080/tcp,>9800/tcp   gloomy_albattani    
f2104cfaab88        zaphinath/apivietnamdocs:latest   "java -Djava.securit   2 days ago          Up 2 days >8080/tcp             romantic_davinci 

You then have to find the container id and execute the following to enter the container if you ever need to debug something.

docker exec -it <docker_id> bash

There is a much easier way to accomplish this. I have a folder called bin in my home directory that contains lots of quick execution scripts and I have one for each of my docker containers. This allows me to access them when I need.

docker exec -it `docker ps | grep recisphere | awk '{print $1}'` bash


This does not work as an alias because when the .bashrc loads the docker container id is loaded when the bashrc file loads. If the image updates you would have to reload the bashrc source to make an alias work. Having a small bash executables is a good alternative.

How to become a software developer

How to become a software developer

I am a software engineer and I often have people, whether they are in marketing, customer support, business development, or any other various positions in companies I have worked for, ask me “How to become a software developer?” So you want to learn to code. One of my favorite stories of all time comes from a legend of a young man who asked the Greek philosopher for his knowledge.

There’s an old legend about a proud young man who came to Socrates asking for knowledge. He walked up to the wise philosopher and said, “O great Socrates, I come to you for knowledge.” Socrates then led the young man through the streets, to the sea, and chest deep into water. Then he asked, “What do you want?” “Knowledge, O wise Socrates,” said the young man.

Socrates put his strong hands on the man’s shoulders and pushed him under. Thirty seconds later Socrates let him up. “What do you want?” he asked again. “Wisdom,” the young man sputtered, “O great and wise Socrates.”Socrates crunched him under again. Thirty seconds passed, thirty-five. Forty. Socrates let him up. The man was gasping. “What do you want, young man?”

Between heavy, heaving breaths the young man wheezed, “Knowledge, O wise and wonderful…” Socrates jammed him under again Forty seconds passed. Fifty. “What do you want?” “Air!” the young man screeched. “I need air!” “When you want knowledge as you have just wanted air, then you will have knowledge.”

I firmly believe that if anyone wants to learn they will not passively try to attain it. He or she will thirst for learning until that thirst can be quenched. If a person wants to become a programmer that is a great goal, but it does not happen over night. This is why software engineers are some of the highest paid professions in the U.S. Personally I think everyone should program, and if you desire to learn this article is just a short list of what I classify as “Critical” concepts to know as you learn. Think of this as a road map to point you in a direction. The rest is up to you.

Data Structures – Methods used to store information

There are so many programming languages in the world to chose from, and new ones are written every day. Understanding some basic data structures is crucial because all languages share this concept. We will start with what is called primitive types and expand from there. Think of primitive types like parts for building a house. You have cement, wood, shingles, drywall, and etc. Each part has a specific function to accomplish. You can then take the wood and arrange it in such a way to build walls. You can then take those walls and build rooms. Primitive types are similar. A primitive type can be organized to build a new data structure, which then can build a new one. Just like a carpenter or construction worker needs to understand what his building materials are he has to work with, a software engineer has a tool belt and one of his tools are data structures.

Let’s look at java as a building example. Java has eight primitive types.

  1. byte
  2. short
  3. int
  4. long
  5. float
  6. double
  7. char
  8. String
  9. boolean

A detailed explanation of these types can be found on Oracle’s Website.

Once you have a basic understanding of primitive types you can begin to arrange the primitive types into more complex data structures. The number of different data structures is comprehensive. I will only mention a few in this article. For a more detailed list any one of these books from Amazon will be full of great information.


An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. An example could be an array of chars that would write the word “Hello” and it would look like this [H][e][l][l][o].


An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.


A tree data structure is a powerful tool for organizing data objects based on keys. It is equally useful for organizing multiple data objects in terms of hierarchical relationships (think of a “family tree”, where the children are grouped under their parents in the tree). The following is a visual of this. Trees are essential to more complex functionality. A great example is how google knows what you meant to type. IE: If I type the word “wrogn” and I meant to type “wrong” Google knows what you meant to type by using a structure known as a Trie Tree.

Object Oriented Programming – OOP

The concept of object oriented programming is to organize your classes based off of real life objects. Example: Say I am trying to organize a list of people who live in an various cities I could use the following java class.

public class Person {
    private String name;
    private String title;
    private String address;
     * Constructor to create Person object
    public Person() {
     * Constructor with parameter
     * @param name
    public Person(String name) { = name;
     * Method to get the name of person
     * @return name
    public String getName() {
        return name;
     * Method to set the name of person
     * @param name
    public void setName(String name) { = name;
     * Method to get the title of person
     * @return title
    public String getTitle() {
        return title;
     * Method to set the title of person
     * @param title
    public void setTitle(String title) {
        this.title = title;
     * Method to get address of person
     * @return address
    public String getAddress() {
        return address;
     * Method to set the address of person
     * @param address
    public void setAddress(String address) {
        this.address = address;
     * Method to get name with title of person
     * @return nameTitle
    public String getNameWithTitle() {
        String nameTitle;
        if (title != null) {
            nameTitle = name + ", " + title;
        } else {
            nameTitle = name;
        return nameTitle;
     * Method used to print the information of person
    public String toString() {
        return "Info [" +
                "name='" + name + ''' +
                ", title='" + title + ''' +
                ", address='" + address + ''' +

Then in some other class we can call Person person = new Person() to initialize this object. A class should accomplish one main goal and do that really well. When a class starts to do more than one thing you should think of splitting that class into two objects. Once you start to understand the basics of objects and how to use them start looking into more advanced concepts of OOP such as Inheritance, Polymorphism, Abstract Classes, and Interfaces.

Big O Notation

Big O Notation is a way of calculating the impact of performance of different design ideas. A lot of languages can let you write really bad code. Understanding how your decisions affect speed is very important. Making your algorithms faster is really important when dealing with embedded systems, games, or mobile applications. Big O Notation

Use an IDE

When I was in college I was taking CS240 – Advanced Programming Concepts. About one third into the semester all students are required to take a programming test. No internet was allowed and we had to write a program assigned to us within three hours. I had ever used VIM, which is still a great tool, and I proceeded to program using vim. I barely made the cutoff time in three hours. I quickly learned that I needed to use a more powerful tool to help me with simple method calls and syntax errors as I was typing and not just when I was compiling my code.

From that point on I have used an IDE. IDE stands for Integrated Development Environment. IDE’s help users understand the methods that are called, help users understand syntax problems, can quickly create classes and refactor code, and above all have GREAT debugging tools available.

I have used various different IDE’s and two of my favorite free ones are either IntelliJ or Eclipse. If you don’t use an IDE – you should. They will bless your life.


How to become a software developer? In conclusion if you want to be a developer or engineer just keep learning as much as you can. Implement what you learn. Although there is no substitute for experience, getting your degree will also help fill in all the gaps that can arise from being self taught.

Using NginX Route to Plex Server Behind Firewall.


If you have a router and want to limit access from the outside world to all the computers inside your home, then you will probably want to set up a server in a DMZ or forward specific ports to it. This open server can then route traffic to anything behind the firewall for you — acting as a proxy. I have used both Apache and Nginx, I like both, but In this article I will show an example using Nginx. Nginx has been proven to be able to handle more concurrent requests than apache and it is very lightweight.


There are lots of tutorials on the internet that show how to install and configure nginx. The general idea is when you install nginx there are to folders (usually in /etc/nginx/) called sites-available and sites-enabled. Good practice is to make a conf file inside the sites-available directory. Then execute the following command:

nginx -t

Once the configuration file is syntactically correct you can do a symbolic link to the same filename in sites-enabled. The following configuration shows one of my configuration files that routes request to to my plex server behind the firewall. If own a domain name then you need to edit the zone file and make an A record that points to the IP address of the router. When you then request the traffic will hit your router, go through the firewall to the server, and be proxied to another location via nginx.

NGinX Server Diagram


upstream plex-upstream {
	# change to the hostname:port of your plex server.
	# this can be "localhost:32400", for instance, if Plex is running on the same server as nginx.
	server <ActualServerAddress>:32400;
server {
	listen 80;
	# server names for this server.
	# any requests that come in that match any these names will use the proxy.
	server_name plex.<your_url>.com;
	# this is where everything cool happens (you probably don't need to change anything here):
	location / {
		# if a request to / comes in, 301 redirect to the main plex page.
                # but only if it doesn't contain the X-Plex-Device-Name header
		# this fixes a bug where you get permission issues when accessing the web dashboard
		if ($http_x_plex_device_name = '') {
			rewrite ^/$ http://$http_host/web/index.html;
		# set some headers and proxy stuff.
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_redirect off;
		# include Host header
		proxy_set_header Host $http_host;
		# proxy request to plex server
		proxy_pass http://plex-upstream;

Node.js Webapp In a Docker Image – MEAN


Node js applications are great for proof of concepts and getting apps made in a short amount of time. Running them inside a docker container is a great security blanket and lets applications be versioned much like software version control. This is a quick code snippet of a nodejs server using express. This is then packaged into a docker image that can be deployed to any machine running docker.



  "name": "apiTest",
  "version": "1.0.0",
  "description": "API for",
  "main": "server.js",
  "private": "true",
  "scripts": {
    "start": "node server.js"
  "author": "Derek Carr",
  "license": "MIT",
  "url": "",
  "dependencies": {
    "body-parser": "*",
    "express": "^4.13.3",

Express JS


var express = require('express');
var bodyParser = require('body-parser');

// Server Vars
var app = express();
var port = process.env.PORT || 9800;

//Configuration of App
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
// Add headers
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
app.set('trust proxy'); // trust first proxy

app.get("/test", function (req, res, next) {

app.listen(port, function () {
console.log("Server started @ " + port);

module.exports = app;


One of the benefits of Docker Images is the layers we can make. Most tutorials on the internet show that you need to pull down an ubuntu or centos image, install node, and do all sorts of updates to the machine in order to run npm apps. Google has a repo in where they took the time to build a base image and strip it down to the bare essentials to run node apps. This makes your total image size smaller and all you have to do as a developer is make sure your package.json has the right dependencies.


FROM google/nodejs-runtime

MAINTAINER Derek Carr &lt;;

ADD package.json /app/
RUN npm install
ADD . /app


CMD []
ENTRYPOINT ["/nodejs/bin/npm", "start"]

Building The Image

This lets

docker build -t $DOCKER_IMAGE:$TAG .
docker push $DOCKER_IMAGE:$TAG
#Clean up docker images
docker images | grep "$DOCKER_IMAGE" | awk '{print $3}' | xargs docker rmi


You need to have docker installed and the daemon running. You also need to be logged into docker – which can be done by running docker login from the command line.

Organizing workbench tools


I have been accumulating a few tools over the years and now is the time to start organizing them. I didn’t like the idea of loose hooks or not knowing where the tools belong, however, with some cheap black paper and locking hooks I have a solution.


  • Two 2×4 white pegboards ($6-8)
  • Three sets of 32-Piece Locking Peg Hook Assortments
  • Spacers + screws or strips of wood for mounting the pegboard onto your wall. I just bought some discounted wood, sized it, and attached it to the wall.

Knowing where your tools belong

Installing the pegboard and the pegs is pretty easy. I know when I work on projects I end up with several tools on my bench that I will need to put away when I’m finished. I want to make sure I return the tools to their rightful spots on the wall. My solution was to buy some recycled black paper from a dollar store, trace my tools on it using my tools as a stencil, cut them out, and tape them behind the tools.

pegboard backdrop

Multiple environments through GEB

I’ve recently been experimenting with GEB, which is a selenium framework that uses the groovy language. One of first challenges I encountered was trying to switch between multiple environments, instances, subdomains, or base urls. GEB uses a config file called GebConfig.groovy that is a standard groovy configuration file. This file is read by the ConfigSlurper class. The ConfigSlurper takes in different environments in the constructer. I also wanted to be able to switch environments based on a command line overwrite – either ANT or Gradle. The following is a small example on how to setup multiple environments that can be changed by a command line override.

def user = ""
def pass = ""

environment = System.getProperty("test.env", "example1")

switch(environment) {
  case "example1":
    user = "foo1"
    pass = "foo2"
    baseurl = ""

The command line override in this case would be:

gradle -Dtest.env=example1 

VGA Synchronization Driver for FPGA


In order to use the VGA connection on an FPGA there needs to be a vga timer that can change the pixels as it goes across the screen. I won’t go into detail here about VGA standards, or how the horizontal and vertical refreshes work, but rather just give some example VHDL code that will refresh a screen that is 640 X 480 pixels in size. This can then be declared as an entity in other VHDL code that can generate blocks and other movements on the screen.


Port Name Direction Width Purpose
clk Input 1 Input clock (50 MHz)
rst Input 1 Asynchronous reset
HS Output 1 Low asserted horizontal sync VGA signal
VS Output 1 Low asserted vertical sync VGA signal
pixel_x Output 10 Indicates the column of the current VGA pixel
pixel_y Output 10 Indicates the row of the current VGA pixel
last_column Output 1 Indicates that the current pixel_x correspond to the last visible column
last_row Output 1 Indicates that the current pixel_y corresponds to the last visible row
blank Output 1 Indicates that the current pixel is part of a horizontal or vertical retrace and that the output color must be blanked. The VGA pixel must be set to “Black” during blanking.

Screen Shot 2013-12-24 at 10.56.10 PM


library IEEE;

-- arithmetic functions with Signed or Unsigned values

entity vga_timing is
    Port ( clk : in  STD_LOGIC;
           rst : in  STD_LOGIC;
           HS : out  STD_LOGIC;
           VS : out  STD_LOGIC;
           pixel_x : out  STD_LOGIC_VECTOR (9 downto 0);
           pixel_y : out  STD_LOGIC_VECTOR (9 downto 0);
           last_column : out  STD_LOGIC;
           last_row : out  STD_LOGIC;
           blank : out  STD_LOGIC);
end vga_timing;

architecture vga_timer of vga_timing is

signal pixel_en, row_en, visible, column_intermed: STD_LOGIC;
signal horiz_counter, vertical_counter, nexthcount, nextvcount : unsigned (9 downto 0) := (others=>'0');


--toggle register for pixel en, giving 25MHz clk
if (rst = '1') then 
pixel_en <= '0';
elsif (clk'event and clk = '1') then
pixel_en <= not pixel_en;
end if;
end process;

--horizontal pixel counter register based off of pixel_en
if (rst = '1') then
horiz_counter <= (others => '0');
elsif (clk'event and clk = '1') then
        if (pixel_en = '1') then
        horiz_counter <= nexthcount;
        end if;
end if;
end process;

nexthcount <= (horiz_counter + 1) when (horiz_counter < 799) else
                                        (others => '0');
pixel_x <= std_logic_vector(horiz_counter);
column_intermed <= '1' when (horiz_counter = 639)
                                        else '0';
row_en <= '1' when (horiz_counter = 799) else 
last_column <= column_intermed;
HS <= '0' when ((horiz_counter > 655) and (horiz_counter < 752))
                else '1';
--vertical pixel counter increments only with last_column
if (rst = '1') then
vertical_counter <= (others => '0');

Connecting to an API WSDL through Java REST


Java seems to have a pretty decent library for dealing with WSDL soap transactions, however there doesn’t seem to be any great library out there for dealing with rest. The solution is to using java’s built httpconnection library to post the information to the appropriate url and wait for a response. For REST protocol we will first encode a JSON array that contains the proper commands and parameters according the WSDL API you are trying to interface with. Next the JSON encoded array is posted to a url, which should return a response that can be processed.

Encoding in JSON

The first thing to do is look at the API’s web service description language to see the format of the JSON encoded array should be made. The following is an example from the WSDL. This method call is meant to delete a lead from the system.

public int deleteLead(int leadId, boolean purge) {
		int returnLeadId = 0;
		JSONObject json = new JSONObject();
		JSONArray list = new JSONArray();
		try {
			json.put("operation", "deleteLead");
			json.put("parameters", list);
		} catch (JSONException e) {
		String response = wsm.sendJson(json);
		returnLeadId = Integer.valueOf(response);
		return returnLeadId;

The method wsm.sendJson(json) is in the next section. I made a wrapper class to handle various api connections and responses. I put these all in a class I called WebServiceManager.


Once we have the JSON encoded array we need to post it to the appropriate URL. Any WSDL documentation should give the url that the JSON object should be posted to. This means we need to have a function that will allow us to use Java to make the post.

	public String sendJson(JSONObject json) {
		HttpResponse response = null;
		httpClient = HttpClientBuilder.create().build();
		StringBuilder sb = new StringBuilder();
		try {
			request = new HttpPost(destination);
			StringEntity params = new StringEntity(json.toString());
			request.addHeader("content-type", "application/x-www-form-urlencoded");
			request.addHeader("Cookie", this.cookies);
			response =  httpClient.execute(request);
			InputStream ips  = response.getEntity().getContent();
	        BufferedReader buf = new BufferedReader(new InputStreamReader(ips,"UTF-8"));
	        if(response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
	            throw new Exception(response.getStatusLine().getReasonPhrase());
	        String s;
	        while((s = buf.readLine()) != null) {
		} catch (Exception e) {
		} finally {
			try {
			} catch (IOException e) {
		return sb.toString();

http map

The image to the right shows the basic idea of how the hypertext transfer protocol works with a post request. Almost all API’s that exist will require some type of authentication, which I don’t show here, but you do some type of a login method and the server will send back a session id or some type of a cookie that you can store and use for subsequent methods so you don’t need to authenticate with every API request. This is why we send the cookie that we got from authentication with every request. The actual JSON encoded array of commands and parameters goes in the entity body of the post. After the server responds saying that the request is good we can read the response from the server.

Decoding JSON

In the previous section we send an http post request, and then read the response stream. The method deleteLead in this case returns the id of the lead that was deleted, so I just parse the string into an integer and handle it as I need. Other methods such as getLead will return a whole lead object, and in this section the JSON encoded response array will need to be decoded and put into a lead object.

String response = wsm.sendJson(json);
returnLeadId = Integer.valueOf(response);
return returnLeadId;

Project Organization

I have put this off for too long now – I am finally collecting all my projects, both personal and school related, and putting them up on github. Zaphinath’s GitHub repository. I have been using SVN and git for sometime on my own boxes. There are things I like about both and things I dislike. SVN has better version control and reverting abilities, but git is better to fork and merge code. Check out the repository sometime!