2015. július 3.

Very basic GitHub setup

Quick setup — if you’ve done this kind of thing before

git clone git@github.com:username/emptyproject.git

We recommend every repository include a README, LICENSE, and .gitignore.

 …or create a new repository on the command line

echo "# emptyproject" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:username/emptyproject.git
git push -u origin master

…or push an existing repository from the command line

git remote add origin git@github.com:mdhtr/emptyproject.git
git push -u origin master

…or import code from another repository

You can initialize this repository with code from a Subversion, Mercurial, or TFS project.

Startup Applications do not stick, they get removed if I add them

As the user, you can set more startup applications from
gnome-session-properties
(Application Menu / System tools / Preferences / Startup Applications)

I added two new applications,
however, I noticed that they did not start on the next startup.

This was because they were not added permanently to the Startup applications.

and this was because my ~/.config/autostart forlder's write permission owner was the root.

I changed this with sudo chown -R myuser:myuser ~/.config/autostart

Probably running sudo gnome-session-properties would also have been enough, but I did not try.

Git Usage Tutorial

The essencial knowledge of using Git: a case study


Create your working directory and the file you will test git with:
mkdir github-test-project
cd github-test-project/
touch testfile.txt
echo "some text" >> testfile.txt

Initialize Git:
git init // Initialized empty Git repository
ls -a // lists all files in folder: there is now a .git directory.
git status // will show that you have one untracked file (testfile.txt) in your git Working Directory.

(Optional) Set up a local user name and e-mail for a project instead of the global:
git config --local user.name "username"
git config --local user.email "username@users.noreply.github.com"
// will overwrite your git --global settings for this directory. This way you can use different accounts for different git projects. You can confirm these local changes with the git config --local --list command.

Add remote server to the project (i.e. GitHub):
git remote add origin git@github.com:username/github-test-project.git // to add remote named "origin". You can rename your remote to anything you like, but with "origin" you have the privilege to use git push without specifying the remote.
git remote -v // to list added remotes by name with address

The standard usage:

Working Directory and Staging Area or Index (add)
//you have one untracked file (testfile.txt) in your git Working Directory.
git add testfile.txt // adds the file to the Staging Area (aka Index)
echo "and some more text" >> testfile.txt //you change something on the file, and now you have a tracked and an untracked version of your file in git status
git add -u // adds the changes to the files that are already tracked but does not add untracked files to git. now you have - yet again - a single file shown by git status
git reset testfile.txt // un-add file = remove file from index = the opposite of git add file. If you do this, the test file will be listed as untracked one again.

Local Repository (commit)
// this is the point when making mistakes get nastier.
git commit -m "first version of testfile" // commits all your indexed (added) files with the message specified in -m "". Now testfile.txt is in the local repository, and git status shows no "to-be-committed" files.
gitk // check out the commit in the repository browser
git commit --amend // if you realize you want to change your commit message, this can happen right after you commited.

touch newtestfile.txt
git add newtestfile.txt
git commit --amend // if you want to add some new files to your last commit (you can also change the commit message this way) -- now both testfile and newtestfile will be in your first commit.
git update-ref -d HEAD // if you want to undo your initial commit (NOT RECOMMENDED!). This will not bring back the state before the initial commit, only delete the HEAD (master), so it seems as if no commit has been made in this project yet. You could also delete your .git directory and start over from scratch.

//let's add some more commit to see the proper undo method for commits
echo "some other text" >> newtestfile.txt
git add -u
git commit -m "this is the second commit" // now gitk shows already two commits
echo "some more txt" >> testfile.txt 
git add testfile.txt  // this is the last indexed file
echo "some more txt" >> testfile.txt // this is the last untracked change
git reset --soft HEAD~ // will undo the last commit in the sense as if it did not happen at all, but does not change the indexed and untracked files.

// DANGER ZONE (not Working Directory safe!)
// reverting untracked changes = overwriting with last tracked (added/indexed) version
echo "some more txt I will permanently undo" >> testfile.txt
git checkout -- testfile.txt

// DANGER ZONE (not Working Directory safe!)
// reverting commits and uncommited changes = overwriting with commited version
echo "some more txt I will permanently delete" >> testfile.txt 
git add testfile.txt 
git commit -m "a commit I will permanently delete" // this is my last commit
echo "some more txt" >> testfile.txt 
git add testfile.txt  // this is the last indexed file
echo "some more txt" >> testfile.txt // this is the last untracked change
git reset --hard HEAD // will delete everything since the last commit
git reset --hard HEAD~ // will delete everything since the before-the-last commit (it will also delete the last commit)

