Character substitution on Jquery

Here an easy way to search and replace each occurrence a group of characters (in this case underscore and minus) with another (in this case a space) on a specified element (in this case each A), using Jquery javascript library.

$("a").each(function() {
   $(this).html($(this).html().replace(/[_-]/g," "));
});

The first argument passed on replace is a regex, if you just pass a single character (like “_” or “-”) only first occurrence for each element.

Real world usage: I use this onto a long page, where a table has long filenames with underscore and minus in place of spaces. This trick allows in my case to show tables nicely, without caring on a mass substitution via server side scripting.

See also:

Video on Flash doesn’t buffer? Maybe a FLV and MP4 issue

I recently tried Flowplayer a Flash video player released under GNU GPL license. It’s great, since it has a plugin allowing pseudostreaming (it allows buffering from any server) with both FLV and MP4 (H.264 / AC3).

Using avidemux to convert my videos, I had no problem to play FLV files: buffering works as expected, I watch video while buffer is filled. But on MP4, I’ve to wait the video is fully buffered (downloaded entirely).

This is not a Flowplayer issue: this exaustive howto explain that FLV and MP4 files should be properly indexed to works with pseudostreaming.

  • For FLV files, you can use Flvtool2, a Ruby gem, available also on apt / synaptic via “apt-get install flvtool2″ (Debian packages, description on rubyforge). Using avidemux, FLV files are ok even if I don’t use Flvtool2, so FLV metadata seems correctly handled by Avidemux. Ready for pseudostreaming!
  • For MP4 files, you have to move MP4 metadata (”moov atom”) from the end of the file to the beginning, since Avidemux seems to put it on the very end of the video file. To do this, I’ve used successfully a tool named mp4box (mp4box on videohelp, author website) using MP4Box-0.4.6-dev_20090519 version (win32 binary). Read also MP4box documentation on GPAC, you can also get it on sourceforge.

MP4Box usage example:

MP4Box.exe -add TEST_src.mp4 -new TEST_dst.mp4
IsoMedia import – track ID 1 – Video (size 848 x 480)
IsoMedia import – track ID 2 – Audio (SR 44100 – 2 channels)
Saving TEST_dst.mp4: 0.500 secs Interleaving

See also:

Flowplayer forum posts on same topic:

Qt-fastart (FFMpeg alternative), another post

Animax in Italia

L’animazione giapponese nella televisione italiana degli ultimi anni si è affacciata con proposte interessanti principalmente per opera di MTV. Una sera alla settimana (il martedì), il canale musicale trasmetteva e continua a trasmettere una fascia dedicata agli anime dedicati ad un pubblico di teenager e giovani adulti, comprendendo negli anni titoli come Cowboy Bebop, Inuyasha, Fullmetal Alchemist, Le situazioni di Lui & Lei, BECK, Full Metal Panic, Death Note, NANA, Kenshin, GTO (elenco completo).

Una volta l’anno, lo stesso canale trasmetteva un assaggio di alcuni titoli distribuiti principalmente da Shin Vision (attualmente fallita), Dynit e Yamato in un evento autunnale chiamato Anime Week (maggiori informazioni su IAC, maggiori info su Wikipedia) che sembrava fungesse da vetrina per i distributori, dato che molti titoli non venivano poi successivamente trasmessi dalla rete ma resi disponibili contestualmente in home video.

Mentre l’ultima anime week risale al 2006, alcuni canali satellitari hanno iniziato a popolare i propri palinsesti di anime, mentre sono sorti canali dedicati (ad es. Cultoon diventato poi Cooltoon), senza contare che alcuni canali satellitari come Cartoon Network hanno incluso anch’essi animazione giapponese (ad es. School Rumble) in una programmazione più variegata.

Il 12 gennaio 2007 Sony, che vanta un canale satellitare chiamato Animax trasmesso in tutto il mondo, decide di aprire una fascia di animazione giapponese nel canale satellitare AXN, che fino a quel momento trattava principalmente telefilm d’azione statunitensi (es. McGuyver).

In questa fascia, che sembrava sarebbe dovuto fungere da test per lo sbarco del canale satellitare dedicato Animax in Italia, viene trasmesso fra gli altri un titolo di alto pregio come PlanetES, accendendo le speranze degli appassionati italiani (articolo su AnimeClick). La fascia viene prima migrata in orari notturni e successivamente soppressa (articolo su Animeclick). L’avvento di Animax in Italia viene quindi rimandato ad una data indefinita.

Mentre il canale si diffonde in Germania, Spagna, Portogallo, Polonia, Repubblica Ceca, Slovacchia, Ungheria, Romania, l’Italia resta al palo.

Per tentare di organizzare il vero ritorno del canale in Italia nella forma in cui è conosciuto negli altri paesi del mondo, nasce prima il sito web animaxinitalia.org e successivamente una causa su Facebook chiamata Animax in Italia, che al 15 marzo 2009 conta 54 aderenti. L’obiettivo è raggiungere un numero di aderenti tale da poter chiedere formalmente alla Sony di riconsiderare lo sbarco del canale tematico in Italia, dimostrando l’interesse attivo degli appassionati italiani verso un canale di animazione giapponese recente.

Iscriviti alla causa Animax in Italia

Iscriviti alla causa Animax in Italia (cliccando sul banner e poi su Join). In caso non l'abbia già fatto, devi prima autorizzare l'applicazione Causes.

P.S. Ringrazio Cesco per aver acconsentito all’uso del logo modificato di Animax per la causa e ovviamente per aver avviato animaxinitalia.org.

Vedi anche:

Howto merge two torrent files

Sometimes you want to download a torrent that you’ve partially downloaded. Many bittorrent client allow partially downloaded files, but what if you’ve downloaded the same torrent twice, with differents parts available?

Use Zeroconf / Local peer

I’ve used two client on the same LAN, ktorrent (on Debian) and utorrent (on Windows XP). I’ve two downloaded files (or folder) from the same .torrent, with different parts downloaded.

  • Enable Zeroconf plugin on ktorrent
  • Check if on utorrent “Enable local peer discovery” is enabled
  • Import existing download #1 on ktorrent
  • On debian system, as root type ifconfig to discover your local IP address, i.e.  inet addr:192.168.0.XX
  • Go to ktorrent preferences and check the used port (e.g. 12345)
  • On utorrent go to Peers tab on #2 download. Right-click > Add peer
  • Type your first machine IP address (e.g. Debian) and the first bittorrent client port (e.g. 12345 on ktorrent),  e.g. 192.168.0.XX:12345 with no protocol prepended.

On both client you’ll notice a new peer, downloading and uploading very fast. Little after, the two downloaded files / folder could be completely merged.

You can now close #2 and continue to download the torrent on a single machine / client from external peers.

Note: I’ve tested this method on the same machine using Virtualbox (Debian as host, XP as guest).

See also:

Howto extract tracks from mkv and avi

This howto requires:

  • mplayer
  • mkvtoolnix
  • your Linux box ;)

Audio from Avi files (es. Xvid + MP3):

mplayer -dumpaudio "mymovie.avi" -dumpfile mymovie_audio_track.mp3

Tracks from Matroska MKV file:

List all tracks:

mkvmerge -i mymovie.mkv

File 'mymovie.mkv': container: Matroska
Track ID 1: video (V_MS/VFW/FOURCC, XVID)
Track ID 2: audio (A_VORBIS)
Track ID 3: audio (A_VORBIS)
Track ID 4: subtitles (S_TEXT/UTF8)
Track ID 5: subtitles (S_TEXT/UTF8)

mkvextract tracks *.mkv 3:mymovie_audio_track.ogg 4:mymovie_subtitle.srt

Creates two files, mymovie_audio_track.ogg (track 3) and mymovie_subtitle.srt (track 4).

Installing Plone on Debian

A little howto to quickly install and try Plone (a GPL’d CMS based on Zope) on your linux box. Well, the installer seems to do the job nicely. :)

Tested on Plone 3.* version, Debian “Lenny”.

  • apt-get install g++
  • Download latest version of Plone (Unified Installer)
  • Execute:
    tar zxvf Plone-YOURVERSION-UnifiedInstaller.tgz
    cd Plone-
    YOURVERSION-UnifiedInstaller
    ./install.sh standalone
    gedit /usr/local/Plone/zinstance/README.txt &
    gedit /usr/local/Plone/zinstance/buildout.cfg &
    /usr/local/Plone/zinstance/bin/plonectl start
    less /usr/local/Plone/zinstance/adminPassword.txt
  • README should be read to follow installation instructions, then you can modify Plone configuration on buildout.cfg, and then you can start Plone. On adminPassword.txt you’ll find your Plone passwords to use for administrative purpouses.

  • Add /usr/local/Plone/zinstance/bin/plonectl start to /etc/rc.local before exit 0 (Red Hat) to run plone at any server restart or create a script on /etc/init.d/ (Debian) like.

Now you can test this CMS based on Python (I’ve tested it 4 years ago, maybe it hardly can replace Drupal but you can give it a try ;-) ).

RPM Rebuild on Linux Red Hat Enterprise

A quick howto on RPM rebuilding from source:

yum groupinstall "Development Tools"
yum install rpmdevtools
# unpack old tar.gz
tar zxvf my-package-0.0.0.tar.gz
mv my-package-0.0.0.tar.gz orig.my-package-0.0.0.tar.gz

[change interested files]

# create a new tar.gz file, preserving privileges

tar -pzcvf my-package-0.0.0.tar.gz my-package-0.0.0/

Create RPM from tar.gz

rpmbuild -tb my-package-0.0.0.tar.gz

