thoughts

Lies

I saw a man this morning burning a bible on the sidewalk. He had a blanket over his head and was screaming “LIES” into the street.

Commuters passed him by on their way to work like nothing interesting was going on. Just another day in San Francisco.

I wonder which translation it was.

Standard
thoughts

Killed the bird

I deleted Twitter the other day. I got tired of the bullshit.

I wanted to tell the world that I did this. But I have no idea how to do that now that I don’t have Twitter.

I’ll probably post brief thoughts here more often. Or better yet, I’ll keep them to myself.

Standard
books, writing

Bukowski On Writing

I finished reading a book by Charles Bukowski which was supposed to be about his thoughts on writing. What it turned out to be was a collection of stories, letters, and book forwards over the years that are tangentially related to writing.

I enjoyed the book overall but I think that only a Bukowski fan would really appreciate it.

My biggest takeaway from the book is that if I want to be more like Bukowski then I should listen to classical music and drink more wine.

Standard
debian

Docker Based Development Environment for Packaging

I started a new repo called sid-builder which provides a docker based development environment for debian packaging. This project follows all of the best practices that were outlined in the Guide for New Maintainers. The benefit of this approach is that you should be able to easily reproduce your development environment on any machine that supports docker. It also allows you to easily run sid without worrying about breaking your system.

I have not actually built any packages using this setup just yet, but I am going to give it a try over the next few days and report back here.

Standard
debian

Becoming a Debian Developer

I’ve been using debian for as long as I remember. I’ve always wanted to play a more active role in debian development but for whatever reason I never got around to it. Now that I am 30, older, wiser, I am starting a new push to become a debian developer.

So far I have gotten involved in the debian-qa team. Specifically I have been working on fixing some of the newcomer bugs on the distro-tracker project. It’s actually been really fun. The code base is django which I am pretty comfortable with. For the first time in many years, I have been rushing home after work so that I could keep hacking on the bugs that I am working on.

Code contributions are one thing. The thing that I am going to need more practice on is debian packaging itself. This is pretty complex process and I think that becoming someone who can debug and perform packaging issues would bring a lot of value to the project.

I am going to start working on some of the RC bugs (which typically involve at least re-packaging software) to get more comfortable with how other folks have been doing packaging.

In the next few months I would love to bring a new package through it’s full lifecycle.

I hope to be able to look back on this blog post in the future and see how far I have come.

Standard
programming

Dealing With Flakey CI Commands With a Retry Loop in Bash

One of the most frustrating things to deal with in Continuous Integration is flakey commands. Whether it’s flakey tests, or intermittent networking issues, when your build fails for issues outside of your control not only does it cause frustration, it reduces the trust in your CI process.

One strategy for dealing with this type of issue is to introduce some retry logic into your commands. This can easily be accomplished with good old bash.

For example, pretend that I have $FLAKEY_COMMAND and I want to retry it three times before finally failing my build. I could wrap the whole thing up in a bash loop like this.

counter=1
max=3
$FLAKEY_COMMAND

while [[ $? -ne 0 && $counter -lt $max ]]; do
    counter=$((counter+1))
    $FLAKEY_COMMAND
done

This script will run my command, if the exit code (the output of $?) is non zero (i.e something went wrong) and my counter is less than three, then it will retry the command. You can increase or decrease the number of attempts by adjusting the max variable.

This is not a foolproof strategy, but is one approach to handle flakey commands in your CI pipeline.

Standard
linux

Notes On Installing CentOS 7 Server

I’ve been on a fedora kick lately, and naturally for my server needs I am using CentOS 7. I have never really used CentOS in production and there are a couple of gotchas that I ran into while getting everything set up that I wanted to jot down for future reference and also in case its useful to someone else.

Install Some Useful Packages

The default install of CentOS is pretty bare bones. I installed several packages to make it a bit more usable.

sudo yum install wget unzip git htop vim epel-release

I tried to get away without installing epel[3], but it’s too darn useful.

Enable SSH Login

I have no idea how or why this works (I think it might have something to do with SELinux), but in order to be able to SSH into your server you need to set up your authorized keys file like this[1]:

mkdir .ssh
chmod 755 .ssh/

# copy your id_rsa.pub file to .ssh/authorized_keys 
# you can do this with a text editor, or if its on github
# download it with wget https://github.com/$USER.keys and 
# rename it to be the .ssh/authorized_keys file 

chmod 600 .ssh/authorized_keys
sudo restorecon -R -v .ssh

After that be sure to set PasswordAuthentication no in /etc/ssh/sshd_config and restart the sshd service for this to take effect. sudo systemctl restart sshd.service.

Install Docker

I used a convenience script from the main docker docs [2], I also added myself to the docker user group in order be able to run docker commands without root.

curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER

I am not using the root user to log in, I am using my own user.

If you want to use docker-compose, then (assuming you installed epel-release) you should install pip and docker-compose.

sudo yum install python34-pip
sudo pip3 install docker-compose

Allow outside connections

CentOS uses firewalld[4], it is a bit more complex than what I am used to with UFW, but certainly easier to use than iptables.

You can allow traffic on http and https with the following commands.

sudo firewall-cmd --zone=public --add-service=http
sudo firewall-cmd --zone=public --add-service=https

References
[1]Creating .ssh folder
[2]Install Docker on CentOS
[3]Extra Packages for Enterprise Linux
[4]DO firewalld guide