Upstream or Remote Repository (push)
// you have to create the remote repository before you can push to it. On GitHub this can only be done manually through your profile on the website.
git push -u origin master // the very first time you push, you have to specify remote name (origin) and branch name (master) for further usage. The -u sets the remote to be the upstream.
git push // can be used in further cases with default to origin and master.
gitk // now shows the remote branch head status

// community remote repositories exist so more people may work on the same code.
// this is when the terms merge, rebase, fork, etc. come in picture
// the thing with remotes is that they will be always upstream (chronologically behind you). This is why you have to change your local repository first, to be able to make changes on the remote.

// local-repository-safe removal of remote repository commits
git reset --soft HEAD~ // remove the last commit, as written above
git push -f // -f is for force

// this will ruin your local commit-history!
git update-ref -d HEAD // deletes the local HEAD
git reset . // remove all indexed files
touch readme.txt // you'll have to add something to git to have the HEAD position back
git add readme.txt// it can be any file you want
git commit -m "initial commit" // now you have a HEAD again
git push -f // since you have a HEAD, you can reset the remote HEAD with it.
// now you could delete the remote repo if you want (on GitHub you have to do this by hand)
// I think it is generally a good idea to initialize a new project with some uninteresting files, to have a commit history to refer to.

//to be continued with merge, rebase, fork, etc...
// use interactive rebase to clean up commit history before pushing to remote.
// with interactive rebase it is possible to rewrite all of your commit messages to be more informative (before pushing to remote). it is a great tool, but use with extreme care!

// to write formatted text for a readme of wiki page this is the reference

Getting started with Git

Git Basics
  • Git thinks of its data more like a set of snapshots of a miniature filesystem
  • if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored
  • you have the entire history of the project right there on your local disk
  • there is very little you can’t do if you’re offline
  • it’s impossible to change the contents of any file or directory without Git knowing about it (Everything in Git is check-summed before it is stored)
  • Git stores everything in its database not by file name but by the hash value (40-character string used for checksumming) of its contents
  • It is hard to get the system to do anything that is not undoable or to make it erase data in any way
  • Git has three main states that your files can reside in: committed, modified, and staged 
    • Committed means that the data is safely stored in your local database
      • your local database is called the "Git Directory" ("Repository"). This is what is copied when you clone a repository from another computer
    • Modified means that you have changed the file but have not committed it to your database yet
      •  this happens in your "Working Directory". The working directory is a single checkout of one version of the project.
    • Staged means that you have marked a modified file in its current version to go into your next commit snapshot 
      • the Staging Area is a file, generally contained in your Git directory, that stores information about what will go into your next commit
  •  The basic Git workflow goes something like this:
    • 1. You modify files in your working directory.
    • 2. You stage the files, adding snapshots of them to your staging area.
    • 3. You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.
Get the latest Git version installed:
  • Add the latest git version to your repository:
    • sudo add-apt-repository ppa:git-core/ppa 
  • Update repository list:
    • sudo apt-get update
  • Install the latest version of git:
    • sudo apt-get install git
  • Check git version:
    • git --version
Essential Git setup after installation
Set up an SSH key to use with GitHub

Get help:
  • there is a general man page and 
  • there are also separate man pages for each command.
  • Check out the Git CheatSheet
  • install GitK for a visual Git history browser

2015. július 1.

Removing text watermark from PDF

Following this guide, the solution for me was:
  1. Fix your PDF, just in case:
    pdftk original.pdf output fixed.pdf
  2. Uncompress your PDF for text manipulation:
    pdftk fixed.pdf output uncompressed.pdf uncompress
  3. Remove text watermark with SED:
    sed "s/Wow! eBook <WoweBook.Com>/ /g" uncompressed.pdf > unwatermarked.pdf
  4. Compress the edited PDF:
    pdftk unwatermarked.pdf output compressed.pdf compress
As usually, I had trouble using SED.
It turned out that sed -e "s/Wow! eBook <WoweBook.Com>/ /" did not work for me, but somehow the one without the -e option and with the /g flag did.