Quick Code: Repo List

So I ran into an interesting problem over the weekend, I forgot my 2FA token for Gitlab at home while I was away. My laptop’s SSH key was already loaded into Gitlab so I knew I could clone any of my repositories if only I could remember the exact name. That of course turned out to be the problem: I couldn’t remember the name of a specific repository that I wanted to work on. I even tried throwing a bunch of things at git clone to try to guess it and still had no luck. Enter the Gitlab API:

#!/usr/bin/env python3
                                                                                                                    import requests                                                                                                     from tabulate import tabulate
                                                                                                                    personal_token = 'asdfqwerzxcv1234'                                                                             user_id = 'dword4'                                                                                                                                                                                                                      base_url = 'https://gitlab.com/api/v4/'                                                                             repo_url = 'users/'+user_id+'/projects'                                                                                                                                                                                                 full_url = base_url + repo_url + '?private_token=' + personal_token                                                                                                                                                                     res = requests.get(full_url).json()
table = []
for project in res:                                                                                                     name = project['name']
    name_spaced = project['name_with_namespace']
    path = project['path']
    path_spaced = project['path_with_namespace']
    if project['description'] is None:                                                                                      description = ''                                                                                                else:                                                                                                                   description = project['description']                                                                            #print(name,'|', description)                                                                                       table.append([name, description])                                                                                                                                                                                                   print(tabulate(table, headers=["name","description"]))

This is of course super simplistic and does virtually no error checking, fancy formatting, etc. However now with a quick alias I can get a list of my repositories even when I do flake out and forget my token at home.

Terraform – Reference parent resources

Sometimes things get complicated in Terraform, like when I touch it and make a proper mess of the code. Here is a fairly straight forward example of how to reference parent resources in a child.

├── Child
│   └── main.tf
└── main.tf

1 directory, 2 files
$ pwd
/Users/dword4/Terraform

First lets look at what should be in the top level main.tf file, the substance of which is not super important other than to have a rough idea of what you want/need

provider "aws" {
  region = "us-east-2"
  profile = "lab-profile"
}

terraform {
  backend "s3" {}
}

# lets create an ECS cluster

resource "aws_ecs_cluster" "goats" {
  name = "goat-herd"
}

output "ecs_cluster_id" {
  value = aws_ecs_cluster.goats.id
}

What this does simply is create an ECS cluster with the name “goat-herd” in us-east-2 and then outputs ecs_cluster_id which contains the ID of the cluster. While we don’t necessarily need the value outputted visually to us, we need the output because it makes the data available to other modules including child objects. Now lets take a look at what should be in Child/main.tf

provider "aws" {
  region = "us-east-2"
  profile = "lab-profile"
}

terraform {
  backend "s3" {}
}
module "res" {
  source = "../../Terraform"
}
output "our_cluster_id" {
  value = "${module.res.ecs_cluster_id}"
}

What is going on in this file is that it creates a module called res and sources it from the parent directory where the other main.tf file resides. This allows us to reference the module and the outputs it houses, enabling us to access the ecs_cluster_id value and use it within other resources as necessary.

Managing a Growing Project

I am no Project Manager in even the loosest sense of the word. Despite that I find myself learning more and more of the processes of PM. This is especially true when projects start to expand and grow. Specifically I am speaking about the NHL API project I started almost two years ago. This lead me to the rabbit hole that is permissions and how to manage the project overall going forward. The projects roots are very rough, even today I still generally commit directly to master. Now the repository has grown to over 70 commits, two distinct files and 17 contributors.

Balance

I am constantly trying to be cognizant of is becoming overly possessive of the project. While it may have started as a one-man show I want and enjoy contributions from others. The converse of worrying about becoming possessive is that there are times when steering is necessary. One of the instances that comes to mind is the suggestion of including example code. The goal of the project is documentation, so I declined such suggestions. Unmaintained code becomes a hindrance over time and I don’t want to add that complexity to the project.

Growth

