Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

guillaume riflet http://webtopmania.blogspot.com

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Babelfish translate

Ok, so maybe some of you might think that Babelfish's the best translator out there. I don't know about that , but I do know where my towel is ;)
So, boys and girls, here's the bookmarklet that allows to translate your current web-page using the babelfish translation engine.

javascript:location.href='http://babelfish.altavista.com/babelfish/tr?trurl='+encodeURIComponent(location.href)+'&lp=%s&btnTrUrl=Translate'


To make it useful, save it as a bookmark in FF (or as a new search engine in Opera) and give it a keyword/shortcut by editing the bookmark's properties in FF (or the search properties in Opera). Let's call him, say 'bf', that should do it.

Here are some examples:
bf en_fr
bf fr_en
bf en_ja


Enjoy!
G.R.

Google translate bookmarklet

Here's perhaps the most powerful bookmarklet I've ever created ...
This one translates the current web page from your current browser session into another language!

Syntax from the address bar in your FF or Opera browser:
 tr <FROM>|<TO>


Examples:
 tr en|de
 tr en|fr
 tr en|pt
 tr de|en


Here's the bookmarklet code
javascript:location.href='http://translate.google.com/translate?u='+encodeURIComponent(location.href)+'&langpair=%s&hl=EN&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools'


FF instructions:
Copy/paste the code in a new bookmark. Then, in the new bookmark properties, edit the keyword/shortcut field and insert 'tr'. That's it!

Opera instructions:
Copy the bookmarklet code. Then, in tools-->preferences-->search-->add-->details, paste the code in the address field, fill in a name for in the name field, and write 'tr' in the keyword field. Then save all. That's it!

Opera Syncing using Svn

This batch file allows to run opera after checking out your web-based opera profile. When you terminate your opera session, the batch will commit the changes you made to your profile during the opera session.

 REM OperaSync.bat
 @echo off
 
 set PRG=Opera
 set TARGET=%APPDATA%/%PRG%/%PRG%/profile
 set EXEC=%PROGS%/%PRG%/%PRG%.exe
 set REPO=https://********.googlecode.com/svn/trunk/%PROG%Sync
 set USER=*************
 
 echo Checking out from %REPO% ...
 svn checkout %REPO% "%TARGET%" --username %USER%
 echo %PROG% running ...
 %EXEC%
 echo Commiting to %REPO% ...
 svn commit -m --force-log "%TARGET%"
 echo Done.
 
 @echo on


Here's the list of files that I update from a svn repo for my Opera profile
contacts.adr
files.txt
jscripts/
jscripts/deliciousmp3.js
notes.adr
opcacrt6.dat
opcert6.dat
opera6.adr
search.ini
sessions/
sessions/autosave.win
sessions/autosave.win.bak
speeddial.ini

Twitter bot weatherlisbon

This little bash script shows how to use curl, grep, tail, sed and perl one-liners in order to compose a bleeding-edge twitter bot.
This one returns daily weather forecasts for Lisbon city based on the BBC weather forecast rss feed.

#! /bin/sh

#Goto here
here=/home/guillaume/Personal
cd $here

#BBC Lisbon weather id
id=0048

#BBC weather RSS feed address
feed="http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/${id}.xml"

#City
city=lisbon

#temporary file
file="weather${city}"

#Weather twitter bot
twitbot=weatherlisbon:*******

#Timestamp the log file
echo .>> $file.log
date >> $file.log

#Read the RSS feed and filter it
curl $feed | grep 'title' | tail -n 1 | perl -wlne'm/title>(.*)<\/title/i && print $1' | sed -e "s/&#xB0;//g" > $file.txt

#Read the forecast into a weather variable
read weather < $file.txt

#Twit the weather variable away
curl --basic --user $twitbot --data status="$weather" http://twitter.com/statuses/update.xml >> $file.log

Some perl one-liners

Rename htm files to html
In windows:
>dir /B /S | perl -wlne"/([^ ]+)\.htm$/i&&rename$1.'.htm',$1.'.html'"


In linux:
>find | grep htm | perl -wlne'/([^ ]+)\.htm$/i&&rename$1.".htm",$1.".html"'

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS