Blog 1

Random Talk on Random Thoughts

How Does Git Commit Amend Work?

| Comments |

Situation

I’ve written and commited the post My Git Command List (3), but after a while, I changed that post. In order not to complexify my Git commit history, I used git commit --amend -a. That’s quite simple and convenient. I observed that the displayed time in the amended commit was the same as the original one, whereas the SHA-1 hash was changed so that Git knows that they’re different. However, from Git Object ID Generation (1): Blobs and Commits, I’ve learnt that the ID of Git commit objects is totally determined by

  1. the content of the commit message
  2. the commit time
  3. the author

In this case, no difference of the above factors between the original commit and the amended commit can be observed with git show.

Problem

In what way do the original commit and the amended commit differ?

My Git Command List (3)

| Comments |

Overview

Unlike the Git commands found on the previous posts in this series, in this article, I’ll focus on low-level Git commands.

Raison d’être

Usually, one won’t use low-level Git commands in a Git repository, but I included them here because these commands help one understand the Git object model.

The list

$ find .git/objects       # Return all files/folders under `.git/objects'
$ git cat-file -p {hash}  # Print the content to which {hash} corresponds
$ git hash-object {file}  # Return the hash of {file}
$ git hash-object --stdin # Return the hash of the standard input
$ git write-tree          # Return the hash of the tree of tracked contents
$ git ls-files -s         # List all tracked files and their hash
$ git ls-tree {hash}      # List the contents of a tree
$ git rev-parse {hash}    # Return the full SHA-1 of {hash}
$ git rev-parse HEAD      # Return the full SHA-1 of HEAD
$ git diff                # Show the difference between the working directory and the index
$ git diff --cached       # Show the difference between HEAD and the index
$ git diff HEAD           # Show the difference between HEAD and the working directory

It isn’t necessary to supply the full SHA-1 hash for {hash}—several hex digits at the beginning will be enough.

Facts learnt

  1. An SHA-1 hash has 160 bits. Since 1 byte is equal 8 bit, it has 20 bytes. When it’s displayed, it has 40 hex-digits.
  2. The blob for a file is independent of the file name, which was actually stored in a tree object. For example, the object ID of a file which contains only a single line “hello world” is 3b18e512dba79e4c8300dd08aeb37f8e728b8dad, so if the file is stored inside the .git directory as a blob, the blob will be named as .git/objects/3b/18e512dba79e4c8300dd08aeb37f8e728b8dad.
  3. If a sub-directory is created in the dir directory, then a tree entry will be created in the tree object corresponding to dir.1

  1. See the code blocks and the picture in “Tree Objects” in Section 10.2 “Git Objects” of Pro Git a concrete example of a tree entry inside a tree object. 

A Quick Markdown Syntax Error Detection for Writing MathJax Equations in Octopress Posts (3)

| Comments |

Background

I often write math in this blog. After typing lots of characters, syntax errors are inevitable, but no one wants them to be published. Unluckily, the rake generate command takes too long to run. In order to find them out more quickly, I quickly went over the Gemfile of the repository for this blog, and saw that the Markdown engine of Octopress is kramdown. Therefore, I used the command line version of this Markdown parser to convert my Markdown source file to an HTML document by a Vim Ex command.

:!kramdown % > %<.html

For this, I’ve written two posts describing the workflow of producing HTML web pages consisting of math expressions from Markdown source files using kramdown and MathJax.

Problem

In the first post in this series, I’ve made a list of steps in Vim. However, jumping to other files is laborious. More importantly, those steps involve browsing and copying of lines of HTML code of the <head>, which loads MathJax, in other HTML files. This can seriously slow down the editing process. Unhappily, this problem isn’t solved in the second post in this series.

Some Thoughts on a Real-Valued Function

| Comments |

Problem

Spending so much time to work out the locale support for dates and valid HTML code in my second blog which was powered by Jekyll-Bootstrap, I couldn’t recall this fact.

Suppose that $\mathcal{D}$ is a subset of $\R^2$ that contains an $\varepsilon$-neighbourhood of a point $(x_0,y_0)$. If

  1. $f: \mathcal{D} \to \R$ is has first-order partial derivatives in the $\varepsilon$-neighbourhood of $(x_0,y_0)$.
  2. The first-order partial derivatives of $f$ are continuous at $(x_0,y_0)$.

Then we can write