There is often a pressure to grow projects, to make them expand over time and change. Its a common thing for businesses to always want growth and it seems that mentality has spread to software. Something like the NHL API is a very slow changing thing, just looking at the commit history shows this. Weeks and months will go by without new contributions or even me looking at the API itself. I dabbled with ideas such as using Swagger to generate more appealing documentation. Every time I tried to add something new and unique I realized it felt forced. This ultimately forced me to accept that growth will not be happening, the project has likely reached its zenith.

Looking Forward

The next steps are likely small quality-of-life things such as the recent Gitter.im badge. Things that make it easier for people to interact but don’t change the project overall. My knowledge of the API makes for fast answers so I try to help out when I am able.

Home Gardening in the Apocalypse

So if you listen to the news and social media we are in a very slow collapse it seems, where things are never going back to normal but we totally shouldn’t panic just yet because they are going to devalue the living hell out of our currency with multiple massive multi-trillion-dollar stimulus packages. Well this got me thinking that if it were to go as bad as that nagging little voice says then perhaps its time to actively start sustaining myself with food. This leads me to a home garden in my super limited space at the townhouse. Between the fiance and I we love eggs so we had about 3 cartons laying around that we repurposed into vessels for starting our seeds.

Redundancy is key, 3 pods of each seed type and multiple seeds per pod

This is only a portion of what we plan to plant, basically a phase one with the seeds we were able to source locally, the larger shipment of seeds has been slowly winding its way to us from across the US and should be here within a day or so. The overall plan will includes a mix of common herbs such as Rosemary, Cilantro and Basil alongside edibles like Kale, Cucumbers and Tomatoes to help reduce our costs at the grocery store; less time spent at the store means less potential exposure and saves us money while increasing freshness to something not really possible in a grocery store.

The current layout of the seed starting tray

And an aside to the garden project is my long term fruit tree effort, last year the fiance and I bought a Key Lime tree and a Myers Lemon tree at the local garden store and put them out front of my townhouse. They flourished since it was the middle of summer with tons of light and regular rains, but as I moved them inside the Myers tree took a turn for the worse, losing a lot of its leafs when I moved. I tried more intensive watering in case the dry conditions of the house were evaporating more water than I realized. I rotated it a few times in hopes of the sunlight coming through the window pulling it back to a normal vertical position but that also failed to improve its conditions. Eventually I even resorted to a boost from some fertilizer steaks a few weeks ago but those failed to really change things. Finally I stumbled upon my plant light and timer that I had packed up when I moved so I relocated the tree so that I could point the light at it and set the timer up for about a 12 hour sun cycle and within a few days I was greeted with unmistakably fresh shoots in that vibrant green you cant mistake as well as possibly more fruit developing!

It is amazing what a little supplemental sunlight can do and I am hoping that the 12h cycle I have the seeds on ushers forth even more green in the house so that eventually we will have fresh herbs, veggies and fruits in a few months

Selecting an AWS subnet by name in Terraform

One of my recent challenges has been to write tf code to select existing subnets and use them in new blocks of code (specifically in this case to create a Directory, Workspaces and add a few Security Group entries). Since I am relatively new to using Terraform to do this it took far longer to figure out than I would care to say and I figured it would be best to document what finally worked and had the concept click for me in my mind.

provider "aws" {
  region = "us-east-1"
}
variable "subnet_name" {
  default = "workspaces-private-us-east-1c"
}
data "aws_subnet" "selected" {
  filter {
    name = "tag:Name"
    values = ["${var.subnet_name}"]
  }
}

output "vpcid" {
  value = "${data.aws_subnet.selected.vpc_id}"
}

output "subnet_name" {
  value = "${var.subnet_name}"
}
output "subnet_id" {
  value = "${data.aws_subnet.selected.id}"
}

This will look up the named subnet “workspaces-private-us-east-1c” and obtain not only the VPC ID associated with it but the unique subnet id as well, the output should look something like the below sample provided the name you are looking up is unique

data.aws_subnet.selected: Refreshing state...

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

subnet_id = subnet-0299e079c90b20ea6
subnet_name = workspaces-private-us-east-1c
vpcid = vpc-04066bef0a56ebcc2

