Git: How to get a useful diff when renaming files

tldr; Use git diff -M or git diff --find-renames when you've moved a few files around.

Usage

$ git diff --help
  Options:
    -M[<n>], --find-renames[=<n>]
      Detect renames. If n is specified, it is a threshold on the similarity index
       (i.e. amount of addition/deletions compared to the file’s size). For example,
       -M90% means Git should consider a delete/add pair to be a rename if more than
       90% of the file hasn’t changed. Without a % sign, the number is to be read as
       a fraction, with a decimal point...

Preview Github-flavored Markdown from the bash with ianks/octodown

Preview what your markdown would look like on Github. Helpful e.g. when writing or extending a Readme for your gem or projects.

Installation

sudo apt-get install cmake libicu-dev # required for building native extensions
gem install octodown

Know that this will install at least 12 other gems. However, the beautiful output should be worth it.

Usage

octodown README.md

octodown markdown preview

greckout - a bash script to grep and checkout your git branches

greckout query

This will list all branches matching your query as input options for git checkout

  greckout ar
  
  1) ar/cache-api-keys-1098
  2) ar/add-categories-object-to-tv-show-1382
  3) ...

SVGO: SVG Optimizer

SVG files are often much larger than necessary, containing comments, metadata, hidden elements etc.

Optimize them with this tool.

Note that for a properly scaling SVG, you need to keep the viewBox attribute. There's an option --disable=removeViewBox for this.

Geordi 1.0 released

Geordi 1.0 features a command line application geordi, that holds most of Geordi's previous commands.

New features

  • command help and usage examples right within geordi (geordi help and geordi help <command>)

  • quick command access: type just the first few letters of a command, e.g. geordi rs or geordi dev[server]

  • command dependencies, e.g. geordi rspec invokes geordi bundle-install (which bundles only if needed)

  • no cluttered /usr/bin, but all commands in one handy tool

  • template for easily adding new...

Github: How to find the Readme for a certain version of a gem

When a gem author releases a new version to Rubygems, usually a tag with the version number (e.g. v1.2.0) is created an pushed to Github, so everyone can check out or take a look at the source code at this point version release at a later time.

If you'd like to take a look at the Readme of a specific Gem version, you can easily switch to that git tag on Github.

Github: Checkout Git Tag

Github: Search for a repo you've starred

Want to find that repo you've starred some time ago again? Here's where to search for it.

An alternative way to browse and search through your starred repos is Astral, where you'll see the Readme for each repo in a split screen.

How to view a file from another branch

Just run git show branch:file. Examples:

git show HEAD~:bin/command
git show origin/master:../lib/version.rb

mailru/FileAPI

A set of javascript tools for working with files.

It offers different kinds of things:

  • A cross-browser JS API to work with File objects.
  • Image helper methods, like rotating images, or generating thumbnails in the browser (because you don't want your browser to scale tons of 20MB-JPEGs just for an upload preview)
  • Webcam access
  • Uploads

When HTML5 support is unavailable, it uses Flash polyfills.

Check out the documentation and demos at their GitHub page.

To install via bower, simply add the `...

problem updating perl package(s) on freebsd `pkg-static: lstat(..../.packlist): No such file or directory

If you have trouble updating something on FreeBSD you should always take a look in the UPDATING file.

For this error there is this solution which worked perfectly for me:

20141127:
  AFFECTS: users of lang/perl5.*
  AUTHOR: mat@FreeBSD.org

  There was a nasty bug introduced in the update below, it was introduced in
  svn revision 373476 and corrected in 373485.  If you get errors looking like
  this one:

  ===>   Registering installation for p5-Params-Util-1.07_1 as automat...

How to fix: "git diff" does not show umlauts (or other non-ASCII characters) properly

When using git diff, you might encounter weird characters where umlauts (or any other UTF-8) characters should be. It looks like this:

R<C3><BC>ckg<C3><A4>ngig # should be "Rückgängig"

However, not Git is to blame but the less command that Git uses to page your diff output.

You need to tell less to use UTF-8 (otherwise it tries to convert multibyte chars like "ü" which is represented by 2 bytes C3 and BC).

$ LESSCHARSET=UT...

Install or update Chromedriver on Linux

Option 0: Download from the official page (preferred)

Chromedriver must be available in your path. You can add ~/bin to your path like this:

echo "export PATH=$PATH:$HOME/bin" >> $HOME/.bash_profile

If you're also using Geordi, disable automatic updating of chromedriver in ~/.config/geordi/global.yml:

a...

Draggabilly

Javascript library for drag'n'drop that seems to have more options than native HTML5 drag'n'drop.

They also claim to support "multi-touch", which would be awesome if it means that you can drag on touch devices.


Another library with similar aims is interact.js (Github).

They're pitching JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE8+).

Dealing with "TypeError: Converting circular structure to JSON" on JavaScript

JavaScript structures that include circular references can't be serialized with a"plain" JSON.stringify. Example:

a = { name: 'Groucho' };
b = { name: 'Harpo', sibling: a };
a.sibling = b;

Doing a JSON.stringify(a) will throw an error:

TypeError: Converting circular structure to JSON

There is not much you can do about that except specifying a custom serializer function that detects and cleans up circular references. There are existing solutions so you do not need to think of one yourself, like <https://githu...

Using rbenv on Ubuntu 18.04+

We will be installing rbenv and ruby-build from our own fork, not from the Ubuntu sources.

Installing rbenv

  1. Install rbenv:

    git clone https://github.com/rbenv/rbenv.git ~/.rbenv
    

    For Bash:

    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(rbenv init -)"' >> ~/.bashrc
    

    For ZSH:

    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
    echo 'eval "$(rbenv init -)"' >> ~/.zshrc
    

    Now reinitialize ...

Upgrade to LibreOffice 5.x on Ubuntu

Getting rid of your old LibreOffice

Remove your old LibreOffice:

sudo apt-get remove libreoffice*

You probably also want to get rid of the dead PPAs you might have installed for LibreOffice 4.x:

  • Open *Ubuntu Software Center
  • Go to Edit / Software Source ... / Other Software
  • Find and uncheck lines like http://ppa.launchpad.net/libreoffice/libreoffice-4-3/ubuntu. Note that you will probably have at least two lines pertaining to libreoffice.

Installing a new LibreOffice
-------------...

Git: Diff per word or character

By default git diff highlights whole lines as changes.

To diff on a word-by-word basis you can say:

git diff --color-words

To diff on a character-by-character basis you can say:

git diff --color-words=.

Feedjira

Great gem to consume RSS feeds. I was missing some features on Ruby's RSS::Parser that I found in Feedjira:

  • Speed
  • Does not break on slightly malformed RSS feeds (like a missing length attribute on an <enclosure> tag on gizmodo.de's feed)
  • It automatically resolves Feedburner-mangled URLs (hooray!)

The GitHub project has only a minimalistic readme. You can find its documentation on their homepage.

How to undo a 'git reset --hard'

So you erased a whole day's work? There is hope! The linked article tells how to recover from an accidental git reset --hard.

On a Mac

You will need to install GNU find utils as described in this SO post.

Git: Listing branches with their latest author

Run this command to list the authors of the most recent commit of each branch:

git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n

Credits go to DarVar on SO.

jpillora/xdomain · GitHub

Automagically makes XHR requests work cross-domain by tunneling all communications through an IFRAME on your page.

Note sure if it's a wise idea, but it's a thing now.

ruby-concurrency/atomic · GitHub

Provides a value container that guarantees atomic updates to this value in a multi-threaded Ruby program.

Originally linked to:
ruby-concurrency/atomic (Deprecated)

Things to consider when using Travis CI

Travis CI is a free continuous integration testing service. However, it is really fragile and will break more than it will work.

If you choose to use it anyway, learn the lessons we already learnt:

Use a compatible Rubygems for Rails 2.3 on Ruby 1.8.7

Ruby 1.8.7 is not compatible with current Rubygems versions (> 2.0). Runnig rvm rubygems latest-1.8 --force will fix this and install Rubygems version 1.8.29.

To make Travis CI do this, add `before_script: rvm rubygems latest-1....

rbenv: How to update list of available Ruby versions on Linux

When you tell rbenv to install a Ruby it does not know about, you will get an error message.

$ rbenv install 2.1.2
ruby-build: definition not found: 2.1.2

You can list all available versions with `rbenv install --list'.

If the version you're looking for is not present, first try upgrading
ruby-build. If it's still missing, open a request on the ruby-build
issue tracker: https://github.com/sstephenson/ruby-build/issues

(Fun fact: Recent versions of ruby-build will give you a more helpful error message which...