March 5, 2015

Purging git history

Many of my repositories, including this site, contain binary files. This results in repos getting heavier over time, with version after version, every copy ever pushed is still around for me to dig back and recover from — the general light and magic of git. That said, most repos I store tend to be in forward motion, and rarely do I find the need to revert back to an old copy, especially after initial few days of adding something new.

Now, I do not know if this is the best way to manage old baggage, but once in a while, I find purging git history handy — after a particular repo has stabilized in fixes and updates, especially those with obsolete binary files. It makes for faster pulls, leaner on disk space, and it results in generally faster responses from server. To automate this, I wrote a generic script. Here it is.

#!/usr/bin/env python
# encoding: utf-8
""" -- purge (git) history
2015 ckunte

import os

def main():
    fullpath = os.getcwd()
    foldername = os.path.basename(os.path.normpath(fullpath))
    repo = "" + foldername + ".git"
    cmd1 = 'git reset --hard; rm -rf .git/; git init; git add .; git commit -m "first commit.";'
    cmd2 = 'git remote add origin ' + repo + '; git push --force origin master;'
    os.system(cmd1 + cmd2)

if __name__ == '__main__':

It needs to be run from the repo’s root. For example, if the repo is at ~/Projects/hcalc, then I run the script from within the hcalc folder.

Warning: I do not recommend any method of purging repos with valuable and well documented history, particularly open source projects that may have a following, and receive contributions from other project patrons, who may also be interested in project’s history. I use this for my own side projects that are either heavy on binary files, or have uninteresting commit messages.

January 31, 2015

From inline to reference style links

I began using Markdown in 2009, before which, I wrote everything in HTML. Despite switching, the habit of using inline links persisted, resulting in a folder full of draft posts that I now find harder to read and edit. Here’s where I find pandoc really helpful. This following example shows how to convert a file named that has inline style links into another file called with reference links.

pandoc -f markdown -t markdown --reference-links --no-wrap -o

Batch convert

To do this for a folder full of files with .mdown extension to .md, here’s a batch shell script:

#!/usr/bin/env zsh
# 2015 ckunte
# Save this script as and run the following at zsh
# prompt:
#  $ zsh
autoload -U zmv
for file in *.mdown; do pandoc -f markdown -t markdown --reference-links --no-wrap "$file" -o "$"; done
zmv '(*)' '$'

November 23, 2014

Square and cube series conjecture

My ten year old younger daughter has been discovering number series on her own. Today, she said to me that she has developed two conjectures:

  1. Square series conjecture: When any two square values in series are known, an entire series can be built.
  2. Cube series conjecture: When any three cube values in series are known, an entire series can be built.

Here’s how she explains them:

Square series conjecture

Let’s say we have two square values in series:

25, 36
 |  |

The difference between square series is always an even number: 2. For instance,

1,  4,  9,  16
|   |   |   | 
  3   5   7
  |   |   |
    2   2

So, you add 2 to the difference plus the last number to get the next in series.

25, 36,   49 (= 36 + 11 + 2)
 |  |     ^
 +--+     |
  11 + 2--+

Likewise, one can find the previous in the series as below:

25 - (11 - 2) = 16

Imagine a series of sequential square values as below:

\begin{aligned} …, a_{x-1}, a_{x}, a_{x+1}, a_{x+2}, … \end{aligned}

If you know any two in sequence, then you can build the series. Here’s how:

\begin{aligned} a_{x-1} = 2 \cdot a_{x} - a_{x+1} + 2 \newline a_{x+2} = 2 \cdot a_{x+1} - a_{x} + 2 \end{aligned}

This series is built one step at a time, of course, but it can be programmed to whatever iteration required to build the series.

Cube series conjecture

Let’s say we have three cube values in series:

27,   64, 125, 216, 
 |    |    |    |
   37   61   91   
    |    |    |
      24   30
      |    |

The difference between cube series is always an even number: 6. So, you come up with the next number as follows:

 64 - 61 + 30 - 6 = 27
216 + 91 + 30 + 6 = 343

Now Let us again imagine a series of sequential cube values as below:

\begin{aligned} …, b_{x-2}, b_{x-1}, b_{x}, b_{x+1}, b_{x+2}, … \end{aligned}

If you know any three in sequence, then you can build the series. Here’s how.

\begin{aligned} b_{x-2} = 3 \cdot (b_{x-1} - b_{x}) + b_{x+1} - 6 \newline b_{x+2} = 3 \cdot (b_{x+1} - b_{x}) + b_{x-1} + 6 \end{aligned}

Again like the square series, this series too is built one step at a time, of course, but it can be programmed to whatever iteration required to build the series.

She had to explain this whole thing to me twice before I could get my head around the concept and help formalize into equations, since she’s not yet into it herself.