I found something very useful in the dingbats range of Unicode characters:
the negative circled san-serif digits, ➊ ➋ ➌ ➍ ➎ ➏ ➐ ➑ ➒ ➓ .
I've started using them to label points of interest in code.
They play well with the code-block directive in reStructuredText.
sudo docker images --format '{{.Repository}}:{{.Tag}}' \ ➊
| grep $IMAGE_NAME \ ➋
…continue.
I was trying to get some structured information from docker images,
hoping to replace some ugly Sed and AWK trickery.
I could have used the docker-py library.
Instead I chose to use the poorly documented --format option to docker images
(and some other Docker CLI commands).
Adrian Mouat gives some useful starting points at Docker Inspect Template Magic
and notes that formatting is built around Go templates.
I quickly figured out that this format would meet my immediate need.
sudo docker images --format '{{.Repository}}:{{.Tag}}' \
| grep $IMAGE_NAME \
| grep -v latest \
| head -1
That's fine, but …continue.
C-like languages have a ternary operator,
cond ? true_result : false_result.
Python has true_result if cond else false_result.
Bash doesn't have a ternary operator, but there are various workarounds.
I wanted to print succeeded or failed
based on the exit code of the previous command
in a shell script.
In Unix, all programs exit with an integer status code.
Successful programs exit with 0;
all other values, positive or negative, indicate failure.
In Bash, the status code of the previous program is held in $?.
some/command or-other fer example
STATUS="$([ "$?" == 0 ] && echo 'succeeded' || echo 'failed')"
echo "Results: $STATUS"
There are other ways to handle this.
Ever wonder what the six-digit file modes are in a Git commit?
The mysterious 100644 and 100755 modes?
diff --git a/foo/bar.py b/foo/bar.py
old mode 100644
new mode 100755
index b829edea4..ee6bda024
--- a/foo/bar.py
+++ b/foo/bar.py
@@ -1,3 +1,4 @@
...
I had made foo/bar.py executable by using chmod +x
and adding a #!/usr/bin/env python shebang.
The last three digits are obviously the same octal digits that you can use with chmod.
But what's that 100 prefix?
The explanation can be found in a StackOverflow answer:
100644₈ regular file (non-executable) S_IFREG | S_IRUSR | S_IWUSR
…continue.
I've been using Jenkins lately,
setting up Pipeline builds.
I have mixed feelings about that,
but I'm quite liking Groovy.
Here's an example of a Closure called acceptance_integration_tests,
where the release_level parameter is a String
which must be either "dev" or "prod".
def acceptance_integration_tests = { String release_level ->
assert release_level =~ /^(dev|prod)$/
String arg = "--${release_level}"
def branches = [
"${release_level}_acceptance_tests": {
run_tests("ci_acceptance_test", arg, '**/*nosetests.xml')
},
…continue.
I wanted to diff two files.
One of them needed some seds on each line and sorting.
I wanted to do that on the fly,
without leaving a massaged intermediate file lying around.
colordiff --unified <(cat orphaned_permalinks.txt
| sed 's@http://www.georgevreilly.com/@@'
| sed 's/.aspx$/.html/'
…continue.
LKRhash is a hashtable that scales to multiple processors and to millions of items.
LKRhash was invented at Microsoft in 1997
by Per-Åke (Paul) Larson of Microsoft Research
and Murali Krishnan and George Reilly of Internet Information Services.
LKRhash has been used in many Microsoft products.
The techniques that give LKRhash its performance
include linear hashing, cache-friendly data structures, and fine-grained locking.
If Microsoft had had 20% time,
LKRhash would have been my main 20% project.
I put a lot of …continue.
Ever had a Git repository where there's an overwhelming number of branches,
most of which are surely abandoned?
You run git branch --remote and you see dozens of unfamiliar branches.
Where to begin?
- Use git for-each-ref --sort to sort the branches
so that you can identify the oldest branches.
- Use git branch --remote --merged master
to detect which branches have already been merged into master.
It's likely that these are branches that weren't deleted
after a pull request was merged;
it's usually safe to delete these.
- --no-merged shows unmerged branches;
these require further investigation.
Here's an example for flyingcloud:
$ git for-each-ref --sort=-committerdate \
--format='%(committerdate:short) %(refname)' refs/heads refs/remotes
2016-12-29 refs/remotes/origin/master
2016-12-29 refs/remotes/origin/HEAD
2016-12-29 refs/heads/master
2016-12-11
…continue.
It's very useful when creating Markdown to be able to preview it live.
For example, creating a complex pull request or a README.md.
I usually use the built-in Atom Markdown Preview package in Atom.
Just type ⌃⇧M (aka Ctrl+Shift+M) to see a live preview in an adjacent pane.
I use vim-mode-plus to edit in Atom,
which provides an acceptable emulation of Vim.
I recently discovered VS Code Markdown Preview in Visual Studio Code.
Type ⌘K V (aka Ctrl+K V on Windows or Linux)
to invoke the side-by-side live preview.
I use VSCodeVim to meet my Vim needs.
Unfortunately, neither previewer gives identical results to GitHub's Markdown renderer.
GitHub itself seems to use different …continue.
We use Alembic to perform schema migrations
whenever we add (or drop) tables or columns
from our databases.
It's less well known that Alembic can also perform data migrations,
updating existing data in tables.
Here's an example adapted from a migration I put together this afternoon.
I added a non-NULL Boolean stooge column to the old_timers table,
with a default value of FALSE.
I wanted to update certain rows to have stooge=TRUE as part of the migration.
The following works with PostgreSQL.
Note the server_default=sa.false() in the declaration of the stooge column,
which is needed to initially set all instances of stooge=FALSE.
I then declare a table which has only the two …continue.
Previous »
« Next