About Adam Young

Once upon a time I was an Army Officer, but that was long ago. Now I work as a Software Engineer. I climb rocks, play saxophone, and spend way too much time in front of a computer.

Long Refactoring: Resetting the class model

With the inclusion of the Generators, the main functions seem to be in the right shape. What seems off is the naming of things. For example, we have a couple functions that take a parameter named “board” but it turns out they mean different things. The names of classes do not seem to align with what they are doing.

Lets continue with the renaming of things and see where it leads us.

But first: we can remove the exceptions to the flake8 testing, and, with the removal of some white space, we can run with all the pep8 rules intact. Now, on to renaming.

I am not going to go through each commit, but will try to provide enough context so you could follow the logic in the commits in github.

This is the last article in my Long Refactoring series. You can read the first article here.

Continue reading

Long Refactoring: Generators

While the main solving function is now cleaned up, I am not very happy with the code that checks the validation on each cell.

I am not going to go through each step here, as the pattern is well established now. Pull out of the function anything that is a distractor. Once you have the heart of the algorithm, clean it up. Then put things back together.

Continue reading

Getting a File from gitlab using a TOKEN

I work on a system in our lab that I connect to via SSH. Fetching a file via the web and pushing it to this machine is quite slow, and I want to pull on this machine directly. The trick to make this work is to use a TOKEN from gitlab and oauth2 as the username portion of the URL. For example

curl -O   https://oauth2:$CI_JOB_TOKEN@gitlab.com/api/v4/projects/$PROJECT_ID/packages/generic/$PROJECT_NAME/$PROJECT_VERSION/$FILE

The CI_JOB_TOKEN must be set to a token that has appropriate permissions on your project. Most of the values I wrote as envvars could be copy-pasted from the gitlab packages link on the web.

Adding stable to a blobless clone

We regularly sync various git repos from upstream to our company speicfic Linux repository. However, sometimes when working on a development machine, I need a branch from stable that we have not synced yet. If I did a blobless clone from our repository, doing a fetch from stable is going to pull over lots of blobs that I do not need.

Instead, I want to fetch just a specific tag. I can do this by adding the tag to the fetch command, and it will pull over only those blobs

Continue reading

Long Refactoring: Backtracking

Now that I have cleaned the loop up somewhat, we can continue with the process of refactoring the code. This is a continuation to the article series I started here.

This next step really moves beyond refactoring. I have identified that the intended backtracking was not actually implemented in the code. Instead, The whole board is wiped and restarted many times, causing a decent slowdown in execution. My refactoring process thus far has allowed me to understand the code well enough to attempt and improvement.

Continue reading

Long Refactoring: More loop cleanup

In my last article on the Long Refactoring series, I elided the process I went through to solve the bug. While preparing to turn the articles into a presentation, I went through the steps myself again, and came across the bug. When I was writing the articles, I was pressed for time, and didn’t go through the process of solving it step by step, which in turn means there is a gap between the pre-and-post states of the code: you can’t get there from here.
Let me take it from where I mentioned that I found a bug, and added the unit test that shows it.

Continue reading

FreeIPA: whoami via curl

Assuming PRINCIPAL is your Kerberos principal and $IPASERVER is the FQDN of your server, you can query your identity on the IPA server via curl:

kinit $PRINCIPAL
curl -k -H referer:https://$IPASERVER/ipa   -H "Content-Type:application/json"    -H "Accept:applicaton/json"   --negotiate -u :   --cacert /etc/ipa/ca.crt   -d  '{"method":"whoami","params":[[],{"version": "2.220"}],"id":0}'   -X POST    https://$IPASERVER/ipa/json
{"result": {"object": "user", "command": "user_show/1", "arguments": ["ayoung"]}, "version": "4.5.4", "error": null, "id": 0, "principal": "ayoung@YOUNGLOGIC.COM"}

This is handy if your system is not registered as an IPA client.

To fetch by username:

curl -k -H referer:https://$IPASERVER/ipa   -H "Content-Type:application/json"    -H "Accept:applicaton/json" --negotiate -u : --cacert /etc/ipa/ca.crt -d '{"method": "user_show", "params": [[ "ayoung" ], { "all": true, "rights": true }  ]}'  -X POST    https://$IPASERVER/ipa/json