Montag, 30. Mai 2011

Count Regular Expression matches perl line

Count Regular Expression matches per line in several files using a Batch file and Perl:
REM @ECHO OFF

ECHO # #################### _count.bat #################### #
ECHO # Script to count regexp in lines in all filtered files in a given directory.
ECHO # (requires Perl 5.10)
ECHO # (C) 2011/05/30 by Frank Glaser
ECHO # #################################################### #

REM BATCH
REM %d% directory
REM %e% extension
REM %~dp0 path from batch
REM %1 filename as batch parameter
REM %~1 batch parameter without quotes
REM for /f for loop with several files
REM for "delims=" avoid splitting of filenames with spaces
REM %%F actual input file from batch for loop
REM dir /b simple format
REM dir /d wideformat with column sort
REM > dump stdout into file

REM PERL
REM perl -e perl one-liner
REM perl -l turns on line-ending processing
REM perl -n don't print every line
REM $c count
REM $m max
REM $_ actual line of file
REM $. actual line number
REM $ARGV perl actual input file
REM \t print tab

REM change working folder
cd /d "%~dp0"

REM check batch parameter
IF [%1]==[] (
SET d=%~dp0
) ELSE (
SET d=%~1\
)

REM set file extension
SET e=*.txt

REM set regexp
SET r=\.

REM for all files, count regexp per line, find max and dump into log
(for /f "delims=" %%F in ('dir "%d%%e%" /b /d') do call perl.exe -lne "$c=0; $c++ while $_ =~ /%r%/g; $m=$m>$c?$m:$c; END{print \"$ARGV \t $m\"}" "%d%%%F") > _count.log

REM dump log file
echo.
type _count.log
echo.

REM open log file
_count.log

pause

Attention:
Output file should have another extension as the input files.

Perl portable for Windows:
http://sourceforge.net/projects/perlportable/
Alternative:
http://strawberryperl.com

Update:
If You want to use awk, just replace the Perl line:
(for /f "delims=" %%F in ('dir "%d%%e%" /b /d') do call gawk.exe "c=0;{while(match($0, /%r%/)){c++; $0 = substr($0, RSTART + RLENGTH); }m=m>c?m:c;}END{print FILENAME\" \"m;}" "%d%%%F") > _count.log
Gawk for Windows:
http://gnuwin32.sourceforge.net/packages/gawk.htm

Montag, 23. Mai 2011

Note in GoogleReader ToolBar Button for Firefox

Install the Firefox extension:
https://addons.mozilla.org/en-us/firefox/addon/custom-buttons/

Alternative:
https://addons.mozilla.org/en-US/firefox/addon/custom-buttons²

To add new button you should:
* Go into menu View -> Add new Button....
OR
* Toolbar -> right click -> Add new Button....

Name: Note in Reader
Icon: http://www.google.com/reader/ui/favicon.ico
Code: loadURI("javascript:var b=document.body;var GR________bookmarklet_domain='http://www.google.de';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='http://www.google.de/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}");

Update:
Posted in CustomButtons² Database:
http://custombuttons2.com/en/node/1177
Add it directly

Mittwoch, 18. Mai 2011

Android Infinite Gallery

Provided a small Bugfix for the Android Infinite Gallery Project.
http://code.google.com/p/infinite-gallery/

Patch 1:
http://code.google.com/p/infinite-gallery/issues/detail?id=1
Bug in startUsingVelocity
this.moveByVelocity((int) -velocityX);
mFlingRunnable.startUsingVelocity((int) -velocity);
velocity is used with a negative sign twice

Donnerstag, 12. Mai 2011

Google Reader add a note without sharing the article

With the bookmarklet "Note in Reader", we can add an article to Google Reader.
Also we can add a note to the article with or without sharing the article.

Within Google Reader there is only a button "Share with Note" but no "Note only" button.

A solution is to add this feature to the Send To functionality:
(http://googlesystem.blogspot.com/2009/08/google-readers-send-to-feature.html)

Name: Add Note
URL:
http://www.google.com/reader/link?url=${url}&title=${title}&snippet=${source}&srcUrl=${url}&srcTitle=${title}
Icon URL: http://www.google.com/reader/ui/favicon.ico

Based on http://www.google.com/support/reader/bin/answer.py?hl=en&answer=147149

Update:
The simplest solution is pressing Shift+D, the iFrame (known by the bookmarklet) will popup.