@ wrote... (1 year ago)

I kept getting Incorrect string value warnings when trying to import UTF-8 strings into Mysql. It turns out that Mysql has pretty questionable utf-8 support as seen from this stackoverflow.com question.

Well enough was enough so I decided to migrate some datbases to Postgresql. Here are some notes/scripts that helped me.

more…

Category: tech, Tags: database
Comments: 0
@ wrote... (1 year ago)

Packages change pretty frequently when you're using Homebrew on OSX, including Python.

I noticed that I had several instances of lots of large packages installed (Boot, MacVim, Python, etc) so I ran brew cleanup and that freed up approx 9 gigs of disk! Unfortunately it also broke many virtual environments since the version of python that they were pointing at no longer existed.

What to do what to do…

Based on this Stack Overflow question I wrote a script to update a single virtual environment or all of them.

Note, this only updates virtual enviroments created with virtualenvwrapper. Also, you may have to reinstall your packages, but hopefully not.

#!/bin/bash

if [ -z "$1" ]; then
    echo "usage: $0 virtualenv|all"
    exit 1
fi

if [ -z "$WORKON_HOME" ]; then
    echo "you must export WORKON_HOME"
    exit 1
fi

if [ "$1" = "all" ]; then
    echo "udpating all virtualenvs"
    cd $WORKON_HOME

    for name in $(find . -type d -maxdepth 1 -mindepth 1|xargs -n1 basename); do
        $0 $name
    done

    exit 0
fi

cd $WORKON_HOME
virtenv="$WORKON_HOME/$1"

echo "deleteing $1"