The “-p” stays for “preserve privileges”

You got something like:

Wrote: /usr/src/redhat/RPMS/i386/my-package-0.0.0.i386.rpm
cd ~
cp /usr/src/redhat/RPMS/i386/my-package-0.0.0.i386.rpm ./
rpm -i my-package-0.0.0.i386.rpm

See also:

Mount NTFS partition on Debian

Once upon a time, writing to NTFS was a chimera. For years I tell to friends to use FAT32 when installing Windows XP. But now the NTFS support is fine, even on Debian. Just type on your shell:

sudo apt-get install ntfs-3g

sudo mkdir /media/win

And add to your /etc/fstab:

/dev/YOURDEVICE /media/win ntfs-3g umask=0,nls=utf8 0 0

Where YOURDEVICE is /dev/something you can found on Partition Editor for the your NTFS partition. Do a mount -a or reboot to apply changes, and then go to /media/win directory to start to read.

See also:

Save user profile on Drupal

Tested on:

  • Drupal 5.x

After you have created some user fields through Profile module provided by core, you can have the need to save value into the user object. Here a quick howto to do this.

On user creation:

/** create user profile ($new_user will be an user object) */
$new_user_array = array (
  'name' => "funnyusername",
  'pass' => "MyVerySecurePassword",
  'mail' => "info@example.gom",
  'status' => 1, # status: active
);
$new_user = user_save(NULL, $new_user_array, $category = 'account');
/** assign values to profile fields */
$new_user_edit =  array(
'profile_surname' => "Yumemiya",
'profile_name' => "Arika",
);
/** create and save profile fields */
profile_save_profile($new_user_edit, $new_user, "Character ID");

Where “Character ID” is the category name for profile_surname e profile_name.

To load current user instead creating new one, you have to use

global $user;

instead a previously declared user object $new_user.

See also:

Update:

  • Using this method during a cronjob (using hook_cron) I experienced an error: profile values are passed, but not written, but only if cronjob is launched automatically, and not forced by Report screen (as admin). After some days, I discovered that it’s a permission issue.
    Problem:
    Add a “cronbot” user with some privileges over user (”administer user”) to allow writing even on hidden Profile field.
    Solution:
    On a dedicated server, with a dedicated IP, you can automatically login by IP (by IP Login module for 5.x and 6.x) the cronjob using the server IP or loopback address (127.0.0.1) depending on server configuration (I use the first in production, the latter on local testing).

    1. Add an ip_login Profile field (single line text field, hidden field)
    2. Enable IP Login module
    3. Assign ip_login field to IP login by IP Login configuration screen
    4. Create a new role named “cronbots”, with “administer users” permission.
    5. Create a new user named “cronbot”, with “cronbots” role assigned
    6. Change the “IP login” field for “cronbot” to your server IP (127.0.0.1 or your static IP address as listed on ifconfig on *nix servers)

    On the next automatic cron run (not force it), you’ll see the “cronbot” user logging in. On Drupal logs, the cronjob execution pass from “Anonymous” to “cronbot”, and profile fields are rightly written.
    The other way:
    Just write profile field via db_query. (You don’t want to do a weird thing like that, right? ;) )

PEAR install quick howto on Debian Lenny: Image_Graph

Tested on Debian Lenny.

Time elapsed before a working script < 10 minutes ;-)

Install PEAR installer:

# apt-get install php-pear

First, type:

pear -h

to get help.

On root shell type:

# pear install --alldeps Image_Graph

Install failed with error:

Failed to download pear/Image_Graph within preferred state “stable”, latest release is version 0.7.2, stability “alpha”, use “channel://pear.php.net/Image_Graph-0.7.2″ to install

Retype as:

# pear install --alldeps Image_Graph-0.7.2

Repeat for other alpha dependencies the same procedure, eg:

pear install --alldeps Numbers_Words-0.15.0

At last, you got:

Nothing to install

Now, you can find all installed packages on /usr/share/php.

ImageGraph is installed on /usr/share/php/Image/Graph.php.

You have to include it on your PHPs.

You can follow the Ian’s howto on:

http://www.phpbuilder.com/columns/ian_gilfillan20060503.php3

To start using PEAR Image_Graph.

Here the result using Ian’s code on my Linux box:

Image_Graph test, using Ian code

Image_Graph test, using Ian code

Additional info:

Hosting providers (eg. HostMonster) sometimes furnish simplified PEAR installation via CPanel. So, you can use local PEAR installation for developement, and online installation for production use.

Remember:

  • To check differences between local and production versions
  • To change include path! (say no to white screen!)

See also:

Next Page »


IE6: Rust in Peace

Blog Stats

  • 78,142 hits
My Bookshelf

Texts double licensed under Creative Commons Attribution - Share Alike license and GNU Free Documentation License. Examples may contain software licensed under GNU General Public License. Images and comments texts aren't necessarily licensed under these terms.