\begin{equation} \Delta f = \frac{\partial f}{\partial x} (x_0,y_0) \Delta x + \frac{\partial f}{\partial y} (x_0,y_0) \Delta y + \varepsilon_1 \Delta x + \varepsilon_2 \Delta y, \label{fact} \end{equation}

where $\Delta f := f(x_0+\Delta x,y_0+\Delta y)-f(x_0,y_0), \varepsilon_1$ and $\varepsilon_2 \to 0$ as $\Delta x$ and $\Delta y \to 0$.

Basic Jekyll Date Locale Support

| Comments |

Problem

I tried installing _plugins/i18n_filter.rb and _locales/fr.yml from GitHub. I mistakenly thought that I had finished changing the English dates on Blog 2 to their corresponding French version due to the successful results shown in the local preview.

How can one get the locale support for dates on Jekyll sites?

Octoshape on Ubuntu 14.04

| Comments |

Background

I installed Octoshape player 2 years ago on Ubuntu 12.04. A year ago, I upgraded the OS to Ubuntu 14.04.

Problem

I tried running Octoshape streaming service on a sample test page tonight. Unluckily, it failed to work. On the test page, the output on the right-hand side was similar to the one listed below.

20:35:57.368: OctoProgressEvent: 0 - Connecting to Octoshape client
20:35:57.382: Player is waiting for a link input (this does not mean
that Octoshape is ready).
20:35:57.509: OctoProgressEvent: 83 - Connecting to Octoshape client
20:35:57.623: OctoProgressEvent: 166 - Connecting to Octoshape client
20:35:57.748: OctoProgressEvent: 249 - Connecting to Octoshape client
20:35:57.880: OctoProgressEvent: 332 - Connecting to Octoshape client
20:35:58.011: OctoProgressEvent: 415 - Connecting to Octoshape client
20:35:58.138: OctoProgressEvent: 498 - Connecting to Octoshape client
20:35:58.271: OctoProgressEvent: 581 - Connecting to Octoshape client
20:35:58.370: OctoProgressEvent: 664 - Connecting to Octoshape client
20:35:58.470: OctoProgressEvent: 747 - Connecting to Octoshape client
20:35:58.574: OctoProgressEvent: 830 - Connecting to Octoshape client
20:35:58.704: OctoProgressEvent: 913 - Connecting to Octoshape client
20:35:58.804: OctoProgressEvent: 996 - Connecting to Octoshape client
20:35:58.808: OctoProgressEvent: 1000 - Connecting to Octoshape client

Mik$\rm \TeX$ Update

| Comments |

Background

This morning, I tried typing the chemical symbol of carbon dioxide (CO2) in $\rm \LaTeX$, but I wouldn’t like to use \mathrm in math mode — first, I changed from text mode to math mode, then in order to type normal font, I used \mathrm to change it back to “text mode in math mode”. I did all of these for a little subscript only. Clearly, that’s not an elegant way of typesetting CO2. It didn’t took me long to find out that what I needed was the package mhchem.

Problem

I tried to \usepackage[version=3]{mhchem}, but Mik$\rm \TeX$ complained that the installed version of l3kernel was too old. As a result, I opened the package manager, and called the “Update Wizard” inside.

</source> update helper disappered?

How can I get the packages updated without manually creating another folder?

MS Word Hanged

| Comments |

Problem

I tried editing in M$ Word, but failed.

</source> M$ Word hanged

Solution

The solution is extremely simple: don’t use M$ Office if it’s too heavy for your computer — use something more lightweight: a text editor with a typesetting engine.

Choose your favourite editors

I use Vim every day as a text editor. I tried EMACS. Though I can’t remember two sets of keystrokes, the latter is still useful when you need to browse info pages on *nix.

Typesetting engines

  1. Markdown and pandoc

    For simple documents which have little variation in styles, such as blog entries and some homework essays.

  2. $\rm \LaTeX$

    For more complicated documents like lab report, documents containing math expressions, etc.

W3C Validator and SVGPan

| Comments |

Background

Similar to that of my recent post Added W3C Validated Logos to Some Pages—to get my SVG code validated by W3C.

I’m now using SVGPan for the zoom and drag functionality in SVG images generated from PDF files which are generated by xelatex from $\rm \LaTeX$ source code for TikZ pictures.1

Problem

I submited my SVG file to the W3C’s validator, which showed me one error. To illustrate this, I used an sample SVG in the official web site of SVGPan as an example.

</source> </source> SVGPan's SVG validation fails