Tuesday, March 3, 2015

git commands

To set up a new git repo with existing project:
cd .../project
edit .gitignore
git init
git add . -v
git commit

Add repo to bitbucket:
Create repository here: https://bitbucket.org/repo/create
git remote add origin https://user@bitbucket.org/user/project.git
git push -u origin --all
git push -u origin --tags

important concepts in git: the working tree (files on disk), the index (the staging area for the next commit), and HEAD (last commit you made)

to add new file to index OR to get a changed file to the index:
git add whatever.tex
(this does not commit the new file)
to add all changes and new files (but not rm anything) (-v for verbose):
git add -v .

to commit (will prompt for commit message):
git commit

push to github/bitbucket:
git push origin master
to push all branches/tags:
git push --all
git push --tags

diff between working copy and index:
git diff
diff between index and HEAD:
git diff --cached
diff between local (HEAD?) and github:
git diff origin/master master

status:
git status
abbreviated status:
git diff --name-status
git diff --cached --name-status

create new branch:
git checkout -b branch_name
list branches:
git branch
switch branches
git checkout branch_name

temporarily go back to older state:
git checkout [commit_hash]
...do some stuff...
(can make a new branch here with:
git checkout -b branch_name
)
to switch back:
git checkout master [or whatever original_branch was]


Make a new copy on different computer:
git clone https://github.com/user/project

simple git guide here: http://rogerdudler.github.io/git-guide/

if you get error like:
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/user/project.git/info/refs
run:
git remote set-url origin https://user@github.com/user/project.git
(see http://stackoverflow.com/questions/7438313/pushing-to-git-returning-error-code-403-fatal-http-request-failed )

Sunday, February 15, 2015

Make Zotero export to bibtex handle latex math

The default bibtex export module for Zotero is not great at handling math in titles. The only good solution I have found is to change the manually change the titles from using Unicode symbols (γp→ϕp) to using latex math ($\gamma p \to \phi p$). Then you need to modify the bibtex export module so that it will output your math verbatim without escaping it. Modify the file [Firefox profile]/zotero/translators/BibTeX.js. Change
var alwaysMap = {
  "|":"{\\textbar}",
  "<":"{\\textless}",
  ">":"{\\textgreater}",
  "~":"{\\textasciitilde}",
  "^":"{\\textasciicircum}",
  "\\":"{\\textbackslash}",
  "{" : "\\{",
  "}" : "\\}"
};
to
var alwaysMap = {
  "|":"{\\textbar}",
  "<":"{\\textless}",
  ">":"{\\textgreater}",
  "~":"{\\textasciitilde}"//,
  //"^":"{\\textasciicircum}",
  //"\\":"{\\textbackslash}",
  //"{" : "\\{",
  //"}" : "\\}"
};
and in the function writeField() change
    value = value.replace(/[|\<\>\~\^\\\{\}]/g, mapEscape).replace(/([\#\$\%\&\_])/g, "\\$1");
to
    value = value.replace(/[|\<\>\~]/g, mapEscape).replace(/([\#\%\&])/g, "\\$1");
    //extra protect all math against capitalization
    value = value.replace(/(\$.*?\$)/g,"{$1}");
The last line is needed to protect math from being auto-capitalized or auto-uncapitalized with two pairs of brackets. Without this line it's only surrounded by one pair of brackets, which is not always enough. Before fixing this, I had a problem where BibTeX kept changing \Lambda to \lambda, uncapitalizing my greek letters in inappropriate places.

References:
https://ohadsc.wordpress.com/2012/06/20/zotero-exporting-unicode-and-latex-constructs-to-bibtex/
https://forums.zotero.org/discussion/5324/bibtex-and-greek-characters/

Tuesday, November 6, 2012

reading binary files in ruby

Let's say you have a binary file filled with a bunch of doubles:
File.open("file_name","r") do |file|
  while !file.eof?
    puts file.read(8).unpack('D')[0]
  end
end

Thursday, March 29, 2012

create a local svn repository

adapted from here

copy project1/ to project1_cp/
remove hidden files, other crap from project1

in e.g. /home/XXX/svnrep:

svnadmin create project1
svn import /path/to/project1 file:///home/XXX/svnrep/project1/trunk -m "Initial import"
rm -rf /path/to/project1
svn co file:///home/XXX/svnrep/project1/trunk /path/to/project1

verify that project1 builds and works, then remove project1_cp

Tuesday, March 13, 2012

dry-run svn up

See if a svn up will lead to any conflicts:
svn merge --dry-run -r BASE:HEAD .

Alias this (csh):
alias svnupdry 'svn merge --dry-run -r BASE:HEAD .'

Monday, March 5, 2012

ignore whitespace in svn diff

svn diff -x -w
the -x indicates that the next option is an argument for the svn internal diff implementation

other options:
-u (--unified):
Output 3 lines of unified context.
-b (--ignore-space-change):
Ignore changes in the amount of white space.
-w (--ignore-all-space):
Ignore all white space.
--ignore-eol-style:
Ignore changes in EOL style.
-p (--show-c-function):
Show C function name in diff output.