Posts Tagged ‘tips’

Mouse gestures in Chrome (and elsewhere)

Friday, September 11th, 2009

After checking the gestures extension for Chrome/Chromium I decided to use a small freeware utility instead, StrokeIt, which is free for personal use and can recognize mouse gestures, convert them to shortcuts or messages and send them into applications – and has an extremely small memory footprint. Really nice indeed!

But what’s the problem with the extension? The fact that it uses the document.body to capture the gesture means that it will have a hard time with the mouse crossing document boundaries – iframes for example (which are widely used with banners and widgets/gadgets), so unless you implement the gesture system in the application itself (Opera) or give a greater control to the extension (XUL) this is not a way I want to go with.

For Linux I’m sure a similar solution exists (probably something -l -i |ke –this| or > similar &) and Apple people always have their nicely designed shareware software with an ever awesome gui and candy-cute icons – though most of them aren’t aware that browsers other than Safari do exist.

Clean/truncate filenames before writing them to a CD/DVD

Sunday, August 23rd, 2009

I’m an old-fashioned IT guy: in filenames I prefer the standard ASCII character set, no spaces, no weird international characters and no meter long names. Before writing a directory to a DVD:

<?php
function cdRename($path, $maxlength) {
$pi = pathinfo($path);
$ext = isset($pi['extension']) ? $pi['extension'] : FALSE;
$fn = $pi['filename'];
$fn = substr($fn, 0, $maxlength);
$fn = str_ireplace(//iso 8859-1 only :((
array('á', 'à', 'ã', 'â', 'é', 'è', 'î', 'í', 'ú', 'u', 'ö', 'õ', 'ô'),
array('a', 'a', 'a', 'a', 'e', 'e', 'i', 'i', 'u', 'u', 'o', 'o', 'o'), $fn);
$npath = $pi['dirname'] . DIRECTORY_SEPARATOR . $fn . ($ext ? '.'.$ext : '');
if ($npath != $path) rename($path, $npath);
}
$it = new RecursiveDirectoryIterator('./');
// RecursiveIteratorIterator - 0: LEAVES_ONLY, 1: SELF_FIRST, 2: CHILD_FIRST
foreach (new RecursiveIteratorIterator($it, 2) as $path) cdRename($path, 170);
?>

This is a PHP cli (shell) script, it truncates filenames (without touching the extension) and removes some international characters, which may pose problems when transferred to ntfs/fat/samba/ext3 etc. Unfortunately PHP is still a crap and if you save this script in UTF-8 then it will not work (at least it did not work for me on ntfs and php 5.2.6), so so far one can only replace iso 8859-1 characters; hope this will change with version 6. The script can also rename directories, since the iterator takes children items first – hope someone finds this useful.

Firefox 3.5 not-so-awesome bar

Saturday, August 22nd, 2009

Since the 3.0 series (released more than a year ago) the url bar is driving me nuts: sometimes it takes 7-10 seconds to come up with the first possible url and locks the browser until then; I really don’t like tweaking the about:config page, but I did do that for this one; now it’s okay – still, it’s a shame: we have canvas, html 5 video, css 3 selectors, new gradient crap is coming up, yet the ui still has some unfixed problems…

EDIT: false alert. Still sucks; maybe if I delete all my bookmarks AND empty the history each and every day… but wait, what’s the point in having this awesome location bar then?

Convert m4a to wav or flac with script

Thursday, January 1st, 2009

For some reason Winamp couldn’t play the Apple Itunes m4a files for me, so I wanted to have a quick solution to convert m4a files to lossless flacs. VLC can write into files as an output, but with that the dumping speed is 1:1, which is not very fast. Basically the solution is just a couple of shell commands, so if you know mplayer, feel free to check the code bellow.

Okay, this is going to be pretty rough: this is a php shell script, I run on Windows, because:

  • I don’t like Cygwin and I totally hate cmd.exe batch scripting (in this case FOR /R and backslashes).
  • I know about the ecmascript and vbscript interpreters and yes, I totally hate those, because they suck compared to plain old Bash and friends.
  • This is a command line php script; I’m on Windows, I registered the .cphp file extension to be handled by php cli, so I just press enter on such file. Believe me, this saved me hours of work, especially at my workplace, where I am using XP and cygwin is broken like hell (I don’t know the admin password to remove it). I know Python is all the hype, but I couldn’t care less.
<?php
$files = explode("\n", `dir /b /o:n *.m4a`);
$mplayer = 'Q:/bin/mplayer/mplayer';
$flac = 'C:/Progra~1/FLAC/flac';
foreach ($files as $file) {
$file = trim($file);
if (!empty($file)) {
echo "Converting $file\n";
shell_exec("$mplayer -vc null -vo null -af volnorm -ao pcm:fast:waveheader:file=\"$file.wav\" \"$file\"");
shell_exec($flac . ' -8 "' . $file . '.wav" ' . str_replace('.m4a.wav', '.flac', $file));
}
}

Jedit: include macro

Monday, October 27th, 2008

Jedit macros can end up pretty verbose and complex and I really hate copy pasting. So, the solution: first set up a directory where the macros can be stored (see my previous post for that), then let’s define a require function in the startup.bsh file:

void require(View view, String filename) {
String script = file_get_contents(MACROLIBPATH + filename + ".bsh");
result = BeanShell.eval(view, BeanShell.getNameSpace(), script);
}

As you might have realized, I used file_get_contents, which is “not really java”; let’s fix it:

String file_get_contents(String filename) {
String s = "";
String ret = "";
FileReader fr = new FileReader(filename);
BufferedReader br = new BufferedReader(fr);
while((s = br.readLine()) != null) { ret += s + "\n"; }
fr.close();
return ret;
}

Yes, I know, my beanshell scripting knowledge is not that great, but hey, it works…
Now for an example macro (call it example.bsh and save it into your macrolib directory):

prettyFunction(view, message) {
Macros.message(view, "Hi! You got a message: " + message);
}

String prettyMessage = "it works!";

Now this should work (in another macro):

require(view, "example");
prettyFunction(view, prettyMessage);

In case you know a solution to the scattered view parameters, let me know.