From 55400a94411452b10c0477cea072d3c9c719d7cd Mon Sep 17 00:00:00 2001 From: Ciro Duran Santillli Date: Sat, 13 Apr 2013 14:54:29 +0200 Subject: [PATCH] git info improved --- git => git/cheat.sh | 103 +- git/makefile | 43 + git/tutorial.md | 1619 ++++++++++++++++++++++++ gnuplot.gnuplot | 226 +++- linux | 634 ++++------ m4/cheat.m4 | 20 + m4/readme.md | 3 + makefile | 81 +- mysql.sql | 263 ++++ pandoc/cheat.md | 8 + pandoc/makefile | 8 +- pandoc/readme.md | 34 +- readme.md | 2 + rename | 0 docutils/cheat.rst => rst/docutils.rst | 13 +- rst/included.rst | 4 + {docutils => rst}/makefile | 14 +- {docutils => rst}/readme.md | 2 +- 18 files changed, 2530 insertions(+), 547 deletions(-) rename git => git/cheat.sh (83%) create mode 100755 git/makefile create mode 100644 git/tutorial.md create mode 100644 m4/cheat.m4 create mode 100644 m4/readme.md create mode 100644 mysql.sql mode change 100755 => 100644 rename rename docutils/cheat.rst => rst/docutils.rst (95%) create mode 100644 rst/included.rst rename {docutils => rst}/makefile (73%) rename {docutils => rst}/readme.md (84%) diff --git a/git b/git/cheat.sh similarity index 83% rename from git rename to git/cheat.sh index bb8a451..c7cfac7 100644 --- a/git +++ b/git/cheat.sh @@ -1,18 +1,5 @@ #!/usr/bin/env bash -##sources - - # - - #description of a production/dev/hotfix branch model: - # - - #update your cloned repo: - # - - #survey of git branching models: - # - ##config #first of all steps: tell git who you are @@ -30,12 +17,15 @@ git init - git remote add github "git@github.com:cirosantilli/python.git" - git remote add bitbucket "https://cirosantilli@bitbucket.org/cirosantilli/testrepo0.git" + ##bare - #allows to push and pull current repo git@github.com:cirosantilli/python.git repo. + #starts a bare repo here: - #this repo gets an alias github. see #1 push for details + git init --bare + + #it this contains directly the contents of the .git file. + + #a repo must be bare if you want to push to it/pull from it ##clone @@ -50,13 +40,19 @@ #see remote for what that means + ##bare + + #what github does on `fork`! + + git clone --bare $R + ##remote - #add remote sources to your git repo - #note that when you clone something, it alreay has a origin remote, - #so you usually only need this when doing the first push + #create aliases to a remote repo - #create a remote branch at github called github: + #when you clone something, it alreay has a origin remote. + + #create an alias to a remote repo: git remote add github https://github.com/cirosantilli/latex.git @@ -116,11 +112,27 @@ # or leave it blank and cancel comit. action is taken after you save ans quit :wq git commit -am 'commit message' + #same as above, but commits directly with message commit message + ##ammend + + #correct last commibt *before it was pushed*: + + #does not create new commitmessage + + #correct message only: + + git commit -m 'new commit message' + + #correct message and updates files: + + git commit -m 'new commit message' + ##push - #pushing is updating hte chages you made + #pushing is updating the chages you made + #it is better to add a remote R=git@github.com:cirosantilli/bash.git @@ -142,7 +154,9 @@ ##fetch #get changes from remote + #*does not change* current repo + #creates new remote/branch branches git remote add upstream git@github.com:cirosantilli/test.git @@ -150,6 +164,7 @@ git branch -r #origin/master + #upstream/master ##pull @@ -247,9 +262,9 @@ #all differences between current state and last commit #no need to have added the files - git checkout $hash #go back to given Hash and KEEP changes. new commits will start branches + git checkout $hash #go back to given Hash and KEEP changes. new commits will start branches git checkout master #go back to last commit and lose uncommited changes on all files - git checkout $hash #go back to hash (beginning of hash). lose uncommited + git checkout $hash #go back to hash (beginning of hash). lose uncommited git checkout $hash -- $file1 $file2 #revert only those files @@ -267,7 +282,7 @@ #if you are sure you are the only one, push --force will do -##branch and merge +##branch #branching is creating a separate path of developement @@ -295,22 +310,7 @@ git branch -d "$B" - #merge master with another branch : - - git checkout master - git merge "$B" - - #if auto merge is fine: - - #master goes to new node created after merge - - #else - - git status - - #shows what was unmerged - - #needs merge +##merge #files get modified to contain trash merge markers @@ -318,27 +318,6 @@ git mergetool -##remove file completelly from repo - - #for example: - #sensitive data - UNAME=cirosantilli - REPONAME=python - REPOURL=https://github.com/$UNAME/$REPONAME.git - RMFILE= - - git filter-branch --index-filter "git rm --cached --ignore-unmatch \"$RMFILE\"" --prune-empty -- --all - git push github master --force - - #remove from local dir - - rm -rf .git/refs/original/ - git reflog expire --expire=now --all - git gc --prune=now - git gc --aggressive --prune=now - - #MAIL ALL COLABORATORS AN TELL THEM TO git rebase - ##submodule #use outside repos inside you main repo, diff --git a/git/makefile b/git/makefile new file mode 100755 index 0000000..61afccc --- /dev/null +++ b/git/makefile @@ -0,0 +1,43 @@ +#compiles all .md files in current directory into pdf and html. + +#can mkdir and output that dir. + +override CCC ?= pandoc +override FLAGS ?= -s --toc --mathml -N #flags that apply to all kinds of output (html, pdf, etc) +override ID ?= +override IN_EXT ?= .md +override OUT_DIR ?= _out/ +override RUN_NOEXT ?= a #basename without extension of file to view (with firefox, okular, etc.) + +SRCS := $(wildcard *$(IN_EXT)) +OUTEXT := .html +OUT_HTML := $(patsubst %$(IN_EXT),$(OUT_DIR)%$(OUTEXT),$(SRCS)) + +OUTEXT := .pdf +OUT_PDF = $(patsubst %$(IN_EXT),$(OUT_DIR)%$(OUTEXT),$(SRCS)) + +.PHONY: all mkdir html pdf firefox okular clean + +all: html pdf + +mkdir: + mkdir -p $(OUT_DIR) + +html: mkdir $(OUT_HTML) + +pdf: mkdir $(OUT_PDF) + +firefox: + firefox "$(OUT_DIR)$(RUN_NOEXT).html$(ID)" + +okular: + nohup okular --unique "$(OUT_DIR)$(RUN_NOEXT).pdf" >/dev/null & + +$(OUT_DIR)%.html: %$(IN_EXT) + $(CCC) $(FLAGS) -o $@ $< + +$(OUT_DIR)%.pdf: %$(IN_EXT) + $(CCC) $(FLAGS) -o $@ $< + +clean: + rm -r "$(OUT_DIR)" diff --git a/git/tutorial.md b/git/tutorial.md new file mode 100644 index 0000000..d71467d --- /dev/null +++ b/git/tutorial.md @@ -0,0 +1,1619 @@ +# about + +git tutorial for absolute beginners. + +it is use case oriented. + +here i'm focusing on linux (ubuntu) + [git](http://git-scm.com/) + [github], +you can use any OS (Windows or OSX), and there are many alternatives to [github], +such as [bitbucket] or [gitorious] + +this workflow is basically valid for any [vcm] with a web interface. + +## souces + +- official book: . Good info and graphs. + +- good tut: + +- good tut, straight to the point, ascii diagrams: + +- description of a production/dev/hotfix branch model: + + +# motivation + +git + github allows you to do the following quickly: + +- [upload] your work to a serverupload to + + - backup your work + + - publish it + +- [download] something someone else made and put on a server + +- [go to another version] + + - in case you make a mistake, you can restore any file you want, even if it was deleted. + + - you can refer to a specific version. + + Why is this useful? + + Say you are writting a book, and you made a session called "motivation". + + Other people liked it, and said, look at the motivation section! + + But one day, you decide that the motivation section should be moved somewhere else. + + But then this breakes the references of other people! + + Not if the other person said: look at the "motivation" section of *version* XXX! + +- create alternate realities + + this is useful when: + + - you want to make two different modifications on a file + but you think they may interfere with one another. + + No problem, create one alternate reality version for each based on the current state. + + - you want to contribute two modifictaions to someoneelse's project. + + You are not sure which he will accept. So you make two alternate realities + and suggest them both. + +- view differences between versions + + it is easy to [view *differences* between versions](#differences) + to find out what was different on a different version + + this is useful when: + + - why was my program working then, but stopped working? + + - what changes exactly did someone else made to my files and wants me to accept? + +- work in groups + + Because of all its capacitie, git is widely used in group projects. + (it was *created* for the linux kernel ) + + This means that: + + - you can make a very large project that need many people to work on the same code. + + - you can learn from others. + + - if you make a good work, you will get more famous, and will have better jobs. + + For open source, this also means that: + + - you can make modifications that you need to the program you use. + +# how to learn git + +git is hard to learn at first because + +- it has inner state that is not obvious to visualise. +- concepts depend on one another + +to learn it, make a bunch of standard test repos, copy them out, test away. + +# setup + +before anything else install git. + +on on ubuntu: + + sudo aptitude insatll git + +next configure git: + + git config --global user.name "Ciro Duran Santilli" + git config --global user.email "ciro@mail.com" + +you will also want to install a local gui git viewer: + + sudo aptitude insatll gitk + +it makes it easy to see certain things + +# repository + +git works inside the dirs you tell it to work. + +those dirs are called *repositories*, *repo* for short. + +to create a new repo, use [init]. + +To copy an existin repo, use [clone]. No need to init it after you clone it. + +To transform a repo into a non repo, remove the `.git` dir (and maybe other files like `.gitignore`) + +# init + +go into some dir you have code you want to add to git and then do: + + git init + +this creates a `.git` dir that contains all the git information. + +## branches + +read this after you understand [branch] + +example: remote + + +---------------(E) + / | + (A) -- (B) -- (C) -- (D) | + | | + master feature + | + HEAD + +you repo after clone: + + +-------------- (E) + / | + (A) -- (B) -- (C) -- (D) | + | | + origin/master, master origin/feature + | + HEAD + +# create version + +most of git operations are based on versions, so you'd better know how to create them! + +to create a version you need: + +- decide what files will be included in the version with [add], [rm] or [reset] +- create the version with [commit] + +you can see what would be included in the next version with [status] + +# status + +allows you to see what would be included in the next version + + git status + +you can change what would be added with commmands like [add], [rm] or [reset] + +there are 3 possible sections: + +`Untracked files` + +: files which have never been added in any version. + +`Changes not staged for commit:` + +: files which have changed but will not be considered. + +`Changes to be committed: ` + +: files which which have changed and will be considered + +and if nothing changes, it says so. + +check out the [add], [rm] and [reset] commands to see how it behaves +(it is only cool once you start changing the repo) + +# add + +make git track files for next version + + add a + add a b + +check that it will be considered for next version with: + + git status + +## example: add + +requires that you understand [add], [rm] and [reset] to modify the repo. + +start with [0] + + status + #untracked: a b + git add a + status + #to be commited: new file: a + #untracked: b + git add b + #to be commited: new file: a b + git commit -m '1' + status + #no changes + echo a2 >> a + status + #not staged: modified: a + git add a + #to be committed: modified: a + +--- + +# reset + +unadd a file that would be added to net version + +if you regret adding a file to next version, and want to undo that to: + + git reset HEAD a + +the file stays the same on your disk, but it will not be considered for next commit anymore. + +# rm + +if you want to remove a file that is tracked from future versions then use: + + git rm a + +a simple `rm a` will not remove it from next version. + +If you already did `rm a`, then doing `git rm a` will work even if the file +does not exist. + +note however that this file still can be accessed on older versions! + +if you committed sensitive data like passwords like this by mistake, +you need to remove it from history too! + +to do that see [remove file from repo history]. + +## example: rm + +start with [1] + + rm a + git status + #not staged: removed a + echo b2 >> b + git add b + git commit -m 2 + +then `a` is still in the repo: + + git checkout a + +restores a. + +If you use `commit -a`, it gets removed anyway: + + rm a + git status + #not staged: removed a + echo b2 >> b + git add b + git commit -am 2 + +You could also `git add` or `git rm` after a bare `rm`: + + rm a + git add a + +or + + rm a + git rm a + +and a will be removed. + +--- + +# commit + +creates a new version. + +you must first which files will be included in it with commands like [add], [rm] and [reset] + +after you have decided what will be included or not, +you are ready to commit. + +you should give a short message for every version telling what is happening on it. + +this will be important later on to know what a version contains. + +so from the [0] do: + + git add a + git commit -m 'added a' + git status + +to give it a message 'added a'. + +now status only says that b is untracked and nothing about a. + +## correct last commit before upload + +to understand this section you need to know the basic of push. + +if you haven't yet uploaded this repo, you can correct the last message with: + + git commit --amend -m 'new msg' + +see with `log` how this does not create new version. + +can only use *before* push + +## commit all tracked files + + git add -am 'message' + +will create a new version, considering all files that are tracked. +( even if they were not added with add ) + +it is a very common default commit command. + +if you use this all the time, you only add files once. + +# remove file from repo history + +useful if + +- you mistakenly committed sinsitive data like a password +- some large output file like an .avi + + UNAME=cirosantilli + REPONAME=cpp + REPOURL=https://github.com/$UNAME/$REPONAME.git + RMFILE="*.ogv" + + git filter-branch --index-filter "git rm --cached --ignore-unmatch \"$RMFILE\"" --prune-empty -- --all + +remove from local dir + + rm -rf .git/refs/original/ + git reflog expire --expire=now --all + git gc --prune=now + git gc --aggressive --prune=now + +remove from repo: + + git push origin master --force + +MAIL ALL COLABORATORS AN TELL THEM TO git rebase + +# log + +list existing versions + +start with [2] and then: + + git log + +sample output: + + commit 1ba8fcebbff0eb6140740c8e1cdb4f9ab5fb73b6 + Author: Ciro Duran Santillli + Date: Fri Apr 12 10:22:30 2013 +0200 + + 2 + + commit 494b713f2bf320ffe034adc5515331803e22a8ae + Author: Ciro Duran Santillli + Date: Thu Apr 11 15:50:38 2013 +0200 + + 1 + +explanation: + +There are 2 versions, one with commmit message `1` and another with commmit message `2`. + +On version `1` we see that: + +- author name: `Ciro Duran Santilli` (specified in `git config`) + +- author email: ciro@mail.com (specified in `git config`) + +- commit hash: `494b713f2bf320ffe034adc5515331803e22a8ae`. + + If you don't know what a hash is, it is time to learn now! + + Put simply, a hash is an angorithm that takes lots of input bytes (the repo) + and outputs a short string (aka "the hash"), and so that it is very hard + to find two inputs that have the same hash (altough they obviously exist, + because the ouput string is much smaller! ) + +## find the version you want + +in a plain `log` command, the only information you have about what happenned in a version +is the commit message. + +you may need more information and better inofrmation filtering before deciding where you want to go back to. + +show only if grepping commit messages match: + + git log --grep 1 + +show all commits on all branches (by default only current branch is shown): + + git log --all + +# gitk + +gitk is a gui for git. + +it helps visualise commits and branches. + +show commits on all branches: + + gitk --all + +# how to refer to a version + +to actually go to another version, you have to be able to tell git which one is it, +so that git can go back to it. + +there are a few ways to do that. + +## hash + +the most complete is giving the entire hash, so: + + 1ba8fcebbff0eb6140740c8e1cdb4f9ab5fb73b6 + +would be version 2. + +It is very unlikelly that another version will have the same hash as this one. + +Now, if this is the only version that starts with `1ba8fc` or `1ba8`, (and it is) you could use those as well! + +## HEAD + +head is the current commit we are on. + +### definition: a head (lowercase) + +is a commit with a name other than the hash, +such as + +- a branch +- a remote head +- the HEAD. + +### example: HEAD + +start with [1]. we have: + + (1) + | + HEAD + +after another commit: + + (1)-----(2) + | + HEAD + +after another commit: + + (1)-----(2)-----(3) + | + HEAD + +## by branch + +to understand branches, see [branch] + +## by remote head name + +see [remote head] + +## relative to another version + +one commit before: + + HEAD~ + +two commits before: + + HEAD~~ + HEAD~2 + +three commits before: + + HEAD~~~ + HEAD~3 + +also work: + +- hash: `1ba8f~3` +- branch: `master~3` +- remote head: `origin/master~3` + +# diff + +TODO + +see differences between two versions with: + + git diff eebb22 06637b + +sample output: + + @@ 3,2 3,3 @@ + before + +error + after + +meaning: + +- before, line 3 was "before", line for "after". + + there were 2 lines total in what we see + +- after, "error" was added after "before", becoming line 4 + + there will be 3 lines total in what we see + + '+' indicates that a line was added. + + not surprisingly, if we remove something, a '-' will show instead + +# branch + +a branch is a name for a commit. + +the commit a branch referst to may change. + +using branches you may split up the commit tree + +this creates alternate realities so you can test changes without one affecting the other. + +the first commit of a repo is made on a branch called `master` + +## view existing branches + + git branch + +not the asterisk indicating which is the current branch. + +for more info: + + git branch -v + +also shows start of hash and commit message. + +one very important way is to do is graphically: + + gitk --all + +will show you who is descendant of who! + +## create a branch + +create a branch called b: + + git branch b + +check it was created: + + git branch + +but the asterisk shows we are still in branch `master`. + +this does not move to the branch just created! to do so you must use: + + git checkout b + +## create a and move to it + + git checkout -b b + git branch + +## what happens when you create a branch + +to the files, nothing. + +to the tree, suppose we are [1u] + +then after: + + git branch b + +it becomes: + + (1) + | + master * + b + +## what happens to a branch when you commit + +the *current* branch moves forward and continues being current. + +Ex: start at [1ub] now: + + git add c + git commit -am 'c' + +gives: + + (1)-----(c) + | + master * + +now try: + + git checkout b + +which gives: + + (1)-----(2) + | | + b * master + +c disappears because it was not tracked in b: + + ls + #a b + +echo c1 > c + + git add c + git commit -m 'cb' + +and now we have: + + +---------------(cb) + | | + (1)-----(2) b * + | + master + +which makes it obvious why a branch is called a branch + +## detached head + +is when you checkout to a commit that has no branch associated + +Ex: start with [2] + + git checkout HEAD^ + +now see: + + git branch + +shows current branch as: + + (no branch) * + +### what should I do if I want to branch from the detached head + +if you are on it, you should first create a branch: + + git branch b + +then work normally. + +You can also create a branch before going to it with: + + git branch + +### what happens if I commit on a detached head + +bad things! never do this! + +git does commit, but stays on a undefined state + +to correct it you can create a branch: + + git branch b + +and since you were on no branch, git automatically changes to `b`. + +#### what if I commit and checkout?? + +worse things. + +your old commit still exists, but does not show even on `git log --all` + +git warns you: this might be a good time to give it a branch, +and you should as: + + git branch b hash + +## start point + +you can also create a branch at any commit other than the current one: + +take [2] + + git branch b HEAD~ + +now + + git branch -v + +to create switch to it directly: + + git checkout -b b HEAD~ + +# checkout + +goes to another version + +before you go to another version, you must see which versions you can go back with [log] or [gitk]. + +## entire repo + +use the `checkout` command with some version name as explained in [how to refer to a version] for example: + + git checkout 494b + git checkout HEAD~ + git checkout master~ + +the command is called `checkout`, because we are goint to "check out" what another version was like. + +if you checkout the entire repo, `HEAD` moves! + +### example: checkout entire repo + +start with [3] + +it looks like this: + + (1)-----(2)-----(3) + | + master + HEAD + +now do: + + git checkout HEAD~~ + +the files `a` and `b` now both contain one line! + + cat a + #a1 + + cat b + #b1 + +The tree looks like this: + + (1)-----(2)-----(3) + | | + HEAD master + +Note how the `HEAD` moved, but `master` did not! + +Now do: + + git checkout master + +And `a` and `b` contain three lines again. This is how things look: + + (1)-----(2)-----(3) + | + master + HEAD + + cat a + #a1 + + cat b + #b1 + +--- + +files that are not tracked stay the same. + +### example: untracked files + +start with [2] + + echo -e 'c1\nc2' > c + +now checkout: + + git checkout HEAD~ + +`a` and `b` have changed + + cat a + #a1 + + cat b + #b1 + +but the untracked `c` stays the same: + + cat c + #c1 + #c2 + +--- + +### uncommited changes + +if you have not yet commited changes, git warns you and does not checkout. + +#### example: checkout uncommited modification + +start with [2] + + echo a3 >> a + +then try: + + git checkout HEAD~ + +git says that there is a change, and does nothing. + +--- + +#### example: checkout file overwite + +start with [2] + + git rm a + git commit -am '-a' + + git echo -e 'a1\na2' > a + +then try: + + git checkout HEAD~~ + +This fails again, because file a would be overwritten, even if its contents did not change. + +--- + + +## single file or dir + +just like checking out the dir, but you also specify the files: + + git checkout HEAD~ a b + +the head does not move now! this is different from the behaviour of checkout [entire repo] + +new files that appear are just like untracked ones. + +### example: checkout single file + +start from [2] + + git checkout HEAD^ a + + cat a + #a1 + +but we are still at master: + + git branch + #* master + +--- + +### example: checkout single removed file + +start from [2] + +remove b and commit: + + git rm b + git commit -am '-b' + +now restore it: + + git checkout HEAD~ b + + cat b + #b1 + #b2 + +--- + +### uncommited changes + +unlike when cheking out the entire repo, +git does not prompt you in case of non committed modifications +when checking out individual files! + +### example: checkout single file with modifications + +start from [2] + + echo a3 >> a + git checkout + + +--- + +# merge + +is when you take two branches and make a new one that is child of both. + +this is what you do when you like the modifications of two branches! + +ex: start with [2b] + + merge + +# push + +makes changes on a [bare] remote repo. + +the other repo can be on an external server like github. + +typical changes: + +- put branches there +- remove branches from there + +## usage + +pushes branch to remote bare repo: + + git push path/to/bare/repo branch + +if the branch does not exist it is created. + +## don't type the repo url + +### remote add + +one way to avoid typing the repo url is giving it an alias with `remote add`: + + git remote add origin git@github.com:userid/reponame.git + +origin can be any alias we want, but `origin` is a standard name for the main remote repo. + +and now you can do: + + git push origin master + +you can view existing aliases with: + + git remote -v + +which gives: + + origin git@github.com:cirosantilli/reponame.git (fetch) + origin git@github.com:cirosantilli/reponame.git (push) + +### -u + +another way is to use the -u flag: + + git push -u git@github.com:userid/reponame.git master + +now next time you can just do: + + git push + +and it will push to the last location. + +# remote head + +is a head that has a name + +itis not a branch however! + +if you checkout to them, you are in a detached head state. + +## how to get one + +see [clone] and [fetch] + +## how to see the ones I have + + git branch -a + +they are listed like remote// + +where remote-name was either given + +- explicitly by `remote add` +- `origin` by default by `clone` + +## how to refer to one + +depends on the command + +the best way is explicitly / but some +commands do explicit stuff if you enter just and +there is no other branch in your repo with that name. + +ex: `origin/master`, `origin/feature2`, `upstream/feature2`, etc. + +### branch + +branch only sees remotes if you give the `remote-name` explicitly. + +### checkout + +if you have a remote `origin/b` and no branch named `b`, + + git checkout b + +is the same as (magic!, never do this, it is very confuging!): + + git checkout b origin/b + +but: + + git checkout -b b + +is the same as: + + git branch b + git checkout b + +if you had a branch named `b`: + + git checkout b + +would simply go to it. + +# clone + +make a "copy" of another repo. + +fetchs all the remote branches. + +creates only a single branch: the branch were the `HEAD` of the remote was. + +## example: clone and branches + +start with [multi]. + + git clone a c + +creates a repo c that is a "copy" of a. now: + + cd c + branch -a + #master * + #remote/origin/b + #remote/origin/b2 + #remote/origin/master + +so you only have one branch, and the other are [remote head]s. + +but if you do: + + cd a + git checkout b + cd .. + git clone a d + cd d + git branch -a + #b * + #origin/b + #origin/b2 + #origin/master + +then you have a `b` branch, because that is where the head was when you cloned + +## from github + +it can also clone from a server such as github: + + git clone git@github.com:userid/reponame.git newname + +this is how you download a project which interests you. + +# fetch + +looks for all modifications made on all branches of a remote and make them available on repo +through [remote head]s + +does not modify any branch on current repo. + +the remote must have a name (either given automatically at `clone` as `origin` or through explicit `remote add`) + +## example + +you after a clone: + + git clone path/to/repo + + +--------------- (E) + | | + (A)----(B)----(C)----(D) | + | | + origin/master, master origin/feature + | + HEAD + +new state of the remote: + + +--------- (E)----(F)----(G) + | | + (A)----(B)----(C)----(D)----(H) | + | | + master feature + | + HEAD + +you after a fetch: + + git fetch origin + + +-------------(E)--------------(F)------(G) + / | | + (A)----(B)----(C)----(D)-----------------(H) | + | | | | + master feature origin/master origin/feature + | + HEAD + +--- + +## remove a pushed remote branch + +if you pushed a branch test by mistake, here is how you remove it: + + git push origin :branchname + +just add the colon before the branch name. + +# bare + +a repo that only contains the files that are inside `.git`. + +this is what github stores for you: no need to store the files also! + +there are some operations that you can only do/cannot do on a bare repo: + +- you can only push to a bare repo. + +- you cannot pull from a bare repo. + +to create a bare repo: + + git init --bare + git clone --bare other + +# pull + +pull is exactly the same as [fetch] + [merge] on given branch and merges with current branch. + +does not update remote heads like [fetch] does. + +## example: pull + +you after a clone: + + git clone path/to/repo + + +-------------- (E) + / | + (A) -- (B) -- (C) -- (D) | + | | + origin/master, master origin/feature + | + HEAD + +new state of the remote: + + +-------- (E) -- (F) -- (G) + / | + (A) -- (B) -- (C) -- (D) -- (H) | + | | + master feature + | + HEAD + +you after a `pull`: + + git pull origin master + + +-------- (E) ------------- (F) ----- (G) + / | | + (A) -- (B) -- (C) -- (D) ------------ (H) | + | | | + feature origin/master, origin/feature + master + | + HEAD + +so you current branch `master` has been merged into the branch `master` from repo `origin`. + +# push to github + +to upload you must have an account on some server and you must have created + +here we show how to upload to [github] + +## github setup + +create an account. your userid is: `userid` + +create a repository. call it `reponame` + +don't initilized it with a readme. + +the git url is then `git@github.com:userid/reponame.git` + +## do the upload + +upload the latest version to the server with: + + git push git@github.com:userid/reponame.git master + +this may ask for you github username and pass. + +go back to github and browse your uploaded files to check that they are there. + +# test repos + +use those to test stuff. + +## 0 + +2 files uncommitted: + + mkdir 0 + cd 0 + git init + echo 'a1' > a + echo 'b1' > b + cd .. + + git status + #untracked: a b + +## 1 + +2 files committed. + +create: + + cp -r 0 1 + cd 1 + git add * + git commit -m 1 + cd .. + +looks like: + + ls + #a b + cat a + #a1 + cat b + #b1 + + git status + #no changes + + 1 + + ^ + | + + master + + HEAD + +## 1u + +2 files committed and one uncommited + +create: + + cp -r 1 1u + cd 1u + echo 'c1' > c + cd .. + +looks like: + + ls + #a b c + cat a + #a1 + cat b + #b1 + cat c + #c1 + + git status + #untracked: c + + 1 + + ^ + | + + master + + HEAD + +## 1ub + +2 files committed and one uncommited + a branch called `b` + +current branch is `master`. + + cp -r 1u 1ub + cd 1ub + git branch b + cd .. + +looks like: + + ls + #a b c + cat a + #a1 + cat b + #b1 + cat c + #c1 + + git status + #untracked: c + + 1 + + ^ + | + + master * + + b + + HEAD + +## 2 + +2 commits 2 files commited + + cp -r ic 2 + cd 2 + echo 'a2' >> a + echo 'b2' >> b + git commit -m 2 + cd .. + +looks like: + + ls + #a b + cat a + #a1 + #a2 + cat b + #b1 + #b2 + + git status + #no changes + + 1 --> 2 + + ^ + | + + HEAD + + master + +## 2u + +2 commits 2 files commited, 1 file uncommited + + cp -r 2 2u + cd 2u + echo -e 'c1\nc2' >> c + cd .. + +looks like: + + ls + #a b + cat a + #a1 + #a2 + cat b + #b1 + #b2 + cat c + #c1 + #c2 + + git status + #untracked: c + + 1 --> 2 + + ^ + | + + HEAD + + master + +## 2b + +two branches unmerged, no uncommited files. + + cp -r 1u 2b + cd 2b + git add c + git commit -m 'master2' + git checkout b + echo a2 >> a + echo '' >> b + echo d1 > d + git add d + git commit -am 'b2' + git checkout master + cd .. + +tree: + + 1 --> master2 + + | ^ + v | + + b2 master * + + ^ HEAD + | + + b + +files: + + git checkout master + + ls + #a b c + cat a + #a1 + cat b + #b1 + cat c + #c1 + + git checkout b + + ls + #a b c + cat a + #a1 + #a2 + cat b + # + cat d + #d1 + +## 3 + +3 commits 2 files + + cp -r 2 3 + cd 3 + echo 'a3' >> a + echo 'b3' >> b + git commit -m 3 + cd .. + +looks like: + + ls + #a b + cat a + #a1 + #a2 + #a3 + cat b + #b1 + #b2 + #b3 + + git status + #no changes + + 1 --> 2 + + ^ ^ + | | + + master HEAD + +## ib + +bare + + mkdir ib + cd ib + git init --bare + cd .. + +## multi + +contains multiple repos for interepo tests + +it looks just like the github fork model! + + mkdir multi + cp -r 1 multi/a + cd multi + clone --bare a ao + clone --bare ao bo + clone bo b + cd a + git remote add origin ../ao + cd ../b + git remote add upstream ../ao + cd ../.. + + cd ao + git remote rm origin + git remote add origin ../a + cd ../bo + git remote rm origin + git remote add origin ../ao + cd ../b + git remote rm origin + git remote add origin ../bo + +the repo looks like this: + + ls + # a ao b bo + +where + +- ao is the origin of a +- ao is the origin of bo +- bo is the origin of b +- ao is the upstream of b + +meaning that a is the original repo + +ao is where the owner put it on github + +bo is the fork made by someone else + +b is the clone of the fork + + +# definitions + +some commonly git vocabulary + +## a commit + +is a version + +--- + +## to commit + +is to create version + +--- + +## to stage a file + +is to consider it for next commit + +--- + +## tracked file + +is one that has already been staged once + +--- + +[github]: https://github.com/ +[bitbucket]: https://www.bitbucket.org/ +[gitorious]: http://gitorious.org/ +[vcm]: http://en.wikipedia.org/wiki/Revision_control diff --git a/gnuplot.gnuplot b/gnuplot.gnuplot index ba8e6ef..7d650f3 100644 --- a/gnuplot.gnuplot +++ b/gnuplot.gnuplot @@ -1,17 +1,25 @@ #!/usr/bin/env gnuplot -##uses its own scripting language +#install: - #the awk of plotting: very domain specific language. + #sudo aptitude install gnuplot-x11 - #can get specific jobs done in seconds with amazing golfing. - - #but if you get slightly away from its intended usage - #it becomes insane or impossible to get the task done. +##review -#install: + ##uses its own scripting language - #sudo aptitude install gnuplot-x11 + #the awk of plotting: very domain specific language. + + #can get specific jobs done in seconds with amazing golfing. + + #but if you get slightly away from its intended usage + #it becomes insane or impossible to get the task done. + + ##limitations + + #- cannot draw primitives like points or lines + #- cannot draw vector flow plots from functions + #- no c api, only via pipes... ##command line @@ -37,16 +45,32 @@ ##data block - #each data block in a file is separated by a two newlines + #each data block in a file is separated by **two empty lines** + + ##non nummeric + + #is an error ##set #set plot parameters - set xrange [-1:1] - set yrange [-1:1] + #if not set, gnuplot is free to chooses a good value + + ##xrange ##yrange + + #view area: + + set xrange [-1:1] + set yrange [-1:1] - #if not set, gnuplot is free to choose a good value + ##key + + #legends + + #turn off: + + set key off ##unset @@ -54,17 +78,28 @@ ##Plot + #function: + p sin(x) p sin(x), cos(x) - p "a.dat", "b.dat" - #Using - - #select data columns + #set xrange: + + p [-5:5] sin(x) + + ##data file + + p "a.dat", "b.dat" + + #must be in format: x y\nx y\n ... + + ##Using - #only columns 2 and 3: + #select data columns + + #only columns 2 and 3: - p "a.dat" u 2:3 + p "a.dat" u 2:3 ##With @@ -87,53 +122,152 @@ p sin(x) lw 0.25 p sin(x) lw 25 -##stats + ##Line Color + + p sin(x) lc rgb "red" + p sin(x) lc rgb "blue" + +##SPlot + + #3d plot + + sp x+y + +##CLear + + #clear plot screen + + p sin(x) + cl + +##REPlot + + #adds to existing plot without clearing first: + + p sin(x) + rep cos(x) + rep cos(x+1) + + #must have a previous plot + +##STats #view and get data info #view: fp = 'a.dat' - stats fp + st fp #get number of rows *after doing a stats*: - print STATS_records + pr STATS_records -##pause +##pa - #pause one second: + #pa one second: - pause 1 + pa 1 - #pause gnuplot until any character is input by user: + #pa gnuplot until any character is input by user: - pause -1 + pa -1 ##minimal programming language a = 1 - print 1 + 1 - print 1 * 1 - print 1.0 / 2.0 - print "as"."df" - print a - print 1 < 2 - print 1 > 2 - print 1 != 1 - if( 1 ){ print "1" } - if( 0 ){ print "0" } - do for[i=1:5:2]{ print i } - do for[i=1:5:2]{ print i } - -##combos - - ##plot solution of a 2nd order ode as an animation + pr a + pr pi + + ##functions + + #define: + + f(x) = cos(x) + sin(x) + exp(-x**2) + abs(x) + + #use: + + pr f(1) + p f(x) + + ##piecewise + + step(x) = x>a ? 1 : 0 + p f(x)*(x<0.8) + g(x)*(x>=0.8) + #disadvantage: both parts are always evaluated + + pr 1 + 1 + pr 1 * 1 + pr 1.0 / 2.0 + + pr 1 < 2 + pr 1 > 2 + pr 1 != 1 + + pr "as"."df" + + if( 1 ){ pr "1" } + if( 0 ){ pr "0" } + + do for[i=1:5:2]{ pr i } + do for[i=1:5:2]{ pr i } + + ##not possible in 4.6: + + #- use command line arguments + #- define non mathematical functions (`f(){p sin(x); rep cos(x)}`) + +##save image + + p abs(x) + + #save the image + + set term gif + set output "out.gif" + rep + + #jpeg, png, svg, postscript also possile + + #return to normal plotting mode in linux: + + set output + set term x11 + + ##save gif video + + set key off + set term gif animate + set out "out.gif" + p sin(x) + n = 20 + for [i=1:n]{ rep sin(x+i*2*pi/n) } + + #now whatever you plot will go to a gif video file! + +##SAve session + + #save current session: + #- variables + #- functions + #- last plot/splot command + + sa ses.gnuplot + + ##LOad + + #load something saved with `save` + + lo ses.gnuplot + +##examples + + ##plot state space evolution of a 2nd order ode as an 2d animation #data is of form: x x' - set xrange [] - set yrange [] - fp = "" + fp = "ode.dat" stat fp - do for [i=1:STATS_records]{ p fp ev ::1::i; pause 0.1 } + set key off + p fp lw 0.5 lc rgb "red" + do for [i=1:STATS_records]{ rep fp ev ::i::i lw 5 lc rgb "blue"; pa 0.05 } diff --git a/linux b/linux index af7029d..7836b26 100644 --- a/linux +++ b/linux @@ -807,6 +807,9 @@ int main(int argc, char** argv) #: go to link under cursor #: go to next link #1-9: go to menu item nb. + #m: select menu item in current page by name. + #can tab complete. + #even without tab complete, goes to first match on enter. ##node @@ -814,8 +817,14 @@ int main(int argc, char** argv) #t: top node #[, ]: next previous node. May change node level. #n, p: not - #m: select menu item in current page by name. Can tab complete. - #g: all + #l: go to last viewed node. can be used several times. + #g: like m, but search all nodes + + ##search + + #/: regex + #{: next match of previous search + #}: previous info info rm @@ -1377,6 +1386,14 @@ int main(int argc, char** argv) sudo aptitude install -y exactimage + ##dvipng + + #convert dvi to png + + #important application: latex -> dvi -> png -> website. + + sudo aptitude install -y dvipng + ##book ##readers @@ -2072,6 +2089,17 @@ int main(int argc, char** argv) ##libs + ##itro + + #**TO USE A LIBRARY YOU NEED 2 THINGS**: + + #- the header .h file(s) + #- the compiled .so or .a file(s) + + #either those must be in you compiler find path + #(different for headers and compiled files) + #or you must explicitly add them to the path. + ##search path #where gcc search path for .a and .so @@ -2366,130 +2394,6 @@ int main(int argc, char** argv) file -L /lib/ld-linux.so.2 #ELF - ##recommended libs - - #this is just a quick list, installation and cheats will go better - #in other files/dirs - - ##performance note - - #to get the most out of applications, you have to - #compile it on your own computer so that the compiler will - #be able to make all the possible optimizations for your given - #architecture. - - ##c - - sudo aptitude install -y linux-source linux-headers - - ##check - - #c unit testing - - sudo aptitude install -y check - - ##ncurses - - #command line interactive interfaces - - sudo aptitude install -y ncurses - - ##expat - - #xml parsing - - ##to evaluate - - ##PCRE - - #perl regexes. c11 has regexes. - - ##popt - - #parse command line options - - ##c++ - - ##boost - - #cross platform utilities - - #very popular, largely influences c++ future - - ##glx - - #interface between opengl and x server - - #allows x windows to use opengl acceleration - - #must also support a given opengl version - - sudo aptitude install -y mesa-utils - - glxinfo | less - #lots of opengl info - glxgears - #demo - - ##scientific - - ##netlib - - #lots of good scientific libs from there - - ##blas lapack - - #langs: fortran (native), c - - #linear algebra. very widely standard.. - - ##acts collection - - # - - #collection of good numerical libraries. - - #industry usage. - - ##opengl glut - - #langs: c++(native), python - - #3d rendering - - #de facto open source standard. - - ##opencv - - #langs: c++(native), python - - #computer vision - - ##gsl - - - #langs: c, c++ - - #lots of domains - - ##freefem - - #2d and 3d fem - - #TODO - - ##r - - #statistics - - ##it++ - - #signal processing - - ##ode - - #rigid body physics engine - ##gdb #gnu symbolic debugger @@ -4302,270 +4206,6 @@ int main(void) #convert contents of F from BIG-FIVE to UTF-8 #no changes made: only outputs to stdout -##mysql - - ##souces - - #best way to get started: - # - - ##intro - - #mysql is a database that runs on a server. - - #this means that requests are made to the server, - #and the server returns responses. - - #to install the sever see <#mysql server>. - - ##mysql server - - sudo aptitude install -y mysql-server - #he will ask you for the password, fill it in - #mysql -u root #the tutorial said do that, but I didn't need to. This would be for the password. - - #configuration file: - less /etc/mysql/my.cnf - #contains info such as: listen port, ... - - ##interfaces - - ##mysql command - - #the `mysql` executable is a simple text based interface to mysql - - #it is bad to view tables that don't fit into the terminal width. - - #one advantage of this interface is the possibilty for automation - #using bash. - - ##phpmyadmin - - #popular php based broser interface for mysql - - #first make sure that php is installed. See <#php>. - - sudo aptitude install -y libapache2-mod-auth-mysql php5-mysql phpmyadmin - #gksudo gedit /etc/php5/apache2/php.ini - #according to tutorial, should uncomment ;extension=mysql.so, but I could not find it in the file. still works. - - sudo vim /etc/apache2/apache2.conf - #ensure following line is anywhere in the file: - #Include /etc/phpmyadmin/apache.conf - sudo service apache2 restart - - #test phpmyadmin and mysql: - firefox http://localhost/phpmyadmin & - #login: 'root'. password: what you entered at installation. - - ##users - - #mysql has the concept of user permissions. - - #each user/host pair has certain priviledges such as - #view, edit, delete databases, tables and entries. - - #those permissions may apply either to specific table/database - #or to the entire server (global permissions) - - #by default, a superuser called root is created during server installation. - - ##login - - #logs in as user root - #and prompts for password: - mysql -u root -p - - #execute command and exit: - mysql -u root -p -e "create database test;" - - #BAD: unsafe. Logs in without prompting password: - mysql -u root -p"pass" - #there must be no space between `-p` and `pass` - - #change password for an existing user: - mysqladmin -u root -p password - #prompts for old and new password - - #list users and their *global* priviledges: - select * from mysql.user; - #note how priviledges are given to user/host pairs. - - #create a new user: - CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; - #this user has no priviledges - - #show all global priviledges supported by a server: - SHOW PRIVILEGES; - - #view priviledges given for databases: - SHOW GRANTS; - #to current user: - SHOW GRANTS FOR user@host; - #to user: - - #give priviledges to an user: - #*.* implies global priviledges: - GRANT ALL ON * .* TO 'user'@'localhost'; - #all tables on a mydb: - GRANT ALL ON mydb.* TO 'user'@'localhost'; - GRANT SELECT, INSERT ON mydb.* TO 'user'@'localhost'; - #only for table mydb.mytbl: - GRANT ALL ON mydb.mytbl TO 'user'@'localhost'; - GRANT SELECT, INSERT ON mydb.mytbl TO 'user'@'localhost'; - # ^^^^ ^^^^^ - # 1 2 - FLUSH PRIVILEGES; - #1: on which databases - #2: on which tables of those databases - - #remove priviledges of an user: - REVOKE - - #remove users: - DROP USER user@localhost, user2@localhost - - ##commands - - ##databases - - #list databases: - show databases - - #create databases: - create database - create database elearn_trac character set utf8; - #utf8 charset. default is ascii. - - ##charset and collation - - ##charset - - #view all possible charsets: - show character set; - - #view charset for given db/table/column: - # - - ##collation - - #is how strings in a given charset are compared for equal, smaller, larger. - - #may be set for entire database, tables or individual columns - - #examples: case sensitive, case insensitive, Uppercase comes first (ABC...abc) - #same order: (AaBbCc...), etc. - - #view all possible collations for each charset - show collation; - - #use a database: - use db - #necessary before most table operations - - #list tables of a database: - show tables in db - show tables - #for current db - - #delete a database: - drop db - - ##tables - - #get table description: - DESC tbl; - - #get more info on table: - show create tbl - #shows each step used to create it - - #creates a new table: - - #creates a new table with same structure as old one: - CREATE TABLE newtable LIKE $oldtable - - #delete tables: - drop table table1, table2; - - #copies data from old table to new table - INSERT INTO $newtable SELECT * FROM $oldtable - - #removes all entries from a table - TRUNCATE TABLE $tablename - #faster than - - #deletes entire table data. difference from truncate? - DELETE FROM $table; - - ##select - - #choose certain entries to do actions on them - - #chose a column: - select column from table - - #chose many columns - select column1, column2 from table - - #unique entries: - select distinct column from table - #only shows each value of column once - - #chose all column: - select * from table - - ##locks - - #synchronization method - - LOCK TABLES `$table1` READ; `$table2` WRITE; - #cannot read from table1 and write to table2 - #use before making big db changes - - UNLOCK TABLES - #releases all locks - - ##column types - #length - #there are length limitation on *row* size (sum of all columns) - #2**16-1 = 8k-1 - #this means 8k-1/256 = 85 CHAR(256) fields are permitted - #TEXT field not stored on the table: each occupies up to 12 bytes on their row - - ##dump (save to file) - - mysqldump -u root "$DB_NAME" > bak.sql - mysqldump -u root "$DB_NAME" "$TABLE1" "$TABLE2" > bak.sql - #dump to file - #no USE - #drops existing - - mysqldump -u root --databases "$DB1" "$DB2" > bak.sql - #mutiple dbs - #creates dbs with old names, uses them - - mysqldump -u root --all-databases > bak.sql - #all dbs - #with USE, old names - - # -d : no data - # --no-create-info : data only - - ###restore - - PASS= - mysql-u root -p"$PASS" < bak.sql - #make sure the db exists/you want to overwrite it - - DB= - DB2= - PASS= - mysql -u root -p"$PASS" -e "create database $DB2;" - mysqldump -u root -p"$PASS" $DB | mysql -u root -p"$PASS" $DB2 - #make sure the db exists/you want to overwrite it - #copy db to new name - ##cron #you can't launch graphical applications! @@ -5643,6 +5283,7 @@ int main(void) ##files ##ls + #POSIX #list files in dirs @@ -5710,7 +5351,38 @@ int main(void) #config <#ls> colors + ##gnu extensions + + #-R: recursive + + ls -R + + ##tree + + #prints visual file tree + + #install: + + sudo aptitude install tre + + #recurse 2 levels (default infinite): + + tree -L 2 + + #-a: include hidden: + + tree -a + + ##--charset + + #select a smaller charset for output: + + tree --charset=ascii + + #this is good if you want to paste output! + ##cd + #POSIX cd dir #go to dir @@ -5739,12 +5411,14 @@ int main(void) #~/a ##touch + #POSIX touch f #creates file if does not exist. #updates modify date to present if exists ##mkdir + #POSIX #make a dir @@ -5758,6 +5432,7 @@ int main(void) #-m: mode (permissions) ##mv + #POSIX #move or rename files @@ -5801,6 +5476,7 @@ int main(void) assert [ `ls | wc -l` = 2 ] ##cp + #POSIX #copy @@ -5922,6 +5598,7 @@ int main(void) #TODO understand this! ##chown + #POSIX #change owner and group of files @@ -5956,6 +5633,8 @@ int main(void) sudo chown :newgroup ##chmod + + #POSIX #change file permissions @@ -6056,6 +5735,8 @@ int main(void) ##stat + #POSIX + #cli for sys_stat #get file/dir info such as: @@ -6163,13 +5844,20 @@ int main(void) #compares F and G byte by byte, until first difference #if equal, print nothing #else, print location of first difference + + ##-s + + #silent + + #return status 0 if equal + #!= 0 otherwise - cmp -s "$F" "$G" - if [ $? -eq 1 ]; then - echo neq - else - echo eq - fi + cmp -s "$F" "$G" + if [ $? -eq 1 ]; then + echo neq + else + echo eq + fi ##find @@ -8694,14 +8382,20 @@ print "" ##java - sudo add-apt-repository -y ppa:webupd8team/java - sudo aptitude update - sudo aptitude install -y oracle-java7-installer - sudo aptitude install -y oracle-java7-set-default - #set env variables - sudo aptitude install -y icedtea6-plugin + #its sometimes hard to make this work... + + #not sure which is best + + #sudo add-apt-repository -y ppa:webupd8team/java + #sudo aptitude update + #sudo aptitude install -y oracle-java7-installer + #sudo aptitude install -y oracle-java7-set-default + ##set env variables + #sudo aptitude install -y icedtea6-plugin #allows to run java on certain brosers, including firefox + sudo aptitude install openjdk-7-jre icedtea-7-plugin + ##perl #perl is good for command line golfing and quite powerful @@ -9249,6 +8943,142 @@ add Lock = Caps_Lock ./NVIDIA*.run --extract-only vim NVIDIA*/README +##libs + + #this is just a quick list, installation and cheats may go better + #in other files/dirs since libs are usually large to understand + + ##performance note + + #to get the most out of applications, you have to + #compile it on your own computer so that the compiler will + #be able to make all the possible optimizations for your given + #architecture. + + ##c + + sudo aptitude install -y linux-source linux-headers + + ##check + + #c unit testing + + sudo aptitude install -y check + + ##ncurses + + #command line interactive interfaces + + sudo aptitude install -y ncurses + + ##expat + + #xml parsing + + ##to evaluate + + ##PCRE + + #perl regexes. c11 has regexes. + + ##popt + + #parse command line options + + ##c++ + + ##boost + + #cross platform utilities + + #very popular, largely influences c++ future + + ##glx + + #interface between opengl and x server + + #allows x windows to use opengl acceleration + + #must also support a given opengl version + + sudo aptitude install -y mesa-utils + + glxinfo | less + #lots of opengl info + glxgears + #demo + +##scientific + + ##netlib + + #lots of good scientific libs from there + + ##blas lapack + #fortran: native + #clang: bindings + + #linear algebra. very widely standard. + + ##acts collection + + # + + #collection of good numerical libraries. + + #- asdf + #- qwer + + #industry usage. + + ##opengl glut + #native: c++ + #bindings: python + + #adsf + + #3d rendering + + #de facto open source standard. + + ##opencv + + #langs: c++(native), python + + #computer vision + + ##gsl + #c + #c++ + + #tons of scientific functions + + ##freefem + + #2d and 3d fem + + #TODO + + ##r + + #statistics + + ##it++ + + #signal processing + + ##ode + + #rigid body physics engine + + ##plplot + #c + #cross platform + + #graph plotting + + #quite good at first sight + ##misc ##shutdown reboot diff --git a/m4/cheat.m4 b/m4/cheat.m4 new file mode 100644 index 0000000..ba200dd --- /dev/null +++ b/m4/cheat.m4 @@ -0,0 +1,20 @@ +#define + +define(a, va) +0 a 1 +0a1 +0a 1 +,a 1 +0 a1 +0 a, +0 a 1 define(a, va2)0 a 1 + +#comments + +`a' a +`define(a, va)' +#uninterpreted line: a +dnl not output line +not dnl output to file +not dnloutput to file +notdnl output to file diff --git a/m4/readme.md b/m4/readme.md new file mode 100644 index 0000000..8f75952 --- /dev/null +++ b/m4/readme.md @@ -0,0 +1,3 @@ +macro engine + +absolutelly insane escaping! =) diff --git a/makefile b/makefile index 158d1b3..927da22 100644 --- a/makefile +++ b/makefile @@ -4,9 +4,11 @@ ##motivation - #takes care of dependencies + #- takes care of dependencies - #only builds if requirements were changed! (looks at timestamps) + #- only builds if requirements were changed! (looks at timestamps) + + #this may be important when compilation time starts getting significative ##basics @@ -77,6 +79,31 @@ install: @mv out $(DIRINPATH) +##.SECONDARY + + #an **intermediate** file is a file that is neither target nor prerequisite. + + #example: + + #a.m4 -> a.c -> a.o + + #with a single rule: + + a.o: a.m4 + m4 a.m4 > a.c + gcc -o a.o a.c + + #here a.c is intermediate. + + #make deletes intermediate files by default because: + + #- they are not desired outputs (those must be targets) + #- if one of the base prerequisites is modified, this will be remade anyways + + #if you want to keep them you can use the secondary target: + + .SECONDARY: a.c b.c + ##variables CC=gcc @@ -244,13 +271,20 @@ ##builtin functions - #wildcard. makes an array with wildcard. - SRCS = $(wildcard *$(INEXT)) + ##wildcard - #pathsub. makes an array with wildcard. - OUTS = $(patsubst %$(INEXT),%$(OUTEXT),$(SRCS)) + #makes an array with wildcard. + + SRCS = $(wildcard *$(INEXT)) + + ##patsubst + + #makes an array with wildcard. + + OUTS = $(patsubst %$(INEXT),%$(OUTEXT),$(SRCS)) #compile all files of a type + INEXT=.c OUTEXT= SRCS = $(wildcard *$(INEXT)) @@ -258,6 +292,16 @@ all: $(OUTS) %: %$(INEXT) $(CC) $(CFLAGS) -o $@$(OUTEXT) $< + + ##foreach + + #do a loop and concatenate results + + #select all files with one of the given extensions in current directory + + IN_DIR := ./ + IN_EXTS := .lex .y .c .cpp + INS := $(foreach IN_EXT, $(IN_EXTS), $(wildcard $(IN_DIR)*$(IN_EXT)) ) $(subst from,to,text) Replace from with to in text. $(patsubst pattern,replacement,text) Replace words matching pattern with replacement in text. @@ -321,6 +365,31 @@ all: pwd ;\ ) +##implicit builtins + +#make has some built-in rules and variables + +#PAY ATTENTION OR THIS WILL F*** YOU UP LATER, +#SINCE THEY MAY OVERRIDE YOUR OWN RULES AND VARIABLES WITHOUT WARNING!!!!!!!!!!!!! + +#in this way, for example, c.c -> c.o happens automatically + +#suffixes for which there are implicit rules (may override your own rules!): + + #.out, .a, .ln, .o, .c, .cc, .C, .cpp, .p, .f, .F, .m, .r, .y, .l, .ym, .lm, .s, .S, .mod, .sym, .def, .h, .info, .dvi, .tex, .texinfo, .texi, .txinfo, .w, .ch .web, .sh, .elc, .el + +#predefined vars ( ?= won't work for them! ): + + #AR AS CC CPP FC M2C PC CO GET LEX YACC LINT MAKEINFO TEX TEXI2DVI WEAVE CWEAVE TANGLE CTANGLE RM ARFLAGS ASFLAGS CFLAGS CXXFLAGS COFLAGS CPPFLAGS FFLAGS GFLAGS LDFLAGS LFLAGS YFLAGS PFLAGS RFLAGS LINTFLAGS + +#those vars are mainly used to control the automatic rules. + +#to turn off the implicit rules: add a phony empty rule: + +.SUFFIXES: + +#as you may guess, this specifies for which suffixes automatic rules will work or not. + ##recipes ##make all files of an extension inside given path diff --git a/mysql.sql b/mysql.sql new file mode 100644 index 0000000..02f0d25 --- /dev/null +++ b/mysql.sql @@ -0,0 +1,263 @@ +##souces + + #best way to get started: + # + +##intro + + #mysql is a database that runs on a server. + + #this means that requests are made to the server, + #and the server returns responses. + + #to install the sever see <#mysql server>. + +##mysql server + + sudo aptitude install -y mysql-server + + #he will ask you for the password, fill it in + #mysql -u root #the tutorial said do that, but I didn't need to. This would be for the password. + + #configuration file: + less /etc/mysql/my.cnf + #contains info such as: listen port, ... + +##interfaces + + ##mysql command + + #the `mysql` executable is a simple text based interface to mysql + + #it is bad to view tables that don't fit into the terminal width. + + #one advantage of this interface is the possibilty for automation + #using bash. + + ##phpmyadmin + + #popular php based broser interface for mysql + + #first make sure that php is installed. See <#php>. + + sudo aptitude install -y libapache2-mod-auth-mysql php5-mysql phpmyadmin + #gksudo gedit /etc/php5/apache2/php.ini + #according to tutorial, should uncomment ;extension=mysql.so, but I could not find it in the file. still works. + + sudo vim /etc/apache2/apache2.conf + #ensure following line is anywhere in the file: + #Include /etc/phpmyadmin/apache.conf + sudo service apache2 restart + + #test phpmyadmin and mysql: + firefox http://localhost/phpmyadmin & + #login: 'root'. password: what you entered at installation. + +##users + + #mysql has the concept of user permissions. + + #each user/host pair has certain priviledges such as + #view, edit, delete databases, tables and entries. + + #those permissions may apply either to specific table/database + #or to the entire server (global permissions) + + #by default, a superuser called root is created during server installation. + + ##login + + #logs in as user root + #and prompts for password: + mysql -u root -p + + #execute command and exit: + mysql -u root -p -e "create database test;" + + #BAD: unsafe. Logs in without prompting password: + mysql -u root -p"pass" + #there must be no space between `-p` and `pass` + + #change password for an existing user: + mysqladmin -u root -p password + #prompts for old and new password + + #list users and their *global* priviledges: + select * from mysql.user; + #note how priviledges are given to user/host pairs. + + #create a new user: + CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; + #this user has no priviledges + + #show all global priviledges supported by a server: + SHOW PRIVILEGES; + + #view priviledges given for databases: + SHOW GRANTS; + #to current user: + SHOW GRANTS FOR user@host; + #to user: + + #give priviledges to an user: + #*.* implies global priviledges: + GRANT ALL ON * .* TO 'user'@'localhost'; + #all tables on a mydb: + GRANT ALL ON mydb.* TO 'user'@'localhost'; + GRANT SELECT, INSERT ON mydb.* TO 'user'@'localhost'; + #only for table mydb.mytbl: + GRANT ALL ON mydb.mytbl TO 'user'@'localhost'; + GRANT SELECT, INSERT ON mydb.mytbl TO 'user'@'localhost'; + # ^^^^ ^^^^^ + # 1 2 + FLUSH PRIVILEGES; + #1: on which databases + #2: on which tables of those databases + + #remove priviledges of an user: + REVOKE + + #remove users: + DROP USER user@localhost, user2@localhost + +##commands + + ##databases + + #list databases: + show databases + + #create databases: + create database + create database elearn_trac character set utf8; + #utf8 charset. default is ascii. + + ##charset and collation + + ##charset + + #view all possible charsets: + show character set; + + #view charset for given db/table/column: + # + + ##collation + + #is how strings in a given charset are compared for equal, smaller, larger. + + #may be set for entire database, tables or individual columns + + #examples: case sensitive, case insensitive, Uppercase comes first (ABC...abc) + #same order: (AaBbCc...), etc. + + #view all possible collations for each charset + show collation; + + #use a database: + use db + #necessary before most table operations + + #list tables of a database: + show tables in db + show tables + #for current db + + #delete a database: + drop db + + ##tables + + #get table description: + desc tbl; + + #get more info on table: + show create tbl + #shows each step used to create it + + #creates a new table: + + #creates a new table with same structure as old one: + CREATE TABLE newtable LIKE $oldtable + + #delete tables: + drop table table1, table2; + + #copies data from old table to new table + INSERT INTO $newtable SELECT * FROM $oldtable + + #removes all entries from a table + TRUNCATE TABLE $tablename + #faster than + + #deletes entire table data. difference from truncate? + DELETE FROM $table; + + ##select + + #choose certain entries to do actions on them + + #chose a column: + select column from table + + #chose many columns + select column1, column2 from table + + #unique entries: + select distinct column from table + #only shows each value of column once + + #chose all column: + select * from table + + ##locks + + #synchronization method + + LOCK TABLES `$table1` READ; `$table2` WRITE; + #cannot read from table1 and write to table2 + #use before making big db changes + + UNLOCK TABLES + #releases all locks + +##column types + + #length + #there are length limitation on *row* size (sum of all columns) + #2**16-1 = 8k-1 + #this means 8k-1/256 = 85 CHAR(256) fields are permitted + #TEXT field not stored on the table: each occupies up to 12 bytes on their row + +##dump (save to file) + + mysqldump -u root "$DB_NAME" > bak.sql + mysqldump -u root "$DB_NAME" "$TABLE1" "$TABLE2" > bak.sql + #dump to file + #no USE + #drops existing + + mysqldump -u root --databases "$DB1" "$DB2" > bak.sql + #mutiple dbs + #creates dbs with old names, uses them + + mysqldump -u root --all-databases > bak.sql + #all dbs + #with USE, old names + + # -d : no data + # --no-create-info : data only + +###restore + + PASS= + mysql-u root -p"$PASS" < bak.sql + #make sure the db exists/you want to overwrite it + + DB= + DB2= + PASS= + mysql -u root -p"$PASS" -e "create database $DB2;" + mysqldump -u root -p"$PASS" $DB | mysql -u root -p"$PASS" $DB2 + #make sure the db exists/you want to overwrite it + #copy db to new name diff --git a/pandoc/cheat.md b/pandoc/cheat.md index 19153b8..b20c642 100644 --- a/pandoc/cheat.md +++ b/pandoc/cheat.md @@ -212,3 +212,11 @@ only works for html output, not for pdf, so never use it unless you really need ## inner content is md parsed:

