Sunday, November 13, 2011

Starting MongoDB and php on Ubuntu

Installing MongoDB on Ubuntu:
1. Add 10gen package to source.list 
The 10gen package contains the latest mongoDB version, append below line to the end of the file “/etc/apt/sources.list”
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
For example, you can vim the “source.list” and append the 10gen package like this :
$ sudo vim /etc/apt/sources.list
File : /etc/apt/sources.list
#...content omitted ...
## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu natty main
deb-src http://extras.ubuntu.com/ubuntu natty main
 #mongo repo ##########
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen

 2. Update package
Update the modified “/etc/apt/sources.list” :
sudo apt-get update
Now, a new “mongodb-10gen – An object/document-oriented database” is available for install.
  3. Add GPG Key
10gen package required GPG key, import it :
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
   4. Install mongodb-10gen
Everything is ready, now you can Install the mongoDB package :
sudo apt-get install mongodb-10gen
    5. Post-InstallationVerification
Now, mongoDB is installed, started, and auto start mongoDB script is generated to “/etc/init/mongo” and “/etc/init.d/mongo“. In addition, all mongoDB files are copied to “/usr/bin” folder.

The main configuration file “mongodb.conf” is located at “/etc/mongodb.conf“, change the values to customize your mongoDB server.

File : mongodb.conf
# mongodb.conf
# Where to store the data.
# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb
#where to log
logpath=/var/log/mongodb/mongodb.log logappend=true
#port = 27017
#......
   6. Verification
To verify it, just connect it with “mongo”
$ mongo
MongoDB shell version: 1.8.1 connecting to: test
>
on my next post I will try to connect php with this mongoDB.

Friday, November 4, 2011

Parsing Email with PHP

I was working for a Email Advertisement tool,recently. And the first thing I was put to work with is to develop a parser that parses and incoming email and decides whether it is a bounced back email. After couple of googling I got some fare enough solution that I wanted to use for the solution. The steps I followed for the solution are adopted from the following :
HOWTO: Email Bounce handling with PHP, Exim & CPanel, Catch bounces from non-deliverable emails

And the very basic parser I wrote can be downloaded from the following location:
Download the email parser for bounce management
[Bascially It's a codeIgniter controller, but you can use it as you wanna use it]

However, I had to go some more details parsing, later to decide the type of bounce or the reason for the bounce.First I tried parsing the log file for the exim [exim_mainlog file] and then parsing the entire body of the bounced back emails. I will share two more posts on them in this series.

Monday, October 3, 2011

Hack a Blackberry 9700 Bold to access internet without BlackBerry data service

[I kept this post for long as Draft; thought I shud l publish; ]
Playing with the Blackberry 9700 from Sujoy who was not using it because it cost a lot to enable Blackberry service with the Operators who are offering BB services.
So I picked it up just to see why should such a device left unused just because some kinda service is not available or bcz its expensive. Following are the things what I am currently doing with it :
Setting the Internet connection without the Blackberry data service :
First of all you have to set up your tcp settings. In your BlackBerry menu go to => Options - Advanced Options - TCP and enter your APN information for your GSM Service.You can ask your customer care for the APN information.When you finish the settings you need a browser to surf the net. The best one is Opera Mini Browser. You download the Opera Browser to your BlackBerry and in the Opera Browser menu you go through automatic network setup. Once the Opera Browser finds out your settings you are ready to surf the net from you BlackBerry for free. (Excluding standart connection charges- for the GPRS/Edge from your GSM service provider)
Happy, browsing then without paying the BB service :P.

Saturday, July 2, 2011

Node.js : Simple push from server to browser

Here you go a test that a tasted while playing with Nodejs.I must say that it is a great fun playing with Nodejs.I always love to create real time environment for the web. Here is a little example of it. With this piece of code you'll be able to monitor any changes in a file in real time directly from your browser. Nothing too efficient but still a very good start. 




My flavor : On this video you will see Pedro is using a log file. Instead, I used a simple text file and updated the file manually.

Issue I faced : Din work for me on google chrome but was good on firefox. After investigation here seems a little convincing reason :
http://stackoverflow.com/questions/6068820/node-js-problems-with-response-write

For getting started with  Node.js,  You'll get a complete set of video tutorials at the following location :
http://nodetuts.com/ [the video I have shared here is the second episode from the series]

Happy Techifying the world :)    
Update: just got another example of similar push server ; utilizing socket.io.
http://www.gianlucaguarini.com/blog/?p=272