Standard
linux

Installing Sage Math on Fedora 28

Sage Math is a massive collection of open source mathematical tools. I am using it as a part of going through the Free Linear Algebra Book.

On a fresh install of Fedora 28, when you run dnf install sagemath you will install dozens of different packages. However, when you try to launch the sage math program you will get an error message saying that sage math crashed.

┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.0, Release Date: 2017-07-21                     │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘

**********************************************************************

Oops, Sage crashed. We do our best to make it stable, but...

A crash report was automatically generated with the following information:
  - A verbatim copy of the crash traceback.
  - A copy of your input history during this session.
  - Data on your current Sage configuration.

It was left in the file named:
    '/home/levlaz/.ipython/Sage_crash_report.txt'
If you can email this file to the developers, the information in it will help
them in understanding and correcting the problem.

You can mail it to: sage-support at sage-support@googlegroups.com
with the subject 'Sage Crash Report'.

If you want to do it now, the following command will work (under Unix):
mail -s 'Sage Crash Report' sage-support@googlegroups.com < /home/levlaz/.ipython/Sage_crash_report.txt

In your email, please also include information about:
- The operating system under which the crash happened: Linux, macOS, Windows,
  other, and which exact version (for example: Ubuntu 16.04.3, macOS 10.13.2,
  Windows 10 Pro), and whether it is 32-bit or 64-bit;
- How Sage was installed: using pip or conda, from GitHub, as part of
  a Docker container, or other, providing more detail if possible;
- How to reproduce the crash: what exact sequence of instructions can one
  input to get the same crash? Ideally, find a minimal yet complete sequence
  of instructions that yields the crash.

To ensure accurate tracking of this issue, please file a report about it at:
http://trac.sagemath.org

Hit <Enter> to quit (your terminal may close):

If you inspect the error file found in $HOME/.ipython/Sage_crash_report.txt you will see that there is a missing python dependency.

ImportError: No module named cypari2.gen

You can fix this error by installing the missing dependency with:

sudo dnf install python2-cypari2

Now you should be able to launch Sage Math without it crashing.

Standard
programming

Read All of Hacker News With the hanopener Extension

I’ve been reading Hacker News obsessively lately. In the past I would skip the top posts every couple of days, lately I have been reading every new and top article. In order to achieve this I would go to the main website, and click on every single link on the front pages.

After doing this for a few days I realized that I should probably write some Javascript to automate this entire process. So this afternoon I whipped up the hanopener chrome extension.

Initially I made it a python CLI script, but then realized that this would probably make more sense as a chrome extension.

Be warned: This extension is super obnoxious and will open up 60 chrome tabs every time you click on the icon, which is not always a good time depending on your computer.

It’s available on the chrome webstore and as a Firefox Add-On now.

UPDATE @ 5/28
Added link to Firefox Add On

Standard
programming

Deploying an Angular 6 Application to Netlify

Netlify is an excellent platform for building, deploying, and managing web applications. It supports automated deployment using GitHub webhooks and also provides some advanced features such as custom domains and HTTPS all for free. Deploying a Static Site to Netlify is a breeze. Although it does support running Angular JS applications, there are a couple gotchas in the deployment process that I had to wrangle together from various blog posts in order to get things to work.

Enable Redirects

The first issue that I ran into was after I deployed my site to Netlify, whenever I would click on an Angular link, I would get a 404 page.

Netlify Page Not Found

Looks like you’ve followed a broken link or entered a URL that doesn’t exist on this site.

Getting this to work is pretty simple. Ultimately you just need a file called _redirects in the root of your web project. In order to get angular to create this you need to do the following things. This file will send all URL’s to the root of your application which allows the Angular router to kick in and do its thing.

  1. Create a _redirects file in the src directory of your angular project.

    For most basic sites it should look something like this.

    # src/_redirects
    
    /*  /index.html 200
    
  2. Add this file to your angular.json file.

    Your angular.json file serves as a configuration for many different aspects of the angular CLI. In order to get this file into the root of your output directory you must define the file here. A snippet of my file is shown below. Update this configuration file and push all of your changes back up to GitHub.

    {
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "flagviz": {
        "root": "",
        "sourceRoot": "src",
        "projectType": "application",
        "prefix": "app",
        "schematics": {},
        "architect": {
            "build": {
            "builder": "@angular-devkit/build-angular:browser",
            "options": {
                "outputPath": "dist/flagviz",
                "index": "src/index.html",
                "main": "src/main.ts",
                "polyfills": "src/polyfills.ts",
                "tsConfig": "src/tsconfig.app.json",
                "assets": [
                "src/favicon.ico",
                "src/assets",
                "src/_redirects"
    
    ... rest of file 
    

Configure your Netlify Project

Now that you have the redirects file in place. You can set up your project for automatic deployment with GitHub and Netlify.

Once you have logged into Netlify, click on New Site From Git and find the name of your project.

New Site from GitHub

Configure Build Settings

The last step is to configure your build settings.

For Build command you should enter ng build --prod.

For Publish directory you should enter dist/$NAME_OF_YOUR_PROJECT.

Netlify Build Settings

Be sure to replace $NAME_OF_YOUR_PROJECT with the actual name of your project.

Now you can click on Deploy site and once the initial deployment has completed you should see your new angular application running on Netflify with a working routing system.

Standard