Digital Wanderers

Friday, May 15, 2009

Javascript: How to find all occurences of a string in another string

In Javascript, the indexOf() method will find the index of first occurence of a string in another string.
txt = "You are like like me"
str = "ke"

ind = txt.indexOf(str)

But there is no native method in JS for finding all the occurences of a string.

Here is a function to do that.

function allindices(txt,str)
var lentxt = txt.length
var lenstr = str.length

var j = 0
var indices = new Array()
indices[0] = -1

if (lenstr > lentxt)
return indices;

var i = 0
while(i < lentxt - 1)

ind = txt.slice(i).indexOf(str)
//'ind' is the position of 'str' in the current slice

if (ind == -1)

return indices

i = ind+i //Shift the index

for(k in indices)
if (i == indices[k])
else if (k+1 == indices.length)
indices[j] = i
j = j + 1
i = i + 1
return indices

This function can be used as follows:

arr = allindices(txt,str)

if (arr[0] != -1) \\Print all indices
for(var i = 0;i < arr.length;i++)

Sunday, June 22, 2008

No sound in ChrisTV recorded file ?

I faced a problem while recording video using ChrisTV PVR 5.01
No sound got recorded in the video file(MPEG Recording Mode) is the problem.
Pictures are coming nicely.

Solution: Go to Program Settings -> Image and Sound Settings -> Sound In
-> Recording Control.

This will put sound in recorded file.

Thursday, May 22, 2008

How to download blocked filetypes from your office PC

Suppose your employer is blocking some filetypes(like avi,mp3) or due to some security settings you are unable to download allowed filetype(eg. zip), there is a solution to download these files using MediaConvert.

Idea is to convert the file to some other similar filetype.
If the file is .avi then you can convert it to .mov or some other format which is NOT blocked in your office.

Get the full url link (Copy Link Location in firefox) of the blocked file.
Let this link be
Now go to MediaConvert.
Select "Conversion From Url" option.
Paste your link in the File box and select input type as .avi .
Now come down and select the output file (here video) type to an unblocked video type(eg .mov).Press OK and wait for the download link.

I used the same technique to download a zip file.
It was blocked by my employer because the url contains the word "application/zip"
which is not allowed.

NB: Please verify that content of the file is not against the rules of the company.

Friday, May 2, 2008

How to Access USB Video Camera with Python for Windows XP

Here is a step by step guide on accessing USB Camera(Webcam) with Python and Python Imaging Library(PIL).
(For Windows platform).

1. Download and install Python 2.5 from here. You can choose the folder C:\Python25 for installation.

2. Download the zip file Videocapture from Sourceforge here.
Open the zip file and copy the vidcap.pyd in DLLs to C:\Python25\DLLs and files in Lib to C:\Python25\Lib folders respectively.

3. Download and run the EXE Python Imaging Library 1.1.6 for Python 2.5. You can run this exe from any folder.

The installation is over. Now you are ready to access the USB camera.

4. Open the GUI for Integrated Development Environment(IDLE) by Start -> Programs -> Python 2.5 > IDLE (Python GUI).

You can take a snapshot by executing three command lines only:

>> from VideoCapture import Device
>> cam = Device()
>> cam.saveSnapshot('Snap.jpg')

Snap.jpg file will be stored in the root folder C:\Python25.
It can be viewed by MS Paint.

PIL - Python Image Libray is a collection of files to manipulate images.
You can find a tutorial
here Python Imaging Library Handbook.