Simple Hacks for windows using regedit

Following is a list of some interesting restrictions, which can be made in Windows 2000, XP, 2003, Vista, 2008 and 7. Like you can restrict Display properties, task bar properties, folder options, etc. All tricks are based on Registry editing. So I'll tell the key name and the value, that you have to create for the restriction. If the key is not present, then simply create it.

1.) Restrict Display Properties:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\System
create DWORD value NoDispCPL and set its value to 1

2.) Restrict Taskbar Properties:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
create DWORD value NoSetTaskbar and set its value to 1

3.) Restrict Folder Options:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
create DWORD value NoFolderOptions and set its value to 1

4.) Restrict Locking/Unlocking the taskbar:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
create DWORD value LockTaskbar and set its value to 1

5.) Restrict Active Desktop:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
create DWORD value NoActiveDesktop and set its value to 1

6.) Restrict adding/deleting items from Toolbars:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
create DWORD value NoToolbarCustomize and set its value to 1

7.) Restrict adding/deleting toolbars:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
create DWORD value NoBandCustomize and set its value to 1

8.) Restrict right-click in Start Menu:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
create DWORD value NoChangeStartMenu and set its value to 1

9.) Restrict Desktop Cleanup Wizard:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
create DWORD value No Desktop Clean up Wizard and set its value to 1

10.) Restrict notification at low disk space:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
create DWORD value No Low Disk Space Checks and set its value to 1

11.) Restrict Taskbar Context Menu:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
create DWORD value No Tray Context Menu and set its value to 1

12.) Restrict Programs to run:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer\DisallowRun
create String value with any name, like 1 and set its value to the program's EXE file.
e.g., If you want to restrict msconfig, then create a String value 1 and set its value to msconfig.exe. If you want to restrict more programs, then simply create more String values with names 2, 3 and so on and set their values to the program's exe.

13.) Restrict Registry Editor:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\System
create DWORD value Disable Registry Tools and set its value to 1

14.) Restrict Task Manager:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\System
create DWORD value Disable TaskMgr and set its value to 1

15.) Restrict Writing to USB Drives:
HKEY_LOCAL_MACHINE\SYSTEM\Current Control Set\ ControlSet \Control\ Storage Device Policies
Create DWORD value Write Protect and set its value to 1

16.) Restrict New option in context menu:
HKEY_CLASSES_ROOT\Directory\Background\ shellex\ Context Menu Handlers\New
And delete the value of Default, e.g., empty it.

17.) Restrict Send To in context menu:
HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenu Handlers\Send To
And delete the value of Default, e.g., empty it.

18.) Restrict Balloon Tips:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Explorer\Advanced
Create DWORD value EnableBalloonTips and set its value to 0

19.) Restrict Users to enable New XP StartMenu:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
Create DWORD value No Simple Start Menu and set its value to 1

20.) Restrict Command Prompt:
HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System
Create DWORD value Disable CMD and set its value to 2

21.) Restrict Drives in My Computer:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
In right-side pane, create a new DWORD value No View On Drive and change its value as following:

3 : To Restrict A and B drives only.
4 : To Restrict C drive only.
7 : To Restrict A, B, and C drives only.
8 : To Restrict D drive only.
F : To Restrict A, B, C, and D drives only.
03FFFFFF : To Restrict all drives.

And if you want more specific restrictions, like you want to restrict a combination of other drives, then you can use decimal no. instead of hexadecimal no. Following is a list for all drives decimal no.:

A: 1
B: 2
C: 4
D: 8
E: 16
F: 32
G: 64
H: 128
I: 256
J: 512
K: 1024
L: 2048
M: 4096
N: 8192
O: 16384
P: 32768
Q: 65536
R: 131072
S: 262144
T: 524288
U: 1048576
V: 2097152
W: 4194304
X: 8388608
Y: 16777216
Z: 33554432
ALL: 67108863

So if you want to disable a combination of drives, just sum their numbers and give the same value to NoViewOnDrive. e.g., for restricting C, D, E and F drives, give the value: 4+8+16+32 = 60
NOTE: You can also hide the drives using No Drives DWORD value. The location and its value remain same as the above trick.

