torsdag den 21. januar 2016

søndag den 13. december 2015

JHead Rename images based on EXIF info

I just discovered JHead, a tool for manipulating JPEG images based on EXIT information. I don't know why I didn't find this tool before. This is extremely useful and convenient. I have tried a couple of tools on Windows and Mac but nothing is as convient at this one.

Install using homebrew:

brew install libjpeg
brew install jhead

libjpeg includes jpgtran, which is prerequisite for jhead but did not install as part of the jhead install.

I name my files using a date timestamp:

jhead -autorot -nf%Y-%m-%d-%Hh%Mm%S *.jpg

References:
http://www.phpied.com/installing-jpegtran-mac-unix-linux/
http://www.sentex.ca/~mwandel/jhead/
http://moinne.com/blog/ronald/bash/rename-your-photos-from-the-comandline-using-jhead

tirsdag den 8. december 2015

Release it

I am reading Release It by Nygard and these are some of the things to remember:


  • Use limits on queries. E.g. LIMIT 1 on Postgres or MySQL
  • Watch out for point-point connections
  • Set Socket.setSoTimeout() to protect against servers under heavy load
  • Use circuit breakers to degrade functionality gracefully under load
  • Return different errors for resource not available and application failures 
  • Fail fast, check availability of all required resources (ram, db, integration points, input)
  • Purge data (database, caches, logs)
  • Steady state
  • Bulkheads 
  • Cooperative demand control, handshaking between client and server to allow clients to back off. Problematic with http as the setup and teardown of connections is often the most expensive. Alternatively consider health checks either from client or from load balancer. Build handshaking into lowlevel protocols. 

SublimeText 2 Shortcuts

I am new to SublimeText 2 and so I need a little reminding of various shortcuts. Multiple cursors is one of the things I loved the most in Emacs. So I find this page very useful.

Simple overview of selection.

torsdag den 26. november 2015

Git Rebase Commands

The goal of this post is to make it easier for me to reference the individual steps of rebasing a Git repository.

I usually push the branch to origin as soon as I have made the first commit for backup purposes. Then I do an interactive rebase when the feature is complete to clean up the branch.

First update develop:


git checkout develop
git pull -u
git checkout feature/branch


Perform the interactive rebase:

git rebase -i develop


Push the feature branch to origin using force. Don't do this if somebody else is working on the same branch.

git push --force


If you don't want to do the rebase interactively, then just rebase:
git rebase develop


git rebase develop

If your current branch contain commits already merged into develop. Or is the continuation of a previous branch merged with develop after the current branch has been created. Then you must apply a little more magic.
Get the hash of the commit immediately before the commits you want to keep. The run the following command with #hash replaced by the hash of the commit.

git rebase --onto master #hash

The changes must be force-pushed.

See more here: https://www.atlassian.com/git/tutorials/merging-vs-rebasing/workflow-walkthrough.

mandag den 16. november 2015

How to list all databases with a given prefix in PostgeSQL

I recently had to delete a large number of databases in a PostgreSql database.

I found the code below very useful. It will list a sequence of SQL DROP DATABASE statements, one for each of the databases with a name starting with "database_name_starting_with_this".

The list of statements can be copied to psql a executed by pasting.

I want to warn you this can be dangerous, so go through the list of statements one by one, before you execute them.


SELECT 'DROP DATABASE "' || datname || '";' FROM pg_database
WHERE datname LIKE 'database_name_starting_with_this%';

fredag den 18. september 2015

How to remove deleted branch names from Git autocomplete


This is actually just a kind of short-cut to this SO. But if you want to skip the reading then here is the one-liner which does the cleaning for you.


git fetch --prune --all


Also to prune all local branches which have already been merged:

git branch -d $(git branch --merged)
git remote prune origin
git branch -d $(git branch | sed '$d')