This is of course specific to things as of Terraform 0.12.20 and provider.aws 2.48.0 so naturally things may change over time, however this will get you close and provide you enough of a starting point to use these subnets in other things.

Youtube Essential Ripping Platform

So I have been a longtime user of youtube-dl for ages to archive some things (obscure music, recordings of tech talks) and figured it was worth taking some time to make a simple and easy to use way to achieve this that others could benefit from. More simply put I created a front-end with Python and Flask to sit on top of youtube-dl and make the process so easy non-technical people could use it. Thus YERP was born (https://gitlab.com/dword4/yerp) to fill that role. I know there are tons of other competiting ideas out there doing the exact same thing but I wanted to take a crack at it for my own home network and get it so simplified that all you had to do was run a Dockerfile and it would spring into existence without configuration.

The project is VERY green right now and things are moving around and changing alot (even in my head before code is committed to the repository) so don’t bank on things staying how they are. There are tons of little features I want to put in like folder organization, backups, flags for filetypes and the like which will take quite a while to figure out how I would like to implement them. So if you do run the program just beware and if you find something that can be done better feel free to submit a PR and I will gladly bring other code into the project since I am only one person and not exactly a professional at this to begin with.

Apple 7th Gen iPad + Smart Cover Fix

Perhaps the most frustrating part of using the Apple Smart Cover with the 7th Gen iPad is that the keyboard just randomly stops working from time to time with no real rhyme or reason as to why. After lots of searching around and not getting anywhere I finally found a solution that works like a charm

  1. Physically disconnect cover from the iPad
  2. Reconnect the cover
  3. use Cmd + Tab to switch through a few apps
  4. resume typing because Apple hasn’t fixed this in the software yet

Considering I have seen articles from like 2 years ago where this was an issue it really feels like Apple should have fixed this by now but nope, an up to date 7th generation iPad in 2020 is still having this issue. Makes me wonder what that premium price tag for most Apple goods go to if not fixing/refining the products.

Winter Improvements for Hockey-Info

Finally got around to a rather large update for this project, fixed some small bugs such as the L10 data being way wrong (was showing win-loss-ot for the entire seaseon) as well as added in missing stats for Goalies and made the display of previous game results more sensible. Also redid about 95% of the interface to use Bootstrap4 which has made the look more uniform throughout. If you are interested in seeing the code itself you can see that here, or if you just want to check out the live site which I host as well then you can head over to http://hockey-info.online.

On the Road: Chicago

Not too shabby of a view

So I find myself on the road in Chicago as of Sunday, doing a round of technical interviews in my effort to take the next step in my career progression. Not a very long stay but the view from my hotel room at night was great, really captured the feel of the city at night I think. As much as I miss being at home and sleeping in my own bed I kind of wish I could have at least one more day if only to take a trip to a few landmarks and hit up a nearby fountain pen shop.

Still Moving

Slowly but surely I am getting my stuff set back up, the computer was the first part as I am currently searching for a job and need access to my resume files and my email in a manner other than my phone or tablet. Speaking of tablets I am really enjoying my 6th generation iPad that I got recently with the LTE option on it. After some talk with a buddy of mine (mikep) and getting blink-shell on the app store I gotta say its a fantastic ssh experience on iOS. I have been using it to decent success to work on a few side projects like my youtube-dl front-end.

It is pretty wild how much stuff accumulates over the course of 5 years and nothing quite puts it in focus like moving and having to drastically downsize. My office had 3 different desks, 3 computers and 6 monitors ranging in size from 23″ to 27″. To say the heat could get excessive in there was an understatement, I ran a box fan in the hallway to help circulate the air. In the move I have downsized to just a matched pair of 24″ screens and a single desk, hopefully this more focused environment will let me be more productive when it comes to projects and work.

On the topic of work it seems like the more moving I do the more I just want to lock myself away and code, I have ideas for tweaks to existing projects like the hockey-info website and new stuff like YeRP which needs a big push to get to a point where I am ready to release it to the internet for general use. I wonder what it is about absence of coding that makes me want to do it more?

Close Bitnami banner
Bitnami