rm -f  $virtenv/.Python
rm -f  $virtenv/bin/pip
rm -f  $virtenv/bin/pip2
rm -f  $virtenv/bin/pip2.7
rm -f  $virtenv/bin/python
rm -f  $virtenv/bin/python2
rm -f  $virtenv/bin/python2.7
rm -fr $virtenv/include
rm -f  $virtenv/lib/python2.7/* 2> /dev/null
rm -fr $virtenv/lib/python2.7/distutils
rm -f  $virtenv/lib/python2.7/site-packages/easy_install.*
rm -fr $virtenv/lib/python2.7/site-packages/pip
rm -fr $virtenv/lib/python2.7/site-packages/pip-*.dist-info
rm -fr $virtenv/lib/python2.7/site-packages/setuptools
rm -fr $virtenv/lib/python2.7/site-packages/setuptools-*.dist-info

source `which virtualenvwrapper.sh`

echo "creating $1"
mkvirtualenv -q $1
Category: tech, Tags: osx, python, virtualenv
Comments: 0
@ wrote... (1 year ago)

I seem to need to find files and sort them on modification time just often enough to never remember how but knowing that there's a good way to do it.

Here's the best way I've found so far, it handles spaces correctly and executes a command (ls in this case) on a per file basis. Change (or delete) -n1 to execute the command on multiple files simultaneously.

find . -type f -printf "%T@ %p\0" \ # list all files "seconds-since-epoch filename NULL"
  | sort -z -nr \                   # reverse sort based on seconds
  | cut -z -d' ' -f2- \             # only print filename
  | grep -zZ txt$ \                 # only keep txt$
  | xargs -0 -n1 ls                 # for each line, execute ls

or on one easy copy-paste line:

find . -type f -printf "%T@ %p\0" | sort -z -nr | cut -z -d' ' -f2- | grep -zZ txt$ | xargs -0 -n1 ls

The key here is \0 to output a null character at the end of each filename and then having each command in the pipe honour that null character (via -z|-Z|-0).

Category: tech, Tags: linux
Comments: 0
@ wrote... (1 year, 1 month ago)

There are dozens of similar programs on the the ol' internetz and here's mine.

I'm not a cryptographer.

more…

Category: tech, Tags: python
Comments: 0
@ wrote... (1 year, 1 month ago)

Now that's is so easy for me to create new containers and VMs with Proxmox, that's exactly what I've been doing. However, I like to be a good netizen and use https.

Here's my nginx config that lets me easily add a new LetsEncrypt certificate to a new vm/container for a new webapp.

more…

Category: tech, Tags: linux, nginx
Comments: 0
@ wrote... (1 year, 1 month ago)

When I was setting up Deluge to run headless on my linux server the deluge-web wasn't saving any settings and nothing was working. Turned out to be an easy fix if you know how.

The problem was the that the web-ui wasn't auto connecting to the deluged backend. This caused the connection manager to always pop up.

Anyhow, assuming your web-ui and deluged are running on the same machine edit the web.conf file and make sure that default_daemon is populated.

# /var/lib/deluge/config/web.conf -- your path will likely be different
...
"default_daemon": "localhost:58846",
...
Category: tech, Tags: linux
Comments: 0
@ wrote... (1 year, 2 months ago)

Just a quick note before I forget what little I understand. Something happened (or because I installed proxmox on top of an existing debian install, I honestly can't remember since it was like 4 weeks ago) during my install of proxmox. Long story short is that the nfs server doesn't work on reboot.

$ showmount -e
clnt_create: RPC: Program not registered

So then if you manually run rpc.mountd

$ rpc.mountd

$ showmount -e
Export list for proxmox-1
/tank/etc      192.168.1.0/24

But then you can't actually mount anything until you run rpc.nfsd

$ rpc.nfsd
$ mount proxmox-1:/tank/etc /tmp/etc
# totally works
$ ps auxw |grep rpc.nfsd
# no results

So I'm not sure what's going on. I do know that the half init.d half systemd scripts are somehow buggy.

The really crappy thing is that until I figure out the real solution I can't safely reboot my boxes.

Category: tech, Tags: proxmox
Comments: 0
@ wrote... (1 year, 2 months ago)

I've been making LXC containers in Proxmox like a fiend. I'm toally loving Proxmox, if you want several virtual machines I highly recommend it.

Anyhow, trying to run avahi-daemon in the containers often fails. I'm not the first to notice this but the answers were unsatisfying until I found a suggestion to try running with --no-rlimits. That seems to do the trick!

But how to get systemd to run it that way? Very simply as it turns out.

systemd

systemctl edit avahi-daemon.service

Add then in the text editor that opens up, enter the following:

[Service]
ExecStart=
ExecStart=/usr/sbin/avahi-daemon -s --no-rlimits

libnss-mdns

libnss-mdns sometimes doesn't install properly though. If you can't ping/lookup other .local hosts then edit /etc/nsswitch.conf and change…

hosts:          files dns

to

hosts:          files mdns4_minimal [NOTFOUND=return] dns

If anybody wants to write me an ansible script to do that I would totally buy you a beer. Too late, I had to write it myself, container.yml.

Category: tech, Tags: linux, lxc
Comments: 0
@ wrote... (1 year, 2 months ago)

At work we have a large project that is comprised of several nested git repos so having your bash prompt get updated with some vital information such as repo, branch, etc makes life much easier.

Here's an example of my prompt and how it shows the current git repo:

[kurt@machine-1 ~/src/foo/bar/baz venv:foo git:bug_branch repo:bar]
$

more…

Category: tech, Tags: shell
Comments: 0
@ wrote... (1 year, 5 months ago)

I've recently been wasting time on Empire of Code instead of doing productive and paying work.

Anyhow, the description of the Speed Boost puzzle Landing Holes was the most confusing thing I've ever read.

I'm pretty sure they're describing a Gatling gun. But then mentally s/pipe/barrel/ and s/canon/breach/ and then the description starts to make sense.

As for the function, the first list is a list of barrels, the second is a list of working breaches. The puzzle is asking you for a list of how many times you can rotate the barrels so they align with working breaches.

Category: tech, Tags: Empire-of-Code
Comments: 0