22.) Restrict RUN in New XP Start Menu:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
Create DWORD value No Run and set its value to 1

23.) Restrict Control Panel:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer
Create DWORD value No Control Panel and set its value to 1

NOTE: If you want to remove the restriction, then simply delete the DWORD value or set its value to 0
So, that's some simple hacks that you can try to fight the battle against any virus, worms, trojan horse, malware or spyware or even your naive system admin :P Have fun :) .

Thursday, June 23, 2011

Fun with SAPI

Following vb script pronounces what you write- I tried on my win7 box and I thought it's fun to get started with SAPI. Write the code on Notepad and save the file with extension .vbs.

Then clicking the vb script file will show you the following window - write what you want to listen on the text box and press ok, did you hear that ? :P

I have some more idea based on it; do you ? Will share once I can create some more fun with it :)

Resources for Face Detection

I always had some interest in working with faces :B - yeah face detection and recognition. following is a list I have found once on the internet; thought might be helpful for me someday when I'll get some time to work with seriously :S.
Face detection (or more generally Image Matching resources):
AForge.net
Facedectection in C# with less than 50 LoC
http://friism.com/facedectection-in-c-with-less-than-50-loc
Face Detection in (pure) C#
http://askernest.com/archive/2008/05/03/face-detection-in-c.aspx
Easy to use Wrapper (DLL) for Intel’s OpenCV Library with Examples
http://www.codeproject.com/KB/cs/Intel_OpenCV.aspx
OpenCV (Open Source Computer Vision) for C#
http://coolthingoftheday.blogspot.com/2008/08/opencv-open-source-computer-vision-for.html
OpenCVDotNet
http://code.google.com/p/opencvdotnet/
Emgu CV
http://www.emgu.com/wiki/index.php/Main_Page
SharperCV Project
http://www.cs.ru.ac.za/research/groups/SharperCV/
[C#] OpenCV
http://www.dotblogs.com.tw/chou/archive/2009/06/13/8812.aspx
Webcam in C#: with OpenCVDotNet
http://haryoktav.wordpress.com/2008/12/12/webcam-in-c/
OpenCV / SURF How to generate a image hash / fingerprint / signature out of the descriptors?
http://stackoverflow.com/questions/2146542/opencv-surf-how-to-generate-a-image-hash-fingerprint-signature-out-of-the-d
Face Detection and Identification
http://www.emgu.com/forum/viewtopic.php?f=7&t=11&start=10
Phase Correlation in OpenCV
http://nashruddin.com/phase-correlation-function-in-opencv.html
SURF and OpenSURF
http://amitsarangi.wordpress.com/tag/opencv-features/

A proprietary tool but had a lot of fun with the following tool:
http://www.luxand.com/


Wednesday, June 8, 2011

Free hosting and services for Node.js

If you wanna start playing with Node.js the best way I think is burning a box with Ubuntu or CentOS and start with installing and creating simple hello world  servers. But if the box is instantly not available to you and you are dieing of testing (!! or tasting !!) this incredible technology (it is already being called the future of web !!) then there are some good folks who have come up with the solutions where you can experiment with your thirst for Node.js.
As I always try to check how it works first - instead
of starting from the root of it - I was looking for free
hosting that comes up with Node.js already built in and easy-to-utilize. Here I am going to share the list of them and my experience and/or what others think of them :
  • Nodester : Fair enough. Just registered will update the review soon. Ref link : http://nodester.com/
  • Nodejitsu. :(Seems the folks are fond of Martial Arts :P ) Still not open for public. Request only. I have requested for a Coupon- don get the response yet- but seems good enough. Ref link : http://nodejitsu.com/
  • Joyent Node: I kinda like there url : http://no.de. Just requested for a coupon and waiting for the response. will update with my experience soon.

Monday, May 30, 2011

Playing with Node.js

I was watching a lot of noises speaking high about an incredible technology - a server framework : Node.js.
I was looking for a chance to play with it and this is what I was doing for the last two hours :
Installing Node.js on CentOS box :
1. You will need gc++ if you wanna compile from the source ; so if you don have it just do :
yum install gc-c++
2. You will need python; if you don have it already just do :
yum install python
3. Now download the Node.js source available as tarball from the website : Node.js.
4. Extract the tarball, cd within the directory and sequncially do the following :
./configure
make
make install
5. Hurrah, most possibly you are done ;) You wanna check ? just do :
node --version
possibly you are seeing the installed node version :)

