I have read a nice article written by Yuanyian Zhou and James F. Philbin “Multi-queue replacement algorithm for second level buffer caches”. Authors compares well known implementations LRU, MRU, LFU etc and introduces new, more efficient method based on multiple queues, which performs better than other described implementations.
I highly recommend to read it.
Imagine you have commited file which name contain non latin letters.
git init test-repo
cd test-repo
echo "test" > тест.тэхэтэ
git add .
git commit -m "initial commit"
Ok, lets list files changed at revision
git log -p
Here you can see escaped file name, and obvious its hard to read.
diff --git "a/\321\202\320\265\321\201\321\202.\321\202\321\215\321\205\321\215\
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ "b/\321\202\320\265\321\201\321\202.\321\202\321\215\321\205\321\215\321\202
@@ -0,0 +1 @@
+test
To handle this case there is config options ‘core.quotepath’ The documentations (man git-config 1) says:
Sometimes (more precisely - rarely) you need to export files changed at given revision as directory tree instead of patch file.
Mercurial vcs has archive command which let you to export selected files at given revision:
hg archive --type files --rev $REVISION -I list_of_files
To list files changed at revision:
hg log -r $REVISION --template '{files}\n' | sed 's/\n / -I /g'
Here end of line character is used to handle the case of using space character in filename.
Church numerals is a great example of introducing abstraction in terms of composition of functions. This concept demonstrates that “data” (naturals numbers in particular) and operations on data can be defined in the same way - using higher-order functions.
Summary:
type Church a = (a -> a) -> a -> a
zero, cone, ctwo :: Church a
zero s z = z
one s z = s z
two s = s . s
three s = s . s . s
nth n s z = iterate s z !! n
add,mul,pow :: Church a -> Church a -> Church a
add x y = \s z -> x s (y s z)
-- a little bit easy to understand
mul1 x y = \s z -> x (y s) z
-- the same as
mul x y = x . y
pow x y = \s z -> y (x s) (x s z)
-- pretty print
c2i x = x (+1) 0 -- Church to int
c2s x = x ('*':) "" -- Church to String
Links:
Some time ago i read excellent post about emacs library pcomplete.
The author described implementation of completion for git, mercurial version control system using this library. Article is really usefull, i used code as is, its easy and provides all you need, but later i have some problem with it.
First problem - eager evaluation. General commands for git and mercurial are calculated once. Great, there is no reason to call external process like git or hg multiple times but precalculation occured at script evaluation. You may not want to start eshell, so call hg or git is not needed.
Foreword:
Sometimes you need to edit PATH variable.
Of course you edit .bash_profile, .bashrc, .profile or other scripts and this works fine only in terminal.
GUI apps at Mac Os use its own PATH variable (moreover has its own environment), which can be set using ’launchctl setenv PATH <PATH_VALUE>’.
So you need to setup PATH for GUI apps correctly, and do not forget about PATH var for terminal.
Moreover, after update to Mac Os X 10.10 Yosemite i was wondering about this:
There is some usefull git command rerere (reuse recorded resolution). Sometimes especially for long lived branch you need to resolve same conflicts again and again. This command let you save the results of conflict resolution and apply it again when needed.
Let see how its works:
# create test repo
git init rerere
# move to it
cd rerere
# enable rerere - reuse recorded resolution (its disabled by default)
git config rerere.enabled true
# add some file
echo "test" > readme.txt
git add .
git commit -m "initial"
# add some changes
echo "line1" >> readme.txt
git add .
git commit -m "1"
# save first revision hash (used only to avoid hardcoded hash sums)
initialRevision=`git log HEAD^1 --pretty=format:"%H"`
# create second branch based on initial revision
# (simulate one long lived branch)
git checkout -b first $initialRevision
echo "line2" >> readme.txt
git add .
git commit -m "2"
# create third branch based again on initial revision
# (simulate one more long lived branch)
git checkout -b second $initialRevision
echo "line2" >> readme.txt
git add .
git commit -m "2 again"
# move to master
git checkout master
# merge with first long lived branch
git merge first
# resolve conflict and preserve line1
echo -e "test\nline1" > readme.txt
git add .
git commit -m "first merge"
# now watch for output:
# 'Recorded resolution for 'readme.txt'.'
# git saves conflict resolution for readme.txt file
# now lets merge with second branch
# the same conflict has here
git merge second
# look at the output
# 'Resolved 'readme.txt' using previous resolution.'
cat readme.txt
# you can see the results of saved resolution without conflict markers
# means : "test\nline1"
This is pretty usefull for example, for package versions (pom files, project.clj), because such file fragments are strictly localized.
Sometimes you need to build .net solution/project on different platforms (for example while developing xamarin based application). In that case pre/post build events may contain platform specific instructions.
To handle this situation you can use ‘Condition’ attribute and ‘OS’ variable, for example, like this:
<PostBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">
<!-- windows specifics -->
copy $(TargetPath) $(ProjectDir)../Assemblies /Y
</PostBuildEvent>
<PostBuildEvent Condition=" '$(OS)' == 'Unix' ">
<!-- *nix, mac specifics -->
cp -f $(TargetPath) $(ProjectDir)../Assemblies
</PostBuildEvent>
If OS macro is undefined, you can explicitly define it at project level (projectName.cproj) like this:
Here are some usefull git aliases which i use on a daily basis:
Output samples are generated using clojure repository
List of one line commits
ls = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %C(bold blue)<%an>%Creset'

List of commits with changed files
ll = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %C(bold blue)<%an>%Creset' --decorate --numstat

List of commits without colors
lnc = log --pretty=format:"%h\\ %s\\ [%cn]"

Commits with dates
ldt = log --all --pretty=format:'%Cred%h%Creset %Cgreen%ad%Creset -%C(yellow)%d%Creset %s %C(bold blue)<%an>%Creset'

Some time ago i wrote gist which described how to install ghc from source on ubuntu. Today i see question on stackoverflow.com connected with my gist. I have fixed gist immediately and think about leaving comment to person who had some difficulties with it. I log on using google account and try to leave comment and … i cant do it because my repuration is too low (this is just new account). What ?!? This is service for questions and answers, why i have such strange limitation connected with main purpose of this resource. Completely disappointed.