неделя, 23 декември 2012 г.

git goodness (pt. 2)

Lets continue from p1. I promised interactive add, rebase and cherry-pick. Here they come!

interactive add

So here's the use case: you've been working as usual in your git repo, and suddenly a co-worker comes by tell you about this crazy bug. You start working on another thing, in the same branch, without stashing. Then the same happens again, now with a more severe bug. At the end you have a few separe changes going on in the same folder, touching the same files in different (or the same) locations.

Now you want, as a good code monkey, to commit each change in a separate commit. To do this you can use git add -p [filename]. That will prompt for each individual modified chunk, whether you want it added to the index. The cool thing is that you can split a long chunk in smaller ones (using s), or even edit the chunk with your favourite editorvim, for the most control.

rebase

I think rebase is the coolest feature of git. It just lets you modify your history in all ways imaginable, with a pretty neat interface :)

There are a few use cases. First imagine you've been working on some feature on a branch, where other also commit. Now that you have created a few commits and want to push you realize there are new commits on that branch, so you have to somehow combine your commits with the upstream commits. There are 2 options: merging and rebasing. Merging creates a new commit that combines you head with the remote head. It is the most straight forward, but it also complicates the history -- if you run git log --graph you'll see what I mean. If you prefer your history straight you have to use rebase. It moves your commits on top of the remote ones.

If you're contributing to open source project you might be required to rebase your commits on top of the latest HEAD. github pull requests are actually smart enough, so you can rebase and force-push and the rebased commits will appear in place of the old ones.

Another legitimate use case of rebase is to tidy up your commits before submitting them upstream. You can reorder commits, edit old commits, change their commit message and squash a few commits together. Just use the --interactive (or -i) switch -- you'll see all your commits in an editor, you can reorder them by copy-pasting lines, and other actions are achieved by changing the word in the begining of each line. The person who came up with this interface is genius.

The usage is simple (do you expect me to say anything else?): git rebase [on-top-of [what]]. If you're in the branch that you want to rewrite, you can just specify on-top-of, or where do you want to start placing the new (rewritten) commits. what is the branch you want to rebase, in case you're not on it right now. If you just want to rewrite some history, go to the head and say git rebase -i last-unchanged-commit to reorder, reword, squash the commits after last-unchanged-commit.

If you just want to rebase unpushed changes on top of current HEAD, you can use git pull -r -- that is pull and rebase, not merge.

When you hit a rebase issue, you git add the broken files after you've fixed them and you issue git rebase --continue. If shit hits the fan -- bail out with git rebase --abort.

cherry-pick

Cherry pick lets you copy one commit to another place (normally another branch). You just go where you want the commit to be copied, and say git cherry-pick commit-id. That is it. If you were looking for something more fancy -- sorry for the disappointment.

stash (bonus material)

Consider the use case in the interactive add scenario. Only this time you realize on time, that you'd start working on a second thing, so you can save your current changes for later. You just say git stash [-u] and you have a clean folder again, ready for hacking! -u tells stash to also save the untracked files -- really handy. When you're done hacking and want to continue your work you do git stash pop -- which brings back all the changes you'd done before the stash.

вторник, 20 ноември 2012 г.

Keep the internet free (yet again)

https://www.whatistheitu.org/. Прегледайте видеото и линковете отдолу. Ако си дадете мейла, в получения мейл има линк за изпращане на мейл страницата до народните ни председатели. Преведох шаблона на български (все пак искаме да ни разберат посланието). Зори оправи всички грешки в оригиналния превод, за което много благодаря.

Уважаеми г-жо / г-не,

На предстоящата Световна конференция по международните далекосъобщения (WCIT) в Дубай, правителства ще разглеждат предложения за промяна на правомощията на Международния съюз по далекосъобщения (ITU). Някои от предложенията ще дадат възможност на ITU да заплаши прозрачността и иновацията, които направиха Интернет това, което е в момента, ще увеличи цените за достъп и ще намали човешките права в мрежата.