On the next post I will try to create couple of example apps to play even more with Node.js.So, Stay tuned :P

Wednesday, April 6, 2011

Installing ffmpeg and other extensions and tools to use with php

Installing FFMpeg
yum install ffmpeg ffmpeg-devel
If you get package not found, then you will need to add few lines in the yum repository for dag packages installation. Create a file named dag.repo in /etc/yum.repos.d with the following contents on it
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
then
yum install ffmpeg ffmpeg-devel
If everything is fine, then the installation should proceed smoothly. If not you will get something like warning GPG public key missing .


Common Errors

To fix rpmforge GPG key warning:
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
For more information refer to this faq depending on Centos version
Missing Dependency Error:
If you get missing dependency error like shown below, in the middle of ffmpeg installation
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package ffmpeg
Error: Missing Dependency: libtheora.so.0(libtheora.so.1.0) is needed by package ffmpeg
Error: Missing Dependency: rtld(GNU_HASH) is needed by package ffmpeg
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package imlib2
Error: Missing Dependency: rtld(GNU_HASH) is needed by package a52dec
Error: Missing Dependency: rtld(GNU_HASH) is needed by package imlib2
Error: Missing Dependency: rtld(GNU_HASH) is needed by package gsm
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package x264
Error: Missing Dependency: rtld(GNU_HASH) is needed by package xvidcore
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package lame
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package a52dec
Error: Missing Dependency: rtld(GNU_HASH) is needed by package faad2
Error: Missing Dependency: rtld(GNU_HASH) is needed by package x264
Error: Missing Dependency: rtld(GNU_HASH) is needed by package lame
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package xvidcore
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package faac
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package faad2
Error: Missing Dependency: libgif.so.4 is needed by package imlib2
Error: Missing Dependency: rtld(GNU_HASH) is needed by package faac
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package gsm
Error: Missing Dependency: libpng12.so.0(PNG12_0) is needed by package imlib2
Error: Missing Dependency: rtld(GNU_HASH) is needed by package libmp4v2
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package libmp4v2
then most commonly you have GLIB 2.3 installed instead of GLIB 2.4 version. To check the current GLIB version installed on your server. just use
yum list glib*
and it should list the latest GLIB package version.

The reason i was getting this error was my rpmforge packages was pointed to centos 5 versions instead of centos 4.6.


To fix dependency error:

To fix this error, you might need to check your rpmforge packages compatible to the release of your existing CentOS version.
Check the file /etc/yum.repos.d/rpmforge.repo and it should look like for Centos 4.6(Final). If you have lines like http://apt.sw.be/redhat/el5/en/mirrors-rpmforge you might need to make changes to therpmforge.repos like shown below

Note: Backup the original rpmforge.repo file before you edit its content.
[rpmforge]
name = Red Hat Enterprise $releasever - RPMforge.net - dag
#baseurl = http://apt.sw.be/redhat/el4/en/$basearch/dag
mirrorlist = http://apt.sw.be/redhat/el4/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
To know what linux type and version you are running
cat /etc/redhat-release
Once this is done, do again yum install ffmpeg.
This trick resolved the problem in my linux box running Centos 4.6 and this is the only way i found to install ffmpeg using yum.
To check the FFmpeg working:

Finally, check the ffmpeg whether it is working or not.
ffmpeg
ffmpeg -formats
ffmpeg --help
// This lists path of mpeg, its modules and other path information
ffmpeg -i Input.file Output.file
To check what audi/video formats are supported
ffmpeg -formats > ffmpeg-format.txt
Open the ffmpeg-formats.txt to see the output
D means decode
E means encode
V means video
A means audio
T = Truncated


Install FFMPEG-PHP Extension
FFmpeg-php is a very good extension and wrapper for PHP which can pull useful information about video through API interface. Inorder to install it you will need to download the source file and then compile and install extension in your server. You can download the source tarball : http://ffmpeg-php.sourceforge.net/
wget /path/to/this/file/ffmpeg-php-0.6.0.tbz2
tar -xjf ffmpeg-0.6.0.tbz2
phpize
./configure
make
make install
Common Errors

