Git: Reverting back to specific commit

Posted on August 15th, 2010 in git | No Comments »

If you want to revert to specific commit (with known commit SHA hash), do this:
Find which commit do you want to revert to:


git log

Revert to specific commit:


# reset the index to the desired tree, for example 0ea59eb95218
git reset 0ea59eb95218
# move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}
git commit -m "Revert to 0ea59eb95218"
# Update working copy to reflect the new commit
git reset --hard

Solution written by Charles Bailey on stackoverflow.com. Thanks Charles!

Displaying Tweets on 20×4 serial LCD

Posted on August 11th, 2009 in Uncategorized | 1 Comment »

How about this? Displaying your friends Twitter timeline on 20×4 LCD display. I hate myself because of my fanatic checking for my friends new tweets. Come on, you know the drill :) So, for me to actually do some work, I wrote script for displaying those tweets on small LCD. This is how it works: when there are new (unseen) tweets, script turns LCD’s backlight on, display all new tweets (if there is more then one new tweet, each is displayed for 5sec) and after that turn backlight off. Simple!

For this to work, I’m using Ubuntu 9.04, Ruby 1.8.7 and Siliconcraft’s serial LCD (SC2004). For interaction with Twitter service I’m using my own (very simple) Twitter Ruby class and another one for interacting with LCD. Twittlcd.rb script is using those classes and every 3 min checks for new Tweets.

This is how it looks like:
Twittlcd 1

Twittlcd 2

Source code:
twittlcd.tar.gz
twittlcd.zip

Using PS3 BD Remote with Ubuntu Linux - Part 2

Posted on May 29th, 2009 in PS3, Python | 3 Comments »

Here it is. Part 2 of using PS3 remote with Ubuntu. In this part I will finally show you how to do something useful with remote. So, here is what we want to control with remote:

  • multimedia keys: previos/next song, up/down volume
  • cycle thru opened windows with alt-tab
  • open/close applications (music player, tv application, …)
  • whatever else you want and is controllable with keyboard or from script

Let’s get to work. I assume you have done all the “work” from part 1. If not, do it now. Next, we need library to emulate keyboard keypresses:


sudo apt-get install python-virtkey

I wrote a small wrapper around python-virtkey for easier using. Download it from github. Also, download all other scripts from there because we gonna need them in couple of minutes.

Using VirtualKey:
You’ll be using three methods from VirtualKey: press_key, hold_key, release_key, toggle_key. Hold_key is method for pressing some key and holding it pressed. Release_key is for releasing pressed key. Press_key is like you pressed some key and immediately after that released it. Small examples:


from virtualkey import VirtualKey
keys = VirtualKey()
# pressing "a" button
keys.press_key("a")
# pressing ctrl-c (holding control while pressing "c")
keys.press_key(["ctrl_left", "c"])
# holding alt and pressing tab
keys.toggle_key("alt_left")
keys.press_key("tab");
keys.press_key("tab");
keys.toggle_key("alt_left")

You can try example script (also from ps3bdremote github) which demonstrate how to use VirtualKey:


python virtualkey-test.py

Using remote:
ps3bdremote-thumbFinally, let’s map keys to remote so we can use it. On the left picture (click to zoom it) you can see how I mapped keys. You can, of course, change it as you like.

Enough talking, let’s test it!


python ps3-remote.py

You can add additional “actions”:


elif command == "stop":
   keys.press_key("xf86audiostop")

All key definitions are in virtualkey.py file.

Known issues:

  • pairing - you still need to pair with remote before using. If you know how to solve this, please help :) and leave a comment
  • alt+tab - you’ll have to use two keys for alt+tab. First, press square as this holds alt key. After that, press triangle which simulates pressing tab key. Press square again to release pressed alt. This has to be done this way because there is no information from remote what key is released, just that some key is released

So, this is it. Download scripts from github and enjoy. Again, your feedback is very appreciated. If you like or hate this script(s), leave a comment ;) Also, If you want to help and improve scripts. Thanks!

Using PS3 BD Remote with Ubuntu Linux

Posted on March 4th, 2009 in Python, Ubuntu | 15 Comments »

(There is now 2nd part of this post. Check it out.)

So, you want to use PS3 BD (bluetooth) remote with your computer which is running Ubuntu. Great. Here you can find all the information needed to accomplish this. All the scripts are written by me so your feedback is very appreciated. I’m using D-Link DBT-122 Bluetooth adapter (all bluetooth adapters should work) with already mentioned PS3 BD Remote (Model CECHZR1E) on Ubuntu 8.10 (Intrepid Ibex).

First of all, you need to install all the required applications:


sudo apt-get install bluez-utils python-bluez

Next, we need to find out bluetooth address of remote. On remote press start+enter and on computer start hcitool for scanning bluetooth devices:

hcitool scan

You will get output similar to this:


Scanning ...
	00:82:7C:B9:14:7A	BD Remote Control

Copy address of remote as we will need it in a second. If the scanning command provide no results, you should try it several times.
Next, download required scripts and extract them:


wget http://h00s.net/ps3bdremote.tar.gz
tar xvzf ps3bdremote.tar.gz
cd ps3bdremote

Now open ps3bdremote-test.py file (gedit ps3bdremote-test.py) and change address of remote (approx. 27th line) to match the address you did get with hcitool:


remote = ps3bdremote.PS3BDRemote("00:82:7C:B9:14:7A")

That’s all configuring. Let’s test it. On remote again press start+enter and start the testing script:


python ps3bdremote-test.py

Output should be similar to this:


Trying to connect to PS3 BD Remote...
Trying to connect to PS3 BD Remote...
Trying to connect to PS3 BD Remote...
Connected

If you have problems connecting to remote, terminate script. Press start+enter and immediatly after that start testing script. Eventually, it will connect with remote. After that press buttons on your remote and it will display pressed keys:


audio
releasedbutton
play
releasedbutton
eject
releasedbutton

That’s it. Now it would be cool if you could use these buttons to play/pause player on your computer, start tvtime etc. Well, you can. I will explain how in next post. To be continued :)

Scripts: ps3bdremote.tar.gz

jQuery: animating table rows

Posted on November 11th, 2008 in jquery | No Comments »

Animating table rows (fading in/out, sliding in/out…) is easy. For example let’s use this table:


<table>
    <tr id="row1">
        <td>column 1</td><td>columnd 2</td>
    </tr>
</table>

And javascript code:


$('#row1').fadeOut();

And it works! Well, not exactly. It works in Firefox, Safari, Chrome but not in IE (what a surprise). In Internet Explorer it does not animate instead it just hide it/show it without any animation. Solution is: you have to animate not entire row but row’s columns:


$('#row1').find('td').fadeOut();

So, if you want to animate rows or columns depending on browser you could do something like this:


if ($.browser.msie)
{
    $('#row1').find('td').fadeOut();
}
else
{
    $('#row1').fadeOut();
}

Hard lockups on Ubuntu 8.04 with NVidia

Posted on September 16th, 2008 in Ubuntu | 1 Comment »

Recently, I experienced a lot of hard lockups on my desktop computer running Ubuntu 8.04. When lock up occurred, everything just halted. I couldn’t ssh to it to restart, everything just stops. Only hard reset would help. Computer specs are: MB Gigabyte P35-DS3R, Core2Duo 2.33Ghz, 2GB RAM, NVidia 7900GS…

What was the problem? NVidia drivers. And speedstep/powernowd. When computer was in idle state, processor worked at 2.0GHz, under the load it worked at 2.33GHz. Sometimes when frequency changed, computer crashed due to NVidia drivers.

Here’s the solution:
Disable powernowd. Quick and dirty fix is to edit:

/etc/init.d/powernowd

After #! /bin/sh in new line add exit 0 so it looks like:

#! /bin/sh
exit 0
# Init script for powernowd
#
### BEGIN INIT INFO
...

Isolating users in FTP 7 using Active Directory

Posted on July 22nd, 2008 in Windows | No Comments »

This is quick guide for setting up isolated users in FTP 7 (Windows 2008) using Active Directory. Isolating users using Active Directory is very handy when you want to give FTP access to user’s documents which are redirected to server.

Back in Windows 2003 setting user’s home FTP dir was done using iisftp.vbs script. In Windows 2008 script is not available and this is one way you can do it using FTP 7:

1. Remove currently installed FTP 6 (Server Manager → Roles → Web Server (IIS) → Remove Role Services. Unselect FTP Publishing Service and IIS 6 Management Compatibility to remove).

2. Download and install FTP 7 (http://is.gd/YVg for x86 and http://is.gd/YVi for x86_64 architecture). IIS 7.0 must be installed.

3. Create new FTP site:

  • In IIS Manager, click on your server. In actions pane click on “Add FTP site…”
  • Choose name for you ftp site name. For physical path you can choose c:\inetpub\wwwroot. Chosen path actually doesn’t matter as it will be set for each user separately using AD.
  • IP address, virtual host and SSL set as desired
  • Authentication set to basic and authorization to all users

4. Define user’s home directory:

Only users which have their FTP Root and FTP dir set will have access to FTP.

I think this is my first Windows related blog post without my whining and complaining :)

Ping.fm Ruby Class

Posted on July 8th, 2008 in Ruby | 7 Comments »

Ping.fm is simple service for updating multi social networks. Ping.fm currently supports 18 social networks and custom url. Although it’s in beta, it works great.

Updating is possible thru variety of services/tools: AOL instant messenger, GTalk, iPhone Web app… Developer API is also available and it’s subject of this blog post.

I wrote a Ping.fm Ruby Class which acts as a wrapper for Ping.fm API. Using ping.fm class is easy (you’ll need a API key as well as user app key):


require "pingfm"
pingfm = Pingfm.new("abcde", "12345")
# abcde is API key and 12345 user app key
puts pingfm.validate()["status"]
# return OK if successful, otherwise FAIL

Posting is also easy:


require "pingfm"
pingfm = Pingfm.new("abcde", "12345")
pingfm.post("this is posted to all my services")

Class supports all Ping.fm API calls. All methods are well documented.
You can grab Ping.fm Ruby Class here:
pingfm.rb.tar.gz
pingfm.rb.zip

You can also get refactored version of Ping.fm Ruby Class done by Dale Campbell at http://github.com/Oshuma/pingfm/

Zakrpa za VMWare Workstation 6.0.3 na Ubuntu 8.04

Posted on May 3rd, 2008 in Ubuntu | No Comments »

Prilikom instalacije VMWare Workstationa na Ubuntuu 8.04 dolazi do greške kod kompajliranja vmmon modula i instalacija se prekida:


include/asm/bitops_32.h:9:2: error: #error only <linux/bitops.h> can be included directly
make[2]: *** [/tmp/vmware-config1/vmmon-only/common/cpuid.o] Error 1
make[1]: *** --_module_/tmp/vmware-config1/vmmon-only-- Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-16-generic'
make: *** http://vmmon.ko Error 2
make: Leaving directory `/tmp/vmware-config1/vmmon-only'
Unable to build the vmmon module. 

Problem je što je u 2.6.24 kernelu došlo do nekih promjena i nije moguće više includati bitops.h iz asm direktorija već iz linux.

Rješenje je dakle da se prije instalacije zamjeni linija u izvornom kodu vmmon modula iz #include “asm/bitops.h” u #include “linux/bitops.h”.

Kako bi olakšao ovaj posao, složio sam malu zakrpu koja rješava ovaj problem a koju možete skinuti na kraju posta. Uputstvo je jednostavno:

  1. otklonite trenutnu (potrganu) instalaciju VMWare Workstationa (vmware-uninstall.pl)
  2. raspakirajte vmware arhivu
  3. u vmware-distrib direktorij raspakirajte zakrpu
  4. pokrenite zakrpu (./vmware-patch.sh)
  5. pokrenite instalaciju VMWarea (sudo ./vmware-install.pl)

Zakrpa: vmware-patch.tar.gz

Shell history

Posted on April 11th, 2008 in Ubuntu | No Comments »

Na Planet Ubuntuu se pojavio trend postavljanja vlastitih shell historya odnosno popis najčešće korištenih naredbi. Nema razloga zašto se ja ne bih priključio tom trendu ;)


$ history|awk '{a[$2]++ } END{for(i in a)\
{print a[i] " " i}}'|sort -rn|head
90 exit
88 cd
79 ssh
66 ls
51 bzr
22 sudo
19 vim
18 python
13 ping
6 script/server