January 18, 2011

Git Completion under Screen in Cygwin

I experienced that git tab completion doesn't work under screen in Cygwin.

1. I have git completion file placed at /etc/bash_completion.d/git
2. Git completion works under plain Cygwin shell (without screen)

To solve this problem, I added following line to my ~/.bashrc file
source /etc/bash_completion.d/git
And added shell definition to the /etc/screenrc file.
shell /bin/bash

No it works, hooray!

Strange thing is, that before any of my changes screen had shell /bin/sh
echo $0
/bin/sh


And /bin/sh and /bin/bash has same size:
$ls -la /bin/sh /bin/bash
-rwxr-xr-x 1 Alan root 470542 Aug 13 20:58 /bin/bash
-rwxr-xr-x 1 Alan root 470542 Aug 13 20:58 /bin/sh


And they have same content too, the diff command produces empty output:
$ diff /bin/sh /bin/bash

However, despite of this similarity, I cannot source git completion file under /bin/sh, but I'm able to do this under /bin/bash.

$ /bin/sh
$ source /etc/bash_completion.d/git
sh: /etc/bash_completion.d/git: line 123: syntax error near unexpected token `<'
sh: /etc/bash_completion.d/git: line 123: ` done < <(git config -z --get-regexp '^(svn-remote\..*\.url
|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')'


$ /bin/bash
$ source /etc/bash_completion.d/git
$


Weird.

October 22, 2010

Cat all files in directory

$ cat catall 
for i in $(ls -rt1 `find -type f`);
do
# type file name in red color
echo -e "\033[31;1m$i\033[0m"
cat $i;
done;


This script won't work for files with whitespaces within their names

June 19, 2010

Just a reminder

Always investigate the error messages.

June 16, 2010

Google Closure menu with one selected item

Google Closure provides some UI widgets which you can use on your pages. One of such widgets is a menu widget.

In short, to produce a menu you'd need two pieces of code:

Here is an HTML piece:

<ul id="menu">
   <li class="goog-menuitem goog-option" id="item1">Item 1</li>
   <li class="goog-menuitem goog-option" id="item2">Item 2</li>
   <li class="goog-menuitem goog-option" id="item3">Item 3</li>
</ul>

And here is a JavaScript piece using Closure Library:
var menu = new goog.ui.Menu();
menu.decorate(goog.dom.getElement('menu'));


This will produce a menu which will maintain styles and dispatch events. The goog-option class makes menu items selectable. When a user clicks on an any element, the clicked element will get goog-option-selected style.
But when a user clicks on another item, that item's element will get this style too and you will end up with two selected elements. This is the default behavior and it is suitable for most of menu-like cases.

But what if you have a menu with single-select options, like a plain old HTML radio-group?
Then you need to handle selected items manually. I chose to implement a menu listener to manually deselect all previously selected elements:


goog.events.listen(menu, goog.ui.Component.EventType.ACTION, function(e) {
   /** @type {string} */
   var text = goog.dom.getTextContent(e.target.getElement());
   menu.forEachChild(function(c) {
       if (c != e.target) {
           c.setSelected(false);
           c.setChecked(false);
       }
   });
   caption.getElement().innerHTML = text;
} );

June 15, 2010

A script to compile Google Closure based project

Here is my script to build Google Closure based project: << EOF
#!/bin/sh

function showHelp() {
echo "
Usage:
$0 MAIN_JS_FILE [MODE];
MAIN_JS_FILE - A JavaScript file to compile.
MODE - If set to \"debug\" will omit compilation step and produce human readable script. This mode will not perform any checks on your JS code
Examples:

Compile in debug mode:
./compile.sh js/test.js debug

Compile with javascript checks and optimizations:
./compile.sh js/test.js
";
}

test -z "$1" && echo "MAIN_JS_FILE is required" && showHelp && exit 1;
test -f "$1" || echo "MAIN_JS_FILE is not a file" && showHelp && exit 1;

export dir=..
export compiler=$dir/compiler.jar
export closureLibraryHome=$dir/closure-library/closure
export calcdeps=$closureLibraryHome/bin/calcdeps.py
export target=./www/compiled.js

export mode="compiled"
test "$2" == "debug" && export mode="script"

echo running in $dir in $mode mode

python $calcdeps -i "$1" -p "js" -p "$closureLibraryHome" -o $mode --output_file="www/compiled.js" -c "$compiler" -f "--js_output_file" -f "$target" -f "--compilation_level" -f "ADVANCED_OPTIMIZATIONS" -f "--warning_level" -f "VERBOSE"

EOF

January 10, 2010

How to find find directories in Java?

FileUtils from commons-io doesn't helps you, when you want to find a list of directories.
Check out the commons-vfs library. The FileObject.findFiles can do that.

December 7, 2008

mplayer remote control with k750i

mobile phone + bluetooth = remote control

In order to pair my phone with computer I've used "Bluetooth Applet" that comes with Ubuntu Desktop. Of course, I was dreaming that everything will work form that point: I will move joystick on the phone to the right and mouse cursor will move to the right too. But of course it didn't.

I've been looking through Google search results and realized that a bunch of programs were written to perform this task. I don't remember all of them, but I chose anyRemote and it had the work done.

I've installed java client on my phone. Just used Bluetooth Applet to send /usr/share/anyremote/client/anyRemote.jar to my phone.

Then I've run
anyremote -f /etc/anyremote/Server-mode/mplayer.cfg

From my phone I've started anyRemote, searched for any server and connected.

Thats all. Now I am using my phone as remote control for my PC. I can control video playback, toggle fullscreen mode and open new video files.