Интернет е мощно средство за комуникация, икономически двигател и разширява човешките възможности. Дискусиите за неговото бъдеще трябва да включват колкото се може повече заинтересовани лица, включително държавни представители, технологични експерти, бизнес лидери, граждани и организации за защита на човешките права.

Пиша ви, за да ви помоля:
- да отхвърлите предложенията на WCIT които дават възможност на ITU да управлява Интернет, и по-специално тези които ограничават човешките права в мрежата;
- да направите обществено достъпни предложенията които България и другите страни ще направят на WCIT;
- да се допитате до мнението на Вашите граждани и експерти по предложенията, включително да поканите заинтересовани страни да вземат участие в Българската делегация;

Организацията ITU е направила много за доброто на света и аз се възхищавам на усилията ѝ. Също обаче споделям мненията на много хора по света които вярват, че взимането на решения относно Интернет трябва да се прави прозрачно, с участието на много заинтересoвани лица от обществото, правителствата и частния сектор, а не само от ITU.

С уважение,


петък, 16 ноември 2012 г.

dbus resolved

In case you've been living in a cave for the last 10 years in regard of Linux desktop managers you've probably missed D-Bus, or at least tried to avoid it as much as possible due to its over-engineered nature or the fact that its not automatically started by your bare bones window manager.

At least I did.

But today I found the best way to experiment/use it in your favorite shell. The command is called qdbus (oh well, you have to install qt for that, but it's worth it!).

  • Without arguments it will print all available services (first level address in dbus).
  • With a servicename as a single argument it prints all paths available for that service name (second level address)
  • With a servicename and path it lists all available methods, signals and events (third level)
  • You can specify all three (service, path, method) (+ arguments) and whoala! You'll never get the bad feeling in your stomach again, when you try to call a method or two via dbus

I hope this will help somebody else.

неделя, 4 ноември 2012 г.

Free leach torrents switch

In case you use lztr us, what.cd, pass the popcorn or anything based on project gazelle, which you shouldn't be doing because it's illegal, you can try passing &freetorrent=1 to torrents.php (in the url bar) and it will list all free leach torrents available at the moment. Just sayin'.

събота, 3 ноември 2012 г.

Dell touchpad recognized as PS2 mouse

I just want to put this online in case somebody has the same issue.

So here's my setup -- I have a Dell Latitude E6430 laptop. I have arch linux installed on it, and the touchpad was recognized as PS2 mouse, hence multitouch gestures were not working, including two-finger scroll and multitouch tapping.

A friend of mine suggested that this was actually not an elantech touchpad, but an ALPS one (low cost elantech). So a different driver was needed. The package that fixed the issue for me was psmouse-alps-driver from AUR. In case you use a different linux distro, try this url -- from the guys who wrote it. It is a replacement psmouse kernel module, built with dkms.

Commands you might find useful:

dmesg | less
and search for PS2
modprobe -r psmouse
remove old psmouse driver
modprobe psmouse
reinsert psmouse driver (after installation)
dkms status
see status of dkms managed modules
xinput
list X input devices

Update 16 Nov 2012

And everything works flawlessly until you decide to upgrade your kernel. You may imagine what would happen with your custom-compiled kernel driver. Just issue dkms autoinstall to recompile the driver against the current kernel, and then modprobe -r psmouse to remove the old one (if any) and modprobe psmouse to insert the new one.

And thats it! Until you upgrade your kernel ...

If you're using arch linux you can enable the dkms.service: sudo systemctl enable dkms.service, so it would do that for you on reboot.


четвъртък, 1 ноември 2012 г.

git goodness (pt. 1)

This post is intended for people, who know the basics of git and want to go to the next level ;-)

Branches

A git branch is just a reference to a commit. You can easily change the reference by git reset --hard <refspec>. The first time you do this you are most probably going to lose some commits :) To see the commits you were on recently, try git reflog, and then another git reset --hard <refspec> to point your branch to the right commit.

Remote branches

These are branches on remote repositories. They are read only -- that is, you can not change where they point to by hand. You can update them with git fetch <remote>. Note that git pull does a fetch and a merge/rebase, so it would update them too.

By default you do not have local branches representing all remote branches, just for master. If you have a remote origin with a branch coolbranch, just use git checkout -b coolbranch origin/coolbranch

Deleting remote branches is odd. Use git push origin :branchtodelete and don't ask me why :)

Tracking branches

You can specify that a local branch is linked to a remote branch, so that git pull and git push work without additional arguments.

If you created a new branch on your local machine and want to push it (to say, github.com), you would do git push -u origin newbranch. -u tells git to set newbranch as tracking origin/newbranch.

When you start working on a new branch from origin, if you do git checkout -b branchname it sets local branch branchname as tracking origin/branchname.

gitconfig

User-wide git configuration resides in ~/.gitconfig. Here is mine, I think its good enough to be shared ;-)

[user]
  email = your.name@email.com
  name = Your Name
[alias]
  st = status
  ci = commit
  co = checkout
  l = log --graph --decorate --pretty=oneline --abbrev-commit --all
[color]
  diff = auto
  log = auto
  status = auto
  branch = auto

Aliases are a great way to save you from typing the most common commands. I also had the habit of using st and co from svn and mercurial, so if you're also used to that add them in.

Everybody likes fancy colors nowadays (even me!), they also make the output more readable. To enable colorful output just include the [color] section and list the commands you wish to see in color. You can also specify the colors used, check the docs for more info on that

Read more about the long line in the next section

history

Checking the repo history is a fundamental operation. I'll explain the most useful options here:

git log <commit>

Lists all ancestor commits of the given commit, or HEAD if no commit is given. The commit hash, the author and the full commit message are shown. Use this if you want to search the history for a given commit (sha128) or words you hope to find in the commit message.

git log -p <commit>

The same as above, but also include the diffs of each commit. Very handy if you want to check the history of something in the source code like a function or variable.

git log <path/to/file>

You may also check the history of a particular file.

git log --graph --decorate --pretty=oneline --abbrev-commit --all

I use this recipe to get an ascii graph of all commits in the repo. I use it so often that I aliased it with git l (check gitconfig above). Experiment with a subset of the options to see what they do.

To be continued...

This turned out longer than I expected. I hope I can post more on this topic, more specifically interactive add, rebase, cherry-pick. Stay tuned.

събота, 11 август 2012 г.

keybinds in console

Наскоро научих как точно се настройва коя клавишна комбинация какво прави в терминала. Сега ще споделя това знание... за да може като го забравя да си го прочета от тук :)

клавиши и комбинации

За съжаление, комбинациите не се задават в някакъв четим формат а приличат на нещо от сорта на ^[Od (ctrl + left arrow при мен) или ^[^[[D (alt + left arrow). За да разберете коя комбинация, на каква последователност отговаря стартирате read, натискате и гледате какво излиза на екрана. Ето какво излиза при alt+up, delete, end на моята машина:

[iskren ~]% read
^[^[[A^[[3~^[[8~

После заместваме ^[ със \e като пишем последователностите, т.е ^[^[[A става \e\e[A, ^[[3~ става \e[3~ и т.н.

команди

След като харесате кой клавиш искате да прави нещо, трябва и да обясните какво точно искате да прави :) За да видите списък със всички команди, в терминал (zsh only tested) натискате alt+x tab tab. В общи линии това са extended commands стил emacs но има и други.

клавишни комбинации + команди

Сега остава да напишете някъде коя комбинация, коя команда искате да стартира. Единия вариант е да ги сложите в /etc/inputrc, където формата е "combination": command. Другия е да сложите в $HOME/.zshrc bindkey "combination" command. Обърнете внимание, че комбинацията се задава в двойни кавички.