1. If you get command not found error for phpize, then you will need to do yum install php-devel
2. If you get error like "ffmpeg headers not found" while configuring the source.
configure: error: ffmpeg headers not found. Make sure ffmpeg is compiled as shared libraries using the --enable-shared option
then it means you have not installed ffmpeg-devel packages.
To Fix: Just install ffmpeg-devel using
yum install ffmpeg-devel
3. If you get an error like shared libraries not found problem and the program halts in the middle, then you must specify the ffmpeg installed path explicitly to the ./configure.
configure: error: ffmpeg shared libraries not found. Make sure ffmpeg is compiled as shared libraries using the --enable-shared option
To Fix:
1. First find out the ffmpeg path with ffmpeg --help command. The prefix default path should be like /usr/local/cpffmpeg
2. Configure the FFmpeg-php with --with-ffmpeg option
./configure --with-ffmpeg=/usr/local/cpffmpeg
That should resolve the problem!


Issue that I faced while installing the ffmpeg-php of version 0.6.0 :
/tmp/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function ‘zim_ffmpeg_frame_toGDImage’:
/tmp/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: ‘PIX_FMT_RGBA32’ undeclared (first use in this function)
/tmp/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: (Each undeclared identifier is reported only once
/tmp/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: for each function it appears in.)
/tmp/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function ‘zim_ffmpeg_frame_ffmpeg_frame’:
/tmp/ffmpeg-php-0.6.0/ffmpeg_frame.c:421: error: ‘PIX_FMT_RGBA32’ undeclared (first use in this function)
make: *** [ffmpeg_frame.lo] Erreur 1
Fix to this issue :
Just open the ffmpeg_frame.c file and replace the PIX_FMT_RGBA32 with PIX_FMT_RGB32. With vi you can do it as :
vi ffmpeg_frame.c
:%s/PIX_FMT_RGBA32/PIX_FMT_RGB32
:w
However I just opened it on a text editor on my windows and applied find and replace ;)
After the replacement is done you have surely you have to do the configure and make and make install as :
phpize
./configure
make
make install
[before performing a make this time it is recommended you do a make clean]

Editing php.ini
Once you have done that without any problems then you will see the php extension file /usr/lib/php/modules/ffmpeg.so and you will need mention that extension in php.ini file
vi /etc//php.ini
Put the below two lines at the end of the php.ini file
[ffmpeg]
extension=ffmpeg.so
Then restart the server service httpd restart. In my case I had a server from godaddy and I had to do the following to restart the webserver :
/usr/sbin/apachectl graceful
To check whether ffmpeg enabled with php, point your browser to test.php file. It should show the confirmation of installed ffmpeg php extension
// #test.php
          phpinfo()
?>
This is what you are suppose to get :
If any case the ffmpeg does not show in the phpinfo() test make sure that php.ini path to ffmpeg.so is correct. Still the problem occurs, the reason could be you might be using older versions of ffmpeg-php which is buggy. Just download the latest version of ffmpeg-php source then compile it.
Installing Mplayer + Mencoder
To know more about Mplayer
Just issue the following yum commands to install the rest of the packages.
yum install mplayer mencoder
Installing FlvTool2
Flvtool2 is a flash video file manipulation tool. It can calculate metadata and can cut and edit cue points for flv files.
If you are on Centos 5 try yum install flvtool2 [worked fine with me] with dag repository and if you get package not found you will need to manually download and compile the flvtool2. You can download latest version of flvtool2 here: http://rubyforge.org/projects/flvtool2/
wget
ruby setup.rb config
ruby setup.rb setup
sudo ruby setup.rb install
If you get command not found error, it probably means that you dont have ruby installed.
yum install ruby
Thats it! Once ffmpeg works fine with php extension, download a sample video, convert to .flv format in the command line and plug it to flowplayer to see it work on your web browser. Try also to download the video file offline and see whether the converted flv file works well with both audio and video.
Now following is how you might wanna play with this beautiful tool/toolset :
This is how ffmpeg actually works :

Here is a some tutorials to play with ffmepg.

http://www.phpro.org/tutorials/Video-Conversion-With-FFMPEG.html

Reference :