**par**

+ +##comments + +there is no real good way AFAIK + +a good possibility is: + + diff --git a/pandoc/makefile b/pandoc/makefile index 06864c7..dd816cc 100755 --- a/pandoc/makefile +++ b/pandoc/makefile @@ -2,8 +2,8 @@ #can mkdir and output that dir. -override CCC ?= pandoc -override FLAGS ?= -s --toc --mathml #flags that apply to all kinds of output (html, pdf, etc) +override CC := pandoc +override FLAGS ?= -s --toc --mathml -N #flags that apply to all output formats: (html, pdf, etc) override ID ?= override IN_EXT ?= .md override OUT_DIR ?= _out/ @@ -34,10 +34,10 @@ okular: nohup okular --unique "$(OUT_DIR)$(RUN_NOEXT).pdf" >/dev/null & $(OUT_DIR)%.html: %$(IN_EXT) - $(CCC) $(FLAGS) -o $@ $< + $(CC) $(FLAGS) -o $@ $< $(OUT_DIR)%.pdf: %$(IN_EXT) - $(CCC) $(FLAGS) -o $@ $< + $(CC) $(FLAGS) -o $@ $< clean: rm -r "$(OUT_DIR)" diff --git a/pandoc/readme.md b/pandoc/readme.md index e0de8a1..1044406 100644 --- a/pandoc/readme.md +++ b/pandoc/readme.md @@ -1,32 +1,32 @@ -##pandoc +#pandoc -#input formats: extended markdown, subset of latex -#output formats: html, pdf +input formats: extended markdown, subset of latex +output formats: html, pdf - sudo aptitude install -y pandoc + sudo aptitude install -y pandoc -#description of markdown flavour: +description of markdown flavour: - man pandoc_markdown + man pandoc_markdown -##output type is recognized by extension +#output type is recognized by extension - #generate html from markdown: +generate html from markdown: pandoc a.md -o a.html - #generate pdf from markdown: +generate pdf from markdown: pandoc a.md -o a.pdf -##options +#options pandoc -s --toc -c pandoc.css -A footer.html README -o example3.html - #-s : output is standalone. in output html for example, - #includes ```` and ```` tags - #--toc : creates a toc of links to headers, - #and headers are links to toc and have ids - #-A : include after - #-c : link to css - #-w rst : set input format to rst +- -s : output is standalone. in output html for example, +- includes ```` and ```` tags +- --toc : creates a toc of links to headers, +- and headers are links to toc and have ids +- -A : include after +- -c : link to css +- -w rst : set input format to rst diff --git a/readme.md b/readme.md index 7b2e04f..7b09db4 100644 --- a/readme.md +++ b/readme.md @@ -8,6 +8,8 @@ take tools in a very wide sense that include: - programming languages +- libraries + those tools are kept in this repo because: - they don' deserve a repo of their own because I don't have enough info written on them. diff --git a/rename b/rename old mode 100755 new mode 100644 diff --git a/docutils/cheat.rst b/rst/docutils.rst similarity index 95% rename from docutils/cheat.rst rename to rst/docutils.rst index 83550a1..539d0e4 100644 --- a/docutils/cheat.rst +++ b/rst/docutils.rst @@ -6,7 +6,7 @@ document title must be completely underlined and upperlined with = :depth: 5 .. sectnum:: - :depth: + :depth: 5 h1 ======= @@ -251,15 +251,24 @@ unicode: |copy| |BogusMegaCorp (TM)| |---| datetime: |date| |time| +include +####### + +.. include:: included.rst + raw ### -is only used for respective output: +is only used for respective output. + +html only shows in html output: .. raw:: html

