March 5, 2015

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
"""
ph.py -- purge (git) history
2015 ckunte
"""
import os
def main():
fullpath = os.getcwd()
foldername = os.path.basename(os.path.normpath(fullpath))
repo = "git@github.com:ckunte/" + 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)
pass
if __name__ == '__main__':
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

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 `textinline.md`

that has inline style links into another file called `textref.md`

with reference links.

```
pandoc -f markdown -t markdown --reference-links --no-wrap textinline.md -o textref.md
```

### 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 inl2ref.sh and run the following at zsh
# prompt:
#
# $ zsh inl2ref.sh
#
autoload -U zmv
for file in *.mdown; do pandoc -f markdown -t markdown --reference-links --no-wrap "$file" -o "$file.md"; done
zmv '(*).mdown.md' '$1.md'
```

November 23, 2014

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:

- Square series conjecture: When any two square values in series are known, an entire series can be built.
- 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
| |
+--+
11
```

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
| |
+----+
6
```

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.