raw html

+latex only shows in latex output: + .. raw:: latex {\it raw latex} diff --git a/rst/included.rst b/rst/included.rst new file mode 100644 index 0000000..968ea5f --- /dev/null +++ b/rst/included.rst @@ -0,0 +1,4 @@ +title of included content +========================= + +included content diff --git a/docutils/makefile b/rst/makefile similarity index 73% rename from docutils/makefile rename to rst/makefile index 0e0126f..3ccffdd 100755 --- a/docutils/makefile +++ b/rst/makefile @@ -2,19 +2,19 @@ #can mkdir and output that dir. -override CC_LATEX ?= rst2latex.py -override CC_HTML ?= rst2html.py --math-output=MathML -override ID ?= -override IN_EXT ?= .rst -override OUT_DIR ?= _out/ -override RUN_NOEXT ?= a #basename without extension of file to view (with firefox, okular, etc.) +override CC_LATEX ?= rst2latex.py +override CC_HTML ?= rst2html.py --math-output=MathML +override ID ?= +override IN_EXT ?= .rst +override OUT_DIR ?= _out/ +override RUN_NOEXT ?= a #basename without extension of file to view (with firefox, okular, etc.) SRCS := $(wildcard *$(IN_EXT)) OUTEXT := .html OUT_HTML := $(patsubst %$(IN_EXT),$(OUT_DIR)%$(OUTEXT),$(SRCS)) OUTEXT := .pdf -OUT_PDF = $(patsubst %$(IN_EXT),$(OUT_DIR)%$(OUTEXT),$(SRCS)) +OUT_PDF := $(patsubst %$(IN_EXT),$(OUT_DIR)%$(OUTEXT),$(SRCS)) .PHONY: all mkdir html pdf firefox okular clean diff --git a/docutils/readme.md b/rst/readme.md similarity index 84% rename from docutils/readme.md rename to rst/readme.md index 1edc690..b3b3f9c 100644 --- a/docutils/readme.md +++ b/rst/readme.md @@ -1,4 +1,4 @@ -a python package for generating code documentation from comments. +`docutils` is a python package for generating code documentation. it contains a mojor specification of the `reStructuredTest` and the reference implementations `rst2pdf